Sending ECommerce events on Android

AppMetrica doesn't let you 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. Therefore, to debug Ecommerce event sending, use a reporter to send statistics to the 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

  1. In the AppMetrica interface, click Add application.

  2. Fill in the fields in the form.
  3. Click Create. By clicking the button, you accept the terms of user agreement.
Note. Different versions of the same app can be grouped in a single folder. To do this, create a folder using the button and move the apps to it.

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 cartItem1 = new ECommerceCartItem(product, actualPrice, 1.0)
        .setReferrer(referrer); // Optional.
ECommerceEvent addCartItemEvent = ECommerceEvent.addCartItemEvent(cartItem1);
// Sending an e-commerce event.
YandexMetrica.getReporter(getApplicationContext(), "Testing API key").reportECommerce(addCartItemEvent);
ECommerceEvent removeCartItemEvent = ECommerceEvent.removeCartItemEvent(cartItem1);
// 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 cartItem1 = new ECommerceCartItem(product, actualPrice, 1.0)
        .setReferrer(referrer); // Optional.
// Creating an order object.
ECommerceOrder order = new ECommerceOrder("88528768", Arrays.asList(cartItem1))
        .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