Sending ECommerce events on Android

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 ECommerceEvent class method.

The examples below show how to send specific types of events (Java):

Opening a page
Map<String, String> payload = new HashMap<>();
payload.put("configuration", "landscape");
payload.put("full_screen", "true"); 
// Creating a screen object.
  ECommerceScreen screen = new ECommerceScreen()
	.setCategoriesPath(Arrays.asList( // Optional.
		"Акции", 
		"Красная цена" 
	)) 
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("даниссимо кленовый сироп") // Optional.
	.setPayload(payload); // Optional.
  ECommerceEvent showScreenEvent = ECommerceEvent.showScreenEvent(screen);
// Sending an e-commerce event.
  YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(showScreenEvent);
Viewing a product profile
Map<String, String> payload = new HashMap<>();
payload.put("configuration", "landscape");
payload.put("full_screen", "true"); 
// Creating a screen object.
  ECommerceScreen screen = new ECommerceScreen()
	.setCategoriesPath(Arrays.asList( // Optional.
		"Акции", 
		"Красная цена" 
	)) 
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("даниссимо кленовый сироп") // Optional.
	.setPayload(payload); // Optional.
// Creating an actualPrice object.
  ECommercePrice actualPrice = new ECommercePrice(new ECommerceAmount(4.53, "USD"))
	.setInternalComponents(Arrays.asList( // Optional. 
	new ECommerceAmount(30_570_000, "wood"), 
  new ECommerceAmount(26.89, "iron"), 
  new ECommerceAmount(new BigDecimal(5.1), "gold") 
	));
// Creating an originalPrice object.
  ECommercePrice originalPrice = new ECommercePrice(new ECommerceAmount(5.78, "USD"))
	.setInternalComponents(Arrays.asList( // Optional.
	new ECommerceAmount(30_590_000, "wood"),
  new ECommerceAmount(26.92, "iron"),
  new ECommerceAmount(new BigDecimal(5.5), "gold") 
	));
// Creating a product object. 
  ECommerceProduct product = new ECommerceProduct("779213")
	.setActualPrice(actualPrice) // Optional.
	.setPromocodes(Arrays.asList("BT79IYX", "UT5412EP")) // Optional.
	.setPayload(payload) // Optional.
	.setOriginalPrice(originalPrice) // Optional.
	.setName("Продукт творожный «Даниссимо» 5.9%, 130 г.") // Optional.
	.setCategoriesPath(Arrays.asList("Продукты", "Молочные продукты", "Йогурты")); // Optional.
                      ECommerceEvent showProductCardEvent = ECommerceEvent.showProductCardEvent(product, screen);
// Sending an e-commerce event.
  YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(showProductCardEvent);
Copied to clipboard
Viewing a product page
Map<String, String> payload = new HashMap<>();
payload.put("configuration", "landscape");
payload.put("full_screen", "true"); 
// Creating a screen object.
  ECommerceScreen screen = new ECommerceScreen()
	.setCategoriesPath(Arrays.asList( // Optional.
		"Акции", 
		"Красная цена" 
	)) 
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("даниссимо кленовый сироп") // Optional.
	.setPayload(payload); // Optional.

// Creating an actualPrice object.
  ECommercePrice actualPrice = new ECommercePrice(new ECommerceAmount(4.53, "USD"))
	.setInternalComponents(Arrays.asList( // Optional. 
	new ECommerceAmount(30_570_000, "wood"), 
  new ECommerceAmount(26.89, "iron"), 
  new ECommerceAmount(new BigDecimal(5.1), "gold") 
	));
// Creating an originalPrice object.
  ECommercePrice originalPrice = new ECommercePrice(new ECommerceAmount(5.78, "USD"))
	.setInternalComponents(Arrays.asList( // Optional.
	new ECommerceAmount(30_590_000, "wood"),
  new ECommerceAmount(26.92, "iron"),
  new ECommerceAmount(new BigDecimal(5.5), "gold") 
	));
// Creating a product object. 
  ECommerceProduct product = new ECommerceProduct("779213")
	.setActualPrice(actualPrice) // Optional.
	.setPromocodes(Arrays.asList("BT79IYX", "UT5412EP")) // Optional.
	.setPayload(payload) // Optional.
	.setOriginalPrice(originalPrice) // Optional.
	.setName("Продукт творожный «Даниссимо» 5.9%, 130 г.") // Optional.
	.setCategoriesPath(Arrays.asList("Продукты", "Молочные продукты", "Йогурты")); // Optional.
// Creating a referrer object.
  ECommerceReferrer referrer = new ECommerceReferrer()
	.setType("button") // Optional.
	.setIdentifier("76890") // Optional.
	.setScreen(screen); // Optional.
                      ECommerceEvent showProductDetailsEvent = ECommerceEvent.showProductDetailsEvent(product, referrer); // Referrer is optional — can be null.
// Sending an e-commerce event.
  YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(showProductDetailsEvent);
Copied to clipboard
Adding or removing an item to/from the cart
Map<String, String> payload = new HashMap<>();
payload.put("configuration", "landscape");
payload.put("full_screen", "true"); 
// Creating a screen object.
  ECommerceScreen screen = new ECommerceScreen()
	.setCategoriesPath(Arrays.asList( // Optional.
		"Акции", 
		"Красная цена" 
	)) 
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("даниссимо кленовый сироп") // Optional.
	.setPayload(payload); // Optional.
// Creating an actualPrice object.
  ECommercePrice actualPrice = new ECommercePrice(new ECommerceAmount(4.53, "USD"))
	.setInternalComponents(Arrays.asList( // Optional. 
	new ECommerceAmount(30_570_000, "wood"), 
  new ECommerceAmount(26.89, "iron"), 
  new ECommerceAmount(new BigDecimal(5.1), "gold") 
	));
// Creating an originalPrice object.
  ECommercePrice originalPrice = new ECommercePrice(new ECommerceAmount(5.78, "USD"))
	.setInternalComponents(Arrays.asList( // Optional.
	new ECommerceAmount(30_590_000, "wood"),
  new ECommerceAmount(26.92, "iron"),
  new ECommerceAmount(new BigDecimal(5.5), "gold") 
	));
// Creating a product object. 
  ECommerceProduct product = new ECommerceProduct("779213")
	.setActualPrice(actualPrice) // Optional.
	.setPromocodes(Arrays.asList("BT79IYX", "UT5412EP")) // Optional.
	.setPayload(payload) // Optional.
	.setOriginalPrice(originalPrice) // Optional.
	.setName("Продукт творожный «Даниссимо» 5.9%, 130 г.") // Optional.
	.setCategoriesPath(Arrays.asList("Продукты", "Молочные продукты", "Йогурты")); // Optional.
// Creating a referrer object.
  ECommerceReferrer referrer = new ECommerceReferrer()
	.setType("button") // Optional.
	.setIdentifier("76890") // Optional.
	.setScreen(screen); // Optional.
// Creating a cartItem object. 
  ECommerceCartItem addedItems1 = new ECommerceCartItem(product, actualPrice, 1.0)
	.setReferrer(referrer); // Optional.
                      ECommerceEvent addCartItemEvent = ECommerceEvent.addCartItemEvent(addedItems1);
                      // Sending an e-commerce event.
  YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(addCartItemEvent);
                      ECommerceEvent removeCartItemEvent = ECommerceEvent.removeCartItemEvent(addedItems1);
// Sending an e-commerce event.
  YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(removeCartItemEvent);
Copied to clipboard
Starting and completing a purchase
Map<String, String> payload = new HashMap<>();
payload.put("configuration", "landscape");
payload.put("full_screen", "true"); 
// Creating a screen object.
  ECommerceScreen screen = new ECommerceScreen()
	.setCategoriesPath(Arrays.asList( // Optional.
		"Акции", 
		"Красная цена" 
	)) 
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("даниссимо кленовый сироп") // Optional.
	.setPayload(payload); // Optional.
// Creating an actualPrice object.
  ECommercePrice actualPrice = new ECommercePrice(new ECommerceAmount(4.53, "USD"))
	.setInternalComponents(Arrays.asList( // Optional. 
	new ECommerceAmount(30_570_000, "wood"), 
  new ECommerceAmount(26.89, "iron"), 
  new ECommerceAmount(new BigDecimal(5.1), "gold") 
	));
// Creating an originalPrice object.
  ECommercePrice originalPrice = new ECommercePrice(new ECommerceAmount(5.78, "USD"))
	.setInternalComponents(Arrays.asList( // Optional.
	new ECommerceAmount(30_590_000, "wood"),
  new ECommerceAmount(26.92, "iron"),
  new ECommerceAmount(new BigDecimal(5.5), "gold") 
	));
// Creating a product object. 
  ECommerceProduct product = new ECommerceProduct("779213")
	.setActualPrice(actualPrice) // Optional.
	.setPromocodes(Arrays.asList("BT79IYX", "UT5412EP")) // Optional.
	.setPayload(payload) // Optional.
	.setOriginalPrice(originalPrice) // Optional.
	.setName("Продукт творожный «Даниссимо» 5.9%, 130 г.") // Optional.
	.setCategoriesPath(Arrays.asList("Продукты", "Молочные продукты", "Йогурты")); // Optional.
// Creating a referrer object.
  ECommerceReferrer referrer = new ECommerceReferrer()
	.setType("button") // Optional.
	.setIdentifier("76890") // Optional.
	.setScreen(screen); // Optional.
// Creating a cartItem object. 
  ECommerceCartItem addedItems1 = new ECommerceCartItem(product, actualPrice, 1.0)
	.setReferrer(referrer); // Optional.
// Creating an order object.
ECommerceOrder order = new ECommerceOrder("88528768", Arrays.asList(addedItems1))
        .setPayload(payload); // Optional.
                      ECommerceEvent beginCheckoutEvent = ECommerceEvent.beginCheckoutEvent(order);
// Sending an e-commerce event.
  YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(beginCheckoutEvent);
                      ECommerceEvent purchaseEvent = ECommerceEvent.purchaseEvent(order);
// Sending an e-commerce event.
  YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(purchaseEvent);
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 ECommerceEvent instance to the main API key, use the YandexMetrica.reportECommerce(@NonNull ECommerceEvent event) method.

...
// Sending an e-commerce event.
YandexMetrica.reportECommerce(ecommerceEvent);
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.