Sending ECommerce events on Flutter

In AppMetrica, it isn't possible to segment E-commerce events into "test" and "not test" ones. If you use the main API key for debugging purchases, the test events are included in general statistics. Therefore, to debug E-commerce 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 ECommerce class method.

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

Opening a page
Map<String, String> payload = {
    "configuration": "landscape",
    "full_screen": "true",
};
// Creating a screen object.
ECommerceScreen screen = ECommerceScreen(
    name: "ProductCardActivity",              // Optional.
    searchQuery: "danissimo maple syrup",  // Optional.
    payload: payload,                         // Optional.
    categoriesPath: ["Promos","Hot deal"]  // Optional.
);
ECommerceEvent showScreenEvent = ECommerce.showScreenEvent(screen);
// Sending an e-commerce event.
AppMetrica.getReporter("Testing API key").reportECommerce(showScreenEvent);
Viewing a product card
Map<String, String> payload = {
    "configuration": "landscape",
    "full_screen": "true"
};
// Creating a screen object.
ECommerceScreen screen = ECommerceScreen(
    name: "ProductCardActivity", // Optional.
    searchQuery: "danissimo maple syrup",  // Optional.
    payload: payload,  // Optional.
    categoriesPath: ["Promos","Hot deal"]  // Optional.
);
ECommerceAmount amount = ECommerceAmount(amount: Decimal.parse('4.53'), currency: "USD");
// Creating an actualPrice object.
ECommercePrice actualPrice = ECommercePrice(fiat: amount,
    internalComponents: [  // Optional.
    ECommerceAmount(amount: Decimal.parse('30_570_000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),
]);

// Creating an originalPrice object.
ECommercePrice originalPrice = ECommercePrice(fiat: ECommerceAmount(amount: Decimal.parse('5.78'), currency: "USD"),
internalComponents: [ // Optional.
    ECommerceAmount(amount: Decimal.parse('30570000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),
]);
// Creating a product object.
ECommerceProduct product = ECommerceProduct(
sku: "779213",
name: "Danissimo curd product 5.9%, 130 g",  // Optional.
actualPrice: actualPrice, // Optional.
originalPrice: originalPrice, // Optional.
promocodes: ["BT79IYX", "UT5412EP"],  // Optional.
payload: payload,    // Optional.
categoriesPath: ["Groceries", "Dairy", "Yogurts"]  // Optional.
);

ECommerceEvent showProductCardEvent = ECommerce.showProductCardEvent(product, screen);
// Sending an e-commerce event.
AppMetrica.getReporter("Testing API key").reportECommerce(showProductCardEvent);
Viewing a product page
Map<String, String> payload = {
    "configuration": "landscape",
    "full_screen": "true"
};
// Creating a screen object.
ECommerceScreen screen = ECommerceScreen(
    name: "ProductCardActivity", // Optional.
    searchQuery: "danissimo maple syrup",  // Optional.
    payload: payload,  // Optional.
    categoriesPath: ["Promos","Hot deal"]  // Optional.
);
ECommerceAmount amount = ECommerceAmount(amount: Decimal.parse('4.53'), currency: "USD");
// Creating an actualPrice object.
ECommercePrice actualPrice = ECommercePrice(fiat: amount,
    internalComponents: [  // Optional.
    ECommerceAmount(amount: Decimal.parse('30_570_000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),
]);

// Creating an originalPrice object.
ECommercePrice originalPrice = ECommercePrice(fiat: ECommerceAmount(amount: Decimal.parse('5.78'), currency: "USD"),
internalComponents: [ // Optional.
    ECommerceAmount(amount: Decimal.parse('30570000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),`
]);
// Creating a product object.
ECommerceProduct product = ECommerceProduct(
sku: "779213",
name: "Danissimo curd product 5.9%, 130 g",  // Optional.
actualPrice: actualPrice, // Optional.
originalPrice: originalPrice, // Optional.
promocodes: ["BT79IYX", "UT5412EP"],  // Optional.
payload: payload,    // Optional.
categoriesPath: ["Groceries", "Dairy", "Yogurts"]  // Optional.
);

ECommerceEvent showProductDetailsEvent = ECommerce.showProductDetailsEvent(product, screen);
// Sending an e-commerce event.
AppMetrica.getReporter("Testing API key").reportECommerce(showProductDetailsEvent);
Adding/removing an item to/from the cart
Map<String, String> payload = {
    "configuration": "landscape",
    "full_screen": "true"
  };
// Creating a screen object.
ECommerceScreen screen = ECommerceScreen(
    name: "ProductCardActivity", // Optional.
    searchQuery: "danissimo maple syrup",  // Optional.
    payload: payload,  // Optional.
    categoriesPath: ["Promos","Hot deal"]  // Optional.
);
ECommerceAmount amount = ECommerceAmount(amount: Decimal.parse('4.53'), currency: "USD");
// Creating an actualPrice object.
ECommercePrice actualPrice = ECommercePrice(fiat: amount,
    internalComponents: [  // Optional.
    ECommerceAmount(amount: Decimal.parse('30570000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),
    ]);

// Creating an originalPrice object.
ECommercePrice originalPrice = ECommercePrice(fiat: ECommerceAmount(amount: Decimal.parse('5.78'), currency: "USD"),
    internalComponents: [ // Optional.
    ECommerceAmount(amount: Decimal.parse('30570000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),
    ]);
// Creating a product object.
ECommerceProduct product = ECommerceProduct(
    sku: "779213",
    name: "Danissimo curd product 5.9%, 130 g",  // Optional.
    actualPrice: actualPrice, // Optional.
    originalPrice: originalPrice, // Optional.
    promocodes: ["BT79IYX", "UT5412EP"],  // Optional.
    payload: payload,    // Optional.
    categoriesPath: ["Groceries", "Dairy", "Yogurts"]  // Optional.
);
ECommerceReferrer referrer = ECommerceReferrer(
    type: "button", // Optional.
    identifier: "76890", // Optional.
    screen: screen // Optional.
);
// Creating a cartItem object.
ECommerceCartItem addedItems1 = ECommerceCartItem(
    product: product,
    revenue: actualPrice,
    quantity: Decimal.parse("1.0"),
    referrer: referrer  // Optional.
);

ECommerceEvent addCartItemEvent = ECommerce.addCartItemEvent(addedItems1);
// Sending an e-commerce event.
AppMetrica.getReporter("Testing API key").reportECommerce(addCartItemEvent);
ECommerceEvent removeCartItemEvent = ECommerce.removeCartItemEvent(addedItems1);
// Sending an e-commerce event.
AppMetrica.getReporter("Testing API key").reportECommerce(removeCartItemEvent);
Starting and completing a purchase
Map<String, String> payload = {
    "configuration": "landscape",
    "full_screen": "true"
};
// Creating a screen object.
ECommerceScreen screen = ECommerceScreen(
    name: "ProductCardActivity", // Optional.
    searchQuery: "danissimo maple syrup",  // Optional.
    payload: payload,  // Optional.
    categoriesPath: ["Promos","Hot deal"]  // Optional.
);
ECommerceAmount amount = ECommerceAmount(amount: Decimal.parse('4.53'), currency: "USD");
// Creating an actualPrice object.
ECommercePrice actualPrice = ECommercePrice(fiat: amount,
    internalComponents: [  // Optional.
    ECommerceAmount(amount: Decimal.parse('30570000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),
    ]);

// Creating an originalPrice object.
ECommercePrice originalPrice = ECommercePrice(fiat: ECommerceAmount(amount: Decimal.parse('5.78'), currency: "USD"),
    internalComponents: [ // Optional.
    ECommerceAmount(amount: Decimal.parse('30570000'), currency: "wood"),
    ECommerceAmount(amount: Decimal.parse('26.89'), currency: "iron"),
    ECommerceAmount(amount: Decimal.parse('5.1'), currency: "gold"),
    ]);
// Creating a product object.
ECommerceProduct product = ECommerceProduct(
    sku: "779213",
    name: "Danissimo curd product 5.9%, 130 g",  // Optional.
    actualPrice: actualPrice, // Optional.
    originalPrice: originalPrice, // Optional.
    promocodes: ["BT79IYX", "UT5412EP"],  // Optional.
    payload: payload,    // Optional.
    categoriesPath: ["Groceries", "Dairy", "Yogurts"]  // Optional.
);
ECommerceReferrer referrer = ECommerceReferrer(
    type: "button", // Optional.
    identifier: "76890", // Optional.
    screen: screen // Optional.
);
// Creating a cartItem object.
ECommerceCartItem addedItems1 = ECommerceCartItem(
    product: product,
    revenue: actualPrice,
    quantity: Decimal.parse("1.0"),
    referrer: referrer  // Optional.
);
// Creating an order object.
ECommerceOrder order = ECommerceOrder(
    identifier: "88528768",
    items:[addedItems1],
    payload: payload // Optional.
);
ECommerceEvent beginCheckoutEvent = ECommerce.beginCheckoutEvent(order);
// Sending an e-commerce event.
AppMetrica.getReporter("Testing API key").reportECommerce(beginCheckoutEvent);
ECommerceEvent purchaseEvent = ECommerce.purchaseEvent(order);
// Sending an e-commerce event.
AppMetrica.getReporter("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 object to the main API key, use the method AppMetrica.reportECommerce(ECommerceEvent event);:

// ...
// 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