Sending ECommerce events on Android

In AppMetrica, it is not possible to segment E-commerce events into "test" and "not test". If you use the main API key for debugging purchases, the test events are included in general statistics. Therefore, to debug Ecommerce event sending, use a reporter to send statistics to the additional API key. To learn more about reporters, see Usage examples.

Step 1. Create a test app in AppMetrica

Specify the app parameters: link in the app store (if the app isn't 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 AppMetrica.

Step 2. Configure sending e-commerce events to the test API key

For different user actions, there are appropriate types of e-commerce events. To create a specific event type, use the appropriate ECommerceEvent class method.

The examples below show how to send specific types of events.

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.
		"Promos",
		"Hot deal"
	))
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("danissimo maple syrup") // Optional.
	.setPayload(payload); // Optional.
  ECommerceEvent showScreenEvent = ECommerceEvent.showScreenEvent(screen);
// Sending an e-commerce event.
  AppMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(showScreenEvent);
Viewing a product card
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.
 	 "Promos", 
 	 "Hot deal" 
  )) 
  .setName("ProductCardActivity") // Optional.
  .setSearchQuery("danissimo maple syrup") // 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("Danissimo curd product 5.9%, 130 g") // Optional.
  .setCategoriesPath(Arrays.asList("Groceries", "Dairy products", "Yogurts")); // Optional.
                      ECommerceEvent showProductCardEvent = ECommerceEvent.showProductCardEvent(product, screen);
// Sending an e-commerce event.
  AppMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(showProductCardEvent);
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.
		"Promos",
		"Hot deal"
	))
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("danissimo maple syrup") // 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("Danissimo curd product 5.9%, 130 g") // Optional.
	.setCategoriesPath(Arrays.asList("Groceries", "Dairy products", "Yogurts")); // 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.
  AppMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(showProductDetailsEvent);
Adding/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.
		"Promos",
		"Hot deal"
	))
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("danissimo maple syrup") // 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("Danissimo curd product 5.9%, 130 g") // Optional.
	.setCategoriesPath(Arrays.asList("Groceries", "Dairy products", "Yogurts")); // 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.
  AppMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(addCartItemEvent);
                      ECommerceEvent removeCartItemEvent = ECommerceEvent.removeCartItemEvent(addedItems1);
// Sending an e-commerce event.
  AppMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(removeCartItemEvent);
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.
		"Promos",
		"Hot deal"
	))
	.setName("ProductCardActivity") // Optional.
	.setSearchQuery("danissimo maple syrup") // 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("Danissimo curd product 5.9%, 130 g") // Optional.
	.setCategoriesPath(Arrays.asList("Groceries", "Dairy products", "Yogurts")); // 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.
  AppMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(beginCheckoutEvent);
                      ECommerceEvent purchaseEvent = ECommerceEvent.purchaseEvent(order);
// Sending an e-commerce event.
  AppMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(purchaseEvent);
Opening a page
val payload = mapOf("configuration" to "landscape", "full_screen" to "true")
// Creating a screen object.
val screen = ECommerceScreen().apply {
	categoriesPath = listOf("Promos", "Hot deal") // Optional.
	name = "ProductCardActivity" // Optional.
	searchQuery = "danissimo maple syrup" // Optional.
	this.payload = payload // Optional.
	}
val showScreenEvent = ECommerceEvent.showScreenEvent(screen)
// Sending an e-commerce event.
AppMetrica.getReporter(applicationContext, "Testing API key").reportECommerce(showScreenEvent)
Viewing a product card
val payload = mapOf("configuration" to "landscape", "full_screen" to "true")
// Creating a screen object.
val screen = ECommerceScreen().apply {
	categoriesPath = listOf("Promos", "Hot deal") // Optional.
	name = "ProductCardActivity" // Optional.
	searchQuery = "danissimo maple syrup" // Optional.
	this.payload = payload // Optional.
	}
// Creating an actualPrice object.
val actualPrice = ECommercePrice(ECommerceAmount(4.53, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30570000, "wood"),
			ECommerceAmount(26.89, "iron"),
			ECommerceAmount(BigDecimal(5.1), "gold")
		)
	}
// Creating an originalPrice object.
val originalPrice = ECommercePrice(ECommerceAmount(5.78, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30590000, "wood"),
			ECommerceAmount(26.92, "iron"),
			ECommerceAmount(BigDecimal(5.5), "gold")
		)
	}
// Creating a product object.
val product = ECommerceProduct("779213")
	.apply {
		this.actualPrice = actualPrice // Optional.
		this.originalPrice = originalPrice // Optional.
		promocodes = listOf("BT79IYX", "UT5412EP") // Optional.
		name = "Danissimo curd product 5.9%, 130 g" // Optional.
		categoriesPath = listOf("Groceries", "Dairy products", "Yogurts") // Optional.
		this.payload = payload // Optional.
	}

val showProductCardEvent = ECommerceEvent.showProductCardEvent(product, screen)
// Sending an e-commerce event.
AppMetrica.getReporter(applicationContext, "Testing API key").reportECommerce(showProductCardEvent)
Viewing a product page
val payload = mapOf("configuration" to "landscape", "full_screen" to "true")
// Creating a screen object.
val screen = ECommerceScreen().apply {
	categoriesPath = listOf("Promos", "Hot deal") // Optional.
	name = "ProductCardActivity" // Optional.
	searchQuery = "danissimo maple syrup" // Optional.
	this.payload = payload // Optional.
	}
// Creating an actualPrice object.
val actualPrice = ECommercePrice(ECommerceAmount(4.53, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30570000, "wood"),
			ECommerceAmount(26.89, "iron"),
			ECommerceAmount(BigDecimal(5.1), "gold")
		)
	}
// Creating an originalPrice object.
val originalPrice = ECommercePrice(ECommerceAmount(5.78, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30590000, "wood"),
			ECommerceAmount(26.92, "iron"),
			ECommerceAmount(BigDecimal(5.5), "gold")
		)
	}
// Creating a product object.
val product = ECommerceProduct("779213")
	.apply {
		this.actualPrice = actualPrice // Optional.
		this.originalPrice = originalPrice // Optional.
		promocodes = listOf("BT79IYX", "UT5412EP") // Optional.
		name = "Danissimo curd product 5.9%, 130 g" // Optional.
		categoriesPath = listOf("Groceries", "Dairy products", "Yogurts") // Optional.
		this.payload = payload // Optional.
	}
// Creating a referrer object.
val referrer = ECommerceReferrer()
	.apply {
		type = "button" // Optional.
		identifier = "76890" // Optional.
		this.screen = screen // Optional.
	}
val showProductDetailsEvent = ECommerceEvent.showProductDetailsEvent(product, referrer) // Referrer is optional - can be null.
// Sending an e-commerce event.
AppMetrica.getReporter(applicationContext, "Testing API key").reportECommerce(showProductDetailsEvent)
Adding/removing an item to/from the cart
val payload = mapOf("configuration" to "landscape", "full_screen" to "true")
// Creating a screen object.
val screen = ECommerceScreen().apply {
	categoriesPath = listOf("Promos", "Hot deal") // Optional.
	name = "ProductCardActivity" // Optional.
	searchQuery = "danissimo maple syrup" // Optional.
	this.payload = payload // Optional.
	}
// Creating an actualPrice object.
val actualPrice = ECommercePrice(ECommerceAmount(4.53, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30570000, "wood"),
			ECommerceAmount(26.89, "iron"),
			ECommerceAmount(BigDecimal(5.1), "gold")
		)
	}
// Creating an originalPrice object.
val originalPrice = ECommercePrice(ECommerceAmount(5.78, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30590000, "wood"),
			ECommerceAmount(26.92, "iron"),
			ECommerceAmount(BigDecimal(5.5), "gold")
		)
	}
// Creating a product object.
val product = ECommerceProduct("779213")
	.apply {
		this.actualPrice = actualPrice // Optional.
		this.originalPrice = originalPrice // Optional.
		promocodes = listOf("BT79IYX", "UT5412EP") // Optional.
		name = "Danissimo curd product 5.9%, 130 g" // Optional.
		categoriesPath = listOf("Groceries", "Dairy products", "Yogurts") // Optional.
		this.payload = payload // Optional.
	}
// Creating a referrer object.
val referrer = ECommerceReferrer()
	.apply {
		type = "button" // Optional.
		identifier = "76890" // Optional.
		this.screen = screen // Optional.
	}
// Creating a cartItem object.
val addedItems1 = ECommerceCartItem(product, actualPrice, 1.0)
	.apply {
		this.referrer = referrer // Optional.
	}
val addCartItemEvent = ECommerceEvent.addCartItemEvent(addedItems1)
// Sending an e-commerce event.
AppMetrica.getReporter(applicationContext, "Testing API key").reportECommerce(addCartItemEvent)

val removeCartItemEvent = ECommerceEvent.removeCartItemEvent(addedItems1)
// Sending an e-commerce event.
AppMetrica.getReporter(applicationContext, "Testing API key").reportECommerce(removeCartItemEvent)
Starting and completing a purchase
val payload = mapOf("configuration" to "landscape", "full_screen" to "true")
// Creating a screen object.
val screen = ECommerceScreen().apply {
	categoriesPath = listOf("Promos", "Hot deal") // Optional.
	name = "ProductCardActivity" // Optional.
	searchQuery = "danissimo maple syrup" // Optional.
	this.payload = payload // Optional.
	}
// Creating an actualPrice object.
val actualPrice = ECommercePrice(ECommerceAmount(4.53, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30570000, "wood"),
			ECommerceAmount(26.89, "iron"),
			ECommerceAmount(BigDecimal(5.1), "gold")
		)
	}
// Creating an originalPrice object.
val originalPrice = ECommercePrice(ECommerceAmount(5.78, "USD"))
	.apply {
		internalComponents = listOf( // Optional.
			ECommerceAmount(30590000, "wood"),
			ECommerceAmount(26.92, "iron"),
			ECommerceAmount(BigDecimal(5.5), "gold")
		)
	}
// Creating a product object.
val product = ECommerceProduct("779213")
	.apply {
		this.actualPrice = actualPrice // Optional.
		this.originalPrice = originalPrice // Optional.
		promocodes = listOf("BT79IYX", "UT5412EP") // Optional.
		name = "Danissimo curd product 5.9%, 130 g" // Optional.
		categoriesPath = listOf("Groceries", "Dairy products", "Yogurts") // Optional.
		this.payload = payload // Optional.
	}
// Creating a referrer object.
val referrer = ECommerceReferrer()
	.apply {
		type = "button" // Optional.
		identifier = "76890" // Optional.
		this.screen = screen // Optional.
	}
// Creating a cartItem object.
val addedItems1 = ECommerceCartItem(product, actualPrice, 1.0)
	.apply {
		this.referrer = referrer // Optional.
	}
// Creating an order object.
val order = ECommerceOrder("88528768", listOf(addedItems1))
        .apply {
            this.payload = payload // Optional.
        }
val beginCheckoutEvent = ECommerceEvent.beginCheckoutEvent(order)
// Sending an e-commerce event.
AppMetrica.getReporter(applicationContext, "Testing API key").reportECommerce(beginCheckoutEvent)

val purchaseEvent = ECommerceEvent.purchaseEvent(order)
// Sending an e-commerce event.
AppMetrica.getReporter(applicationContext, "Testing API key").reportECommerce(purchaseEvent)

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 e-commerce events.

To learn more about these reports, see Purchase analysis.

Step 4. Configure sending ECommerce to the main API Key

After successful testing, configure sending E-commerce events to the main API key.

To send the ECommerceEvent instance to the main API key, use the AppMetrica.reportECommerce(@NonNull ECommerceEvent event) method.

// ...
// Sending an e-commerce event.
AppMetrica.reportECommerce(ecommerceEvent);
// ...
// Sending an e-commerce event.
AppMetrica.reportECommerce(ecommerceEvent)

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.

Contact support