Edit in GitHubLog an issue

Products variable

Set the products variable

Since the products variable cannot be set by processing rules, you need to set serialized events directly on the hits that are sent to Analytics.

To set the products variable, set a context data key to &&products, and set the value to the products or merchandising variable. For more information, see the implementing a merchandising variable tutorial.

Java

Syntax

Copied to your clipboard
cdata.put("&&products", "Category;Product;Quantity;Price[,Category;Product;Quantity;Price]");

Example

Copied to your clipboard
//create a context data dictionary
HashMap cdata = new HashMap<String, String>();
// add products, a purchase id, a purchase context data key, and any other data you want to collect.
// Note the special syntax for products
cdata.put("&&products", ";Running Shoes;1;69.95,;Running Socks;10;29.99");
cdata.put("myapp.purchase", "1");
cdata.put("myapp.purchaseid", "1234567890");
// send the tracking call - use either a trackAction or trackState call.
// trackAction example:
MobileCore.trackAction("purchase", cdata);
// trackState example:
MobileCore.trackState("Order Confirmation", cdata);

Kotlin

Example

Copied to your clipboard
//create a context data dictionary
val cdata: Map<String, Any?> = mapOf(
"&&products" to ";Running Shoes;1;69.95,;Running Socks;10;29.99",
"myapp.purchase" to "1",
"myapp.purchaseid" to "1234567890"
)
// send a tracking call - use either a trackAction or trackState call.
// trackAction example:
MobileCore.trackAction("purchase", cdata);
// trackState example:
MobileCore.trackState("Order Confirmation", cdata);

products is set directly on the image request, and the other variables are set as context data. All context data variables must be mapped by using processing rules:

Map products

You do not need to map the products variable using processing rules because it is set directly on the image request by the SDK.

Products variable with merchandising eVars and product-specific events

The following code samples show an example of the products variable with merchandising eVars and product-specific events.

Java

Example

Copied to your clipboard
//create a context data dictionary
HashMap cdata = new HashMap<String, String>();
// add products, a purchase id, a purchase context data key, and any other data you want to collect.
// Note the special syntax for products.
// There are two products in this example: Running shoes and Running Socks, they are separated by a comma.
// Attributes event1 and eVar1 only apply to Running Shoes.
cdata.put("&&events", "event1");
cdata.put("&&products", ";Running Shoes;1;69.95;event1=5.5;eVar1=Merchandising,;Running Socks;10;29.99");
cdata.put("myapp.purchase", "1");
cdata.put("myapp.purchaseid", "1234567890");
// send the tracking call - use either a trackAction or trackState call.
// trackAction example:
MobileCore.trackAction("purchase", cdata);
// trackState example:
MobileCore.trackState("Order Confirmation", cdata);

Kotlin

Example

Copied to your clipboard
//create a context data dictionary
val cdata: Map<String, Any?> = mapOf(
"&&events" to "event1",
"&&products" to ";Running Shoes;1;69.95;event1=5.5;eVar1=Merchandising,;Running Socks;10;29.99",
"myapp.purchase" to "1",
"myapp.purchaseid" to "1234567890"
)
// send a tracking call - use either a trackAction or trackState call.
// trackAction example:
MobileCore.trackAction("purchase", cdata);
// trackState example:
MobileCore.trackState("Order Confirmation", cdata);
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.