Cart events (Sales Insights)

  • iOS
  • watchOS
  • tvOS
 

Foreword

This tagging documentation only applies to Tracker from version 2.15.0.

If you can’t see the “Sales Insights” menu entry in Explorer, please get in touch with us so we can activate this for you.

 

Cart events

With the tracker, an ecommerce instance is available, exposing different objects and methods useful for measuring:

  • Cart displays

    Additionally, it’s possible to enable automatic tagging of SalesTracker cart content by overriding the “autoSalesTracker” configuration variable:

    let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
    tracker.ecommerce.setAutoSalesTrackerEnabled(true, sync: true, completionHandler: nil)
    Tracker* tracker = [ATInternet sharedInstance].defaultTracker;
    [tracker.ecommerce setAutoSalesTrackerEnabled:YES sync:YES completionHandler:nil];
    

  • Cart updates
  • Delivery and payment steps
  • Cart awaiting payment
  • Additionally, it’s possible to enable automatic tagging of SalesTracker orders by overriding the “autoSalesTracker” configuration variable:

    let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
    tracker.ecommerce.setAutoSalesTrackerEnabled(true, sync: true, completionHandler: nil)
    Tracker* tracker = [ATInternet sharedInstance].defaultTracker;
    [tracker.ecommerce setAutoSalesTrackerEnabled:YES sync:YES completionHandler:nil];
    

    The Sales Insights collection domain must be indicated via the “collectDomain” configuration variable:

    tracker.ecommerce.setCollectDomain("collect-euw1", sync: true, completionHandler: nil)
    [tracker.ecommerce setCollectDomain:@"collect-euw1" sync:YES completionHandler:nil];
    

The Sales Insights collection domain must be indicated via the “collectDomain” configuration variable:

tracker.ecommerce.setCollectDomain("collect-euw1", sync: true, completionHandler: nil)
[tracker.ecommerce setCollectDomain:@"collect-euw1" sync:YES completionHandler:nil];

See the full list of Ecommerce configuration variables that can be overridden at the end of this page.

 

Cart display

Measuring cart display is done by creating a DisplayCart object, to which the following are associated:

  • An ECommerceCart-type cart
  • A list of products, products, which can contain one or several ECommerceProduct type products.

A cart’s properties should be declared as a Dictionary-type collection, with different keys:

  • “id” – String: Cart ID (mandatory).
  • “currency” – String: Currency.
  • “turnovertaxincluded” – Float: Total amount of cart, including tax.
  • “turnovertaxfree” – Float: Total amount of cart, excluding tax.
  • “quantity” – Number: Total number of products in the cart.
  • “nbdistinctproduct” – Number: Number of distinct products in the cart.

A product’s properties should be declared as a Dictionary-type collection, with different keys:

  • “id” – String: Product ID (mandatory).
  • “$” – String: Product name.
  • “pricetaxincluded” – Float: Total price, including tax.
  • “pricetaxfree” – Float: Total price, excluding tax.
  • “quantity” – Number: Number of products in the cart.
  • “category1″ – String: The product’s level 1 category (up to 6 tree structure levels are possible; from “category1” to “category6”).

Declaring products is optional for the Sales Insights analysis. Products, if declared, only enable you to enrich the analysis with SalesTracker sales/order information. The only parameters to declare are therefore the parameters necessary for SalesTracker tagging.

In case of SalesTracker tagging activation, you can add screen data by passing an instance of Screen as a parameter.

Example

let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
// With SalesTracker
tracker.ecommerce.setAutoSalesTrackerEnabled(true, sync: true, completionHandler: nil)
let myScreen: Screen = tracker.screens.add("cart")
let dc: DisplayCart = tracker.ecommerce.displayCarts.add(screen:myScreen)
_ = dc.cart.setAll(obj:
    [
        "id": "53",
        "turnovertaxfree": 456.2,
        "turnovertaxincluded": 549,
        "nbdistinctproduct": 1,
        "quantity": 1,
        "currency": "EUR"
    ]
)
_ = dc.products.append(ECommerceProduct(obj: 
    [
        "id": "7",
        "$": "laptop_A56",
        "pricetaxincluded": 549,
        "pricetaxfree": 456.2, 
        "quantity": 1,
        "category1": "Computers_and_Networking",
        "category2": "Computers",
        "category3": "Laptops"
    ]))
tracker.dispatch()

You may use the independent method “tracker.events.send()” in order to send only your Ecommerce data.

Tracker* tracker = [ATInternet sharedInstance].defaultTracker;
// With SalesTracker
[tracker.ecommerce setAutoSalesTrackerEnabled:YES sync:YES completionHandler:nil];
Screen *myScreen = [tracker.screens add:@"cart"];
DisplayCart *dc = [[tracker.ecommerce displayCarts] addWithScreen:myScreen];
NSMutableArray *dcproducts = [dc.products mutableCopy];
(void)[dc.cart setAllWithObj:@{
    @"id": @"53",
    @"turnovertaxfree": @456.2,
    @"turnovertaxincluded":@549,
    @"nbdistinctproduct": @1,
    @"quantity": @1,
    @"currency": @"EUR"
}];
[dcproducts addObject:[[ECommerceProduct alloc] initWithObj:@{
    @"id": @"7",
    @"$": @"laptop_A56",
    @"pricetaxincluded": @549,
    @"pricetaxfree": @456.2,
    @"category1": @"Computers_and_Networking",
    @"category2": @"Computers", 
    @"quantity": @1,
    @"category3": @"Laptops"
}]];
[dc setProducts: dcproducts];
[tracker dispatch];

You may use the independent method “[tracker.events send];” in order to send only your Ecommerce data.

 

Display the delivery step

Measuring the delivery step is done by creating a DeliveryCheckout object, to which the following are associated:

  • an ECommerceCart-type cart
  • delivery data in the form of an ECommerceDelivery-type object

A cart’s properties should be declared as a Dictionary-type collection, with different keys:

  • “id” – String: Cart ID (mandatory).
  • “currency” – String: Currency.
  • “turnovertaxincluded” – Float: Total amount of cart, including tax.
  • “turnovertaxfree” – Float: Total amount of cart, excluding tax.
  • “quantity” – Number: Total number of products in the cart.
  • “nbdistinctproduct” – Number: Number of distinct products in the cart.

Delivery data should be declared as a Dictionary-type collection, with different keys (to be indicated if they are already known at this step):

  • “delivery” – String: Name of shipping company.
  • “costtaxincluded” – Float: Amount of shipping costs, including tax.
  • “costtaxfree” – Float: Amount of shipping costs, excluding tax.

Shipping data should only be indicated once, either during the delivery step, or during the payment step.

Example

let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
let dch: DeliveryCheckout = tracker.ecommerce.deliveryCheckouts.add()
_ = dch.cart.setAll(obj:
    [
        "id": "34",
        "turnovertaxfree": 34,
        "turnovertaxincluded": 40.8,
        "nbdistinctproduct": 1,
        "quantity": 1,
        "currency": "EUR"
    ]
)
_ = dch.shipping.setAll(obj:
    [
        "costtaxfree": 7,
        "costtaxincluded": 8.4,
        "delivery": "My carrier"
    ]
)
tracker.dispatch()

You may use the independent method “tracker.events.send()” in order to send only your Ecommerce data.

Tracker* tracker = [ATInternet sharedInstance].defaultTracker;
DeliveryCheckout *dch = [[tracker.ecommerce deliveryCheckouts] add];
(void)[dch.cart setAllWithObj:@{
    @"id": @"34",
    @"turnovertaxfree": @34,
    @"turnovertaxincluded": @40.8,
    @"nbdistinctproduct": @1,
    @"quantity": @1,
    @"currency": @"EUR"
}];
(void)[dch.shipping setAllWithObj:@{
    @"costtaxfree": @7,
    @"costtaxincluded": @8.4,
    @"delivery": @"My carrier"
}];
[tracker dispatch];

You may use the independent method “[tracker.events send];” in order to send only your Ecommerce data.

 

Display the payment step

Measuring the payment step is done by creating a PaymentCheckout object, to which the following are associated:

  • An ECommerceCart-type cart
  • Delivery data in the form of an ECommerceDelivery-type object

A cart’s properties should be declared as a Dictionary-type collection, with different keys:

  • “id” – String: Cart ID (mandatory).
  • “currency” – String: Currency.
  • “turnovertaxincluded” – Float: Total amount of cart, including tax (shipping costs included).
  • “turnovertaxfree” – Float: Total amount of cart, excluding tax (shipping costs included).
  • “quantity” – Number: Total number of products in the cart.
  • “nbdistinctproduct” – Number: Number of distinct products in the cart.

Delivery data should be declared as a Dictionary-type collection, with different keys (to be indicated if they are already known at this step):

  • “delivery” – String: Name of shipping company.
  • “costtaxincluded” – Float: Amount of shipping costs, including tax.
  • “costtaxfree” – Float: Amount of shipping costs, excluding tax.

Shipping data should only be indicated once, either during the delivery step, or during the payment step.

Example

let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
let pch: PaymentCheckout = tracker.ecommerce.paymentCheckouts.add()
_ = pch.cart.setAll(obj:
    [
        "id": "34",
        "turnovertaxfree": 34,
        "turnovertaxincluded": 40.8,
        "nbdistinctproduct": 1,
        "quantity": 1,
        "currency": "EUR"
    ]
)
_ = pch.shipping.setAll(obj:
    [
        "costtaxfree": 7,
        "costtaxincluded": 8.4,
        "delivery": "My carrier"
    ]
)
tracker.dispatch()

You may use the independent method “tracker.events.send()” in order to send only your Ecommerce data.

Tracker* tracker = [ATInternet sharedInstance].defaultTracker;
PaymentCheckout *pch = [[tracker.ecommerce paymentCheckouts] add];
(void)[pch.cart setAllWithObj:@{
    @"id": @"34",
    @"turnovertaxfree": @34,
    @"turnovertaxincluded": @40.8,
    @"nbdistinctproduct": @1,
    @"quantity": @1,
    @"currency": @"EUR"
}];
(void)[pch.shipping setAllWithObj:@{
    @"costtaxfree": @7,
    @"costtaxincluded": @8.4,
    @"delivery": @"My carrier"
}];
[tracker dispatch];

You may use the independent method “[tracker.events send];” in order to send only your Ecommerce data.

 

Cart awaiting payment

A cart awaiting payment has to be validated with a transaction confirmation on server-side.

Measuring a cart awaiting payment is done by creating a CartAwaitingPayment object, to which the following can be associated:

  • An ECommerceCart-type cart
  • A list of products, products, which can contain one or several ECommerceProduct-type products
  • Shipping data in an ECommerceShipping-type object
  • Payment data in an ECommercePayment-type object
  • Transaction data in an ECommerceTransaction-type object

A cart’s properties should be declared as a Dictionary-type collection, with different keys:

  • “id” – String: Cart ID.
  • “currency” – String: Currency.
  • “turnovertaxincluded” – Float: Total amount of cart, including tax (shipping costs included).
  • “turnovertaxfree” – Float: Total amount of cart, excluding tax (shipping costs included).
  • “creation_utc” – Date: Date of creation of the cart (timestamp UTC in seconds).
  • “quantity” – Number: Total number of products in the cart.
  • “nbdistinctproduct” – Number: Number of distinct products in the cart.

A product’s properties should be declared as a Dictionary-type collection, with different keys:

  • “id” – String: Product ID (mandatory).
  • “variant” – String: Product variant (size, colour, etc.).
  • “$” – String: Product name.
  • “brand” – String: Product brand.
  • “discount” – Boolean: Discounted product (0 for no; 1 for yes).
  • “pricetaxincluded” – Float: Price, including tax.
  • “pricetaxfree” – Float: Price, excluding tax.
  • “currency” – String: Currency.
  • “stock” – Boolean: Product in stock (0 for no; 1 for yes).
  • “quantity” – Number: Number of products to add.
  • “category1” – String: The product’s level 1 category (up to 6 tree structure levels are possible; from “category1” to “category6”).

Delivery data should be declared as a Dictionary-type collection, with different keys:

  • “delivery” – String: Name of shipping company.
  • “costtaxincluded” – Float: Amount of shipping costs, including tax.
  • “costtaxfree” – Float: Amount of shipping costs, excluding tax.

Payment method should be declared in a property:

  • “mode” – String: Payment method.

A transaction’s properties should be declared as a Dictionary-type collection, with different keys:

  • “promocode” – Array: Promotional code table including one or several codes. A promotional code is declared as a label.
  • “firstpurchase” – Boolean: First customer purchase (0 for no; 1 for yes).

If you use double tagging with SalesTracker, you will need to add a screen as a parameter on initializing the cart. The page should also be declared as a main goal.

Example

let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
// With SalesTracker
tracker.ecommerce.setAutoSalesTrackerEnabled(true, sync: true, completionHandler: nil)
let myScreen: Screen = tracker.screens.add("transaction")
let cap: CartAwaitingPayment = tracker.ecommerce.cartAwaitingPayments.add(screen: myScreen)
// Without SalesTracker
//tracker.ecommerce.setAutoSalesTrackerEnabled(false, sync: true, completionHandler: nil)
//let cap: CartAwaitingPayment = tracker.ecommerce.cartAwaitingPayments.add()
_ = cap.cart.setAll(obj:
    [
        "id": "34",
        "turnovertaxfree": 463.2,
        "turnovertaxincluded": 557.4,
        "nbdistinctproduct": 1,
        "quantity": 1,
        "currency": "EUR",
        "creation_utc": 1514973161 //UTC timestamp in seconds
    ]
)
cap.products.append(ECommerceProduct(obj: 
    [
        "id": "7",
        "variant": "1",
        "$": "laptop_A56",
        "brand": "ACER",
        "discount": 1,
        "pricetaxincluded": 549,
        "pricetaxfree": 456.2,
        "currency": "EUR",
        "stock": 1,
        "quantity": 1,
        "category1": "Computers_and_Networking",
        "category2": "Computers",
        "category3": "Laptops"
    ]))
_ = cap.shipping.setAll(obj:
    [
        "costtaxfree": 7,
        "costtaxincluded": 8.4,
        "delivery": "My carrier"
    ]
)
_ = cap.payment.set(key: "mode", value: "Credit card")
_ = cap.transaction.setAll(obj:
    [
        "promocode": ["DQQYRZSJ", "UN1ENE27"],
        "firstpurchase": 0
    ]
)
tracker.dispatch()

You may use the independent method “tracker.events.send()” in order to send only your Ecommerce data.

Tracker* tracker = [ATInternet sharedInstance].defaultTracker;
// With SalesTracker
[tracker.ecommerce setAutoSalesTrackerEnabled:YES sync:YES completionHandler:nil];
Screen *myScreen = [tracker.screens add:@"transaction"];
CartAwaitingPayment *cap = [[tracker.ecommerce cartAwaitingPayments] addWithScreen:myScreen];
// Without SalesTracker
//[tracker.ecommerce setAutoSalesTrackerEnabled:NO sync:YES completionHandler:nil];
//CartAwaitingPayment *cap = [[tracker.ecommerce cartAwaitingPayments] add];
NSMutableArray *capproducts = [cap.products mutableCopy];
(void)[cap.cart setAllWithObj:@{
    @"id": @"34",
    @"turnovertaxfree": @463.2,
    @"turnovertaxincluded": @557.4,
    @"nbdistinctproduct": @1,
    @"quantity": @1,
    @"currency": @"EUR",
    @"creation_utc": @1514973161 //UTC timestamp in seconds
}];
[capproducts addObject:[[ECommerceProduct alloc] initWithObj:@{
    @"id": @"7",
    @"variant": @"1",
    @"$": @"laptop_A56",
    @"brand": @"ACER",
    @"discount": @1,
    @"pricetaxincluded": @549,
    @"pricetaxfree": @456.2,
    @"currency": @"EUR",
    @"stock": @1,
    @"quantity": @1,
    @"category1": @"Computers_and_Networking",
    @"category2": @"Computers",
    @"category3": @"Laptops"
}]];
(void)[cap.shipping setAllWithObj:@{
    @"costtaxfree": @7,
    @"costtaxincluded": @8.4,
    @"delivery": @"My carrier"
}];
(void)[cap.payment setWithKey:@"mode" value: @"Credit card"];
(void)[cap.transaction setAllWithObj:@{
    @"promocode": @[@"DQQYRZSJ", @"UN1ENE27"],
    @"firstpurchase": @0
}];
[cap setProducts: capproducts];
[tracker dispatch];

You may use the independent method “[tracker.events send];” in order to send only your Ecommerce data.

 

Annexes

 

Configuration variables

NomValeur par défautDescriptionVersion
collectDomain“”Sales Insights collection domain >= 2.12.0
autoSalesTrackerfalseEnable automatic measurement of SalesTracker cart content on a cart display event >= 2.12.0
 

Was this post helpful?

Last update: 25/09/2019