Sending ECommerce events on iOS

In AppMetrica, it is not possible to segment ECommerce events into “test” and “not test”. If you use the main API key for debugging purchases, the test events are included in general statistics. If you need to debug sending ECommerce events, use a reporter to send statistics to an additional API key. For more information about reporters, see Usage examples.
  1. Step 1. Create a test app in AppMetrica
  2. Step 2. Configure sending ECommerce events to the test API key
  3. Step 3. Check the test application's report
  4. Step 4. Configure sending ECommerce to the main API Key

Step 1. Create a test app in AppMetrica

Specify the app parameters: link in the app store (if the app hasn't been published yet, leave the field empty), name, category, and time zone for generating reports.

To add another app, click Add app in the drop-down list in the AppMetrica interface.

Step 2. Configure sending ECommerce events to the test API key

For different user actions, there are appropriate types of ECommerce events. To create a specific event type, use the appropriate YMMECommerce class method.

The examples below show how to send specific types of events (Objective-C):

Opening a page
// Creating a screen object. 
YMMECommerceScreen *screen = [[YMMECommerceScreen alloc] initWithName:@"ProductCardScreen"
                                                   categoryComponents:@[ @"Акции", @"Красная цена" ]
                                                          searchQuery:@"даниссимо кленовый сироп"
                                                              payload:@{ @"full_screen": @"true" }];
// Sending an e-commerce event.
id<YMMYandexMetricaReporting> reporter = [YMMYandexMetrica reporterForApiKey:@"Testing API key"];
[reporter reportECommerce:[YMMECommerce showScreenEventWithScreen:screen] onFailure:nil];
Viewing a product profile
// Creating a screen object. 
YMMECommerceScreen *screen = [[YMMECommerceScreen alloc] initWithName:@"ProductCardScreen"
                                                   categoryComponents:@[ @"Акции", @"Красная цена" ]
                                                          searchQuery:@"даниссимо кленовый сироп"
                                                              payload:@{ @"full_screen": @"true" }];
// Creating an actualPrice object.
YMMECommerceAmount *actualFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"4.53"]];
YMMECommerceAmount *woodActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30570000"]];
YMMECommerceAmount *ironActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.89"]];
YMMECommerceAmount *goldActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.1"]];
YMMECommercePrice *actualPrice = [[YMMECommercePrice alloc] initWithFiat:actualFiat
                                                      internalComponents:@[ woodActualPrice, ironActualPrice, goldActualPrice ]];
// Creating an originalPrice object.
YMMECommerceAmount *originalFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"5.78"]];
YMMECommerceAmount *woodOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30590000"]];
YMMECommerceAmount *ironOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.92"]];
YMMECommerceAmount *goldOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.5"]];
YMMECommercePrice *originalPrice = [[YMMECommercePrice alloc] initWithFiat:originalFiat
                                                        internalComponents:@[ woodOriginalPrice, ironOriginalPrice, goldOriginalPrice ]];
// Creating a product object.
YMMECommerceProduct *product = [[YMMECommerceProduct alloc] initWithSKU:@"779213"
                                                                   name:@"Продукт творожный «Даниссимо» 5.9%, 130 г."
                                                     categoryComponents:@[ @"Продукты", @"Молочные продукты", @"Йогурты" ]
                                                                payload:@{ @"full_screen" : @"true" }
                                                            actualPrice:actualPrice
                                                          originalPrice:originalPrice
                                                             promoCodes:@[ @"BT79IYX", @"UT5412EP" ]];
// Sending an e-commerce event.
id<YMMYandexMetricaReporting> reporter = [YMMYandexMetrica reporterForApiKey:@"Testing API key"];
[reporter reportECommerce:[YMMECommerce showProductCardEventWithProduct:product screen:screen] onFailure:nil];
Copied to clipboard
Viewing a product page
// Creating a screen object. 
YMMECommerceScreen *screen = [[YMMECommerceScreen alloc] initWithName:@"ProductCardScreen"
                                                   categoryComponents:@[ @"Акции", @"Красная цена" ]
                                                          searchQuery:@"даниссимо кленовый сироп"
                                                              payload:@{ @"full_screen": @"true" }];

// Creating an actualPrice object.
YMMECommerceAmount *actualFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"4.53"]];
YMMECommerceAmount *woodActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30570000"]];
YMMECommerceAmount *ironActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.89"]];
YMMECommerceAmount *goldActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.1"]];
YMMECommercePrice *actualPrice = [[YMMECommercePrice alloc] initWithFiat:actualFiat
                                                      internalComponents:@[ woodActualPrice, ironActualPrice, goldActualPrice ]];
// Creating an originalPrice object.
YMMECommerceAmount *originalFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"5.78"]];
YMMECommerceAmount *woodOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30590000"]];
YMMECommerceAmount *ironOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.92"]];
YMMECommerceAmount *goldOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.5"]];
YMMECommercePrice *originalPrice = [[YMMECommercePrice alloc] initWithFiat:originalFiat
                                                        internalComponents:@[ woodOriginalPrice, ironOriginalPrice, goldOriginalPrice ]];
// Creating a product object.
YMMECommerceProduct *product = [[YMMECommerceProduct alloc] initWithSKU:@"779213"
                                                                   name:@"Продукт творожный «Даниссимо» 5.9%, 130 г."
                                                     categoryComponents:@[ @"Продукты", @"Молочные продукты", @"Йогурты" ]
                                                                payload:@{ @"full_screen" : @"true" }
                                                            actualPrice:actualPrice
                                                          originalPrice:originalPrice
                                                             promoCodes:@[ @"BT79IYX", @"UT5412EP" ]];
// Creating a referrer object.
YMMECommerceReferrer *referrer = [[YMMECommerceReferrer alloc] initWithType:@"button"
                                                                 identifier:@"76890"
                                                                     screen:screen];
// Sending an e-commerce event.
id<YMMYandexMetricaReporting> reporter = [YMMYandexMetrica reporterForApiKey:@"Testing API key"];
[reporter reportECommerce:[YMMECommerce showProductDetailsEventWithProduct:product referrer:referrer] onFailure:nil];
Copied to clipboard
Adding or removing an item to/from the cart
// Creating a screen object. 
YMMECommerceScreen *screen = [[YMMECommerceScreen alloc] initWithName:@"ProductCardScreen"
                                                   categoryComponents:@[ @"Акции", @"Красная цена" ]
                                                          searchQuery:@"даниссимо кленовый сироп"
                                                              payload:@{ @"full_screen": @"true" }];
// Creating an actualPrice object.
YMMECommerceAmount *actualFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"4.53"]];
YMMECommerceAmount *woodActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30570000"]];
YMMECommerceAmount *ironActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.89"]];
YMMECommerceAmount *goldActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.1"]];
YMMECommercePrice *actualPrice = [[YMMECommercePrice alloc] initWithFiat:actualFiat
                                                      internalComponents:@[ woodActualPrice, ironActualPrice, goldActualPrice ]];
// Creating an originalPrice object.
YMMECommerceAmount *originalFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"5.78"]];
YMMECommerceAmount *woodOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30590000"]];
YMMECommerceAmount *ironOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.92"]];
YMMECommerceAmount *goldOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.5"]];
YMMECommercePrice *originalPrice = [[YMMECommercePrice alloc] initWithFiat:originalFiat
                                                        internalComponents:@[ woodOriginalPrice, ironOriginalPrice, goldOriginalPrice ]];
// Creating a product object.
YMMECommerceProduct *product = [[YMMECommerceProduct alloc] initWithSKU:@"779213"
                                                                   name:@"Продукт творожный «Даниссимо» 5.9%, 130 г."
                                                     categoryComponents:@[ @"Продукты", @"Молочные продукты", @"Йогурты" ]
                                                                payload:@{ @"full_screen" : @"true" }
                                                            actualPrice:actualPrice
                                                          originalPrice:originalPrice
                                                             promoCodes:@[ @"BT79IYX", @"UT5412EP" ]];
// Creating a referrer object.
YMMECommerceReferrer *referrer = [[YMMECommerceReferrer alloc] initWithType:@"button"
                                                                 identifier:@"76890"
                                                                     screen:screen];
// Creating a cartItem object.
NSDecimalNumber *quantity = [NSDecimalNumber decimalNumberWithString:@"1"];
YMMECommerceCartItem *addedItems = [[YMMECommerceCartItem alloc] initWithProduct:product
                                                                      referrer:referrer
                                                                      quantity:quantity
                                                                       revenue:actualPrice];
// Sending an e-commerce event.
id<YMMYandexMetricaReporting> reporter = [YMMYandexMetrica reporterForApiKey:@"Testing API key"];
[reporter reportECommerce:[YMMECommerce addCartItemEvent:addedItems] onFailure:nil];
// Or:
[YMMYandexMetrica reportECommerce:[YMMECommerce removeCartItemEventWithItem:addedItems] onFailure:nil];
Copied to clipboard
Starting and completing a purchase
// Creating a screen object. 
YMMECommerceScreen *screen = [[YMMECommerceScreen alloc] initWithName:@"ProductCardScreen"
                                                   categoryComponents:@[ @"Акции", @"Красная цена" ]
                                                          searchQuery:@"даниссимо кленовый сироп"
                                                              payload:@{ @"full_screen": @"true" }];
// Creating an actualPrice object.
YMMECommerceAmount *actualFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"4.53"]];
YMMECommerceAmount *woodActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30570000"]];
YMMECommerceAmount *ironActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.89"]];
YMMECommerceAmount *goldActualPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.1"]];
YMMECommercePrice *actualPrice = [[YMMECommercePrice alloc] initWithFiat:actualFiat
                                                      internalComponents:@[ woodActualPrice, ironActualPrice, goldActualPrice ]];
// Creating an originalPrice object.
YMMECommerceAmount *originalFiat =
        [[YMMECommerceAmount alloc] initWithUnit:@"USD" value:[NSDecimalNumber decimalNumberWithString:@"5.78"]];
YMMECommerceAmount *woodOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"wood" value:[NSDecimalNumber decimalNumberWithString:@"30590000"]];
YMMECommerceAmount *ironOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"iron" value:[NSDecimalNumber decimalNumberWithString:@"26.92"]];
YMMECommerceAmount *goldOriginalPrice =
        [[YMMECommerceAmount alloc] initWithUnit:@"gold" value:[NSDecimalNumber decimalNumberWithString:@"5.5"]];
YMMECommercePrice *originalPrice = [[YMMECommercePrice alloc] initWithFiat:originalFiat
                                                        internalComponents:@[ woodOriginalPrice, ironOriginalPrice, goldOriginalPrice ]];
// Creating a product object.
YMMECommerceProduct *product = [[YMMECommerceProduct alloc] initWithSKU:@"779213"
                                                                   name:@"Продукт творожный «Даниссимо» 5.9%, 130 г."
                                                     categoryComponents:@[ @"Продукты", @"Молочные продукты", @"Йогурты" ]
                                                                payload:@{ @"full_screen" : @"true" }
                                                            actualPrice:actualPrice
                                                          originalPrice:originalPrice
                                                             promoCodes:@[ @"BT79IYX", @"UT5412EP" ]];
// Creating a referrer object.
YMMECommerceReferrer *referrer = [[YMMECommerceReferrer alloc] initWithType:@"button"
                                                                 identifier:@"76890"
                                                                     screen:screen];
// Creating a cartItem object.
NSDecimalNumber *quantity = [NSDecimalNumber decimalNumberWithString:@"1"];
YMMECommerceCartItem *addedItems = [[YMMECommerceCartItem alloc] initWithProduct:product
                                                                      referrer:referrer
                                                                      quantity:quantity
                                                                       revenue:actualPrice];
// Creating an order object.
YMMECommerceOrder *order = [[YMMECommerceOrder alloc] initWithIdentifier:@"88528768"
                                                               cartItems:@[ addedItems ]
                                                                 payload:@{ @"black_friday" : @"true"}];
// Sending an e-commerce event.
id<YMMYandexMetricaReporting> reporter = [YMMYandexMetrica reporterForApiKey:@"Testing API key"];
[reporter reportECommerce:[YMMECommerce beginCheckoutEventWithOrder:order] onFailure:nil];
[YMMYandexMetrica reportECommerce:[YMMECommerce purchaseEventWithOrder:order] onFailure:nil];
Copied to clipboard

Step 3. Check the test application's report

Make in-app test purchases. After a while, check the “Purchase analysis” report in the AppMetrica interface. Make sure that the report shows ECommerce events.

For more information about the report, see Purchase analysis.

Step 4. Configure sending ECommerce to the main API Key

After successful testing, configure sending ECommerce events to the main API key.

To send the YMMECommerce instance to the main API key, use the +reportECommerce:onFailure: method of the YMMYandexMetrica class.

...
// Sending an e-commerce event.
[YMMYandexMetrica reportECommerce:[YMMECommerce showScreenEventWithScreen:screen] onFailure:nil];
Copied to clipboard

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.