Cart

  • iOS
  • watchOS
  • tvOS
 

Foreword

AT Internet’s SDK allows you to tag your application’s basket or cart, as well as its contents.

As with a real cart, you can add or remove products from the cart and send this information in your screen hit.

 

Get off to a good start

Once your tag is initialised, you can add cart information to your screen hit.

In the case of a Swift project, be sure to import the Tracker (or TrackerExtension if your target is an extension) module in your ViewController. In the case of an Objective-C project, be sure to import SmartTracker-Swift.h

 

Tagging

The tracker makes a cart property available. This property exposes the following methods:

  • set : Allows you to define a cart ID to then be able to add products

    So that cart information is successfully taken into account, the ID must be greater than zero

  • unset: Allows you to remove products from the cart and to reset the cart’s ID

The cart property also exposes a products property allowing you to add or remove products to/from the cart.

The products property exposes the following methods:

  • add : Adds a product to the cart and returns a Product object
  • remove : Deletes a product from the cart
  • removeAll : Removes all products contained in the cart

To send cart information without sending order information, you must define the property isBasketScreen of your Screen object as true. If not, cart information will not be added to your screen hit.

 

Tagging examples

  1. Tagging a screen summarising the content of a cart with 2 articles

    The cart ID must be identical to the ID present in the order content tag; if not, the cart will be considered as abandoned. Please also remember, the ID used for the cart must be unique and should never be reused, in order to avoid inconsistencies in your analyses.

    import UIKit
    import Tracker
    
    class ViewController: UIViewController {
        let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
        
        override func viewDidLoad() {
            super.viewDidLoad()
        }
        
        override func viewWillAppear(animated: Bool) {
            // Enable cart and set an identifier
            tracker.cart.set("1")
            
            let p1 = tracker.cart.products.add("ID[p1]")
            p1.category1 = "10[Shoes]"
            p1.quantity = 1
            p1.unitPriceTaxFree = 70
            p1.unitPriceTaxIncluded = 85
            p1.promotionalCode = "ATInternet"
            p1.discountTaxFree = 0
            p1.discountTaxIncluded = 0
            
            let p2 = tracker.cart.products.add("ID[p2]")
            p2.category1 = "20[Socks]"
            p2.quantity = 2
            p2.unitPriceTaxFree = 5
            p2.unitPriceTaxIncluded = 7
            
            let cartScreen = tracker.screens.add("Cart resume")
            // If isBasketScreen is not set to true, Cart info won't be added to Screen hit
            cartScreen.isBasketScreen = true
            cartScreen.sendView()
        }
    }
    #import "ViewController.h"
    #import "SmartTracker/SmartTracker-Swift.h"
    
    @interface ViewController ()
    @property (nonatomic, strong) Tracker* tracker;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.tracker = [ATInternet sharedInstance].defaultTracker;
    }
    
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        // Enable cart and set an identifier
        [self.tracker.cart set:@"1"];
        
        Product *p1 = [self.tracker.cart.products add:@"ID[p1]"];
        p1.category1 = @"10[Shoes]";
        p1.quantity = 1;
        p1.unitPriceTaxFree = 70;
        p1.unitPriceTaxIncluded = 85;
        p1.promotionalCode = @"ATInternet";
        p1.discountTaxFree = 0;
        p1.discountTaxIncluded = 0;
        
        Product *p2 = [self.tracker.cart.products add:@"ID[p2]"];
        p2.category1 = @"20[Socks]";
        p2.quantity = 2;
        p2.unitPriceTaxFree = 5;
        p2.unitPriceTaxIncluded = 7;
        
        Screen* cartScreen = [self.tracker.screens add:@"Cart resume"];
       // If isBasketScreen is not set to true, Cart info won't be added to Screen hit
        cartScreen.isBasketScreen = YES;
        [cartScreen sendView];
    }
    
    @end
  2. Tagging an order with cart information

    For more information on tagging your orders, visit this page: Orders (SalesTracker)

    import UIKit
    import Tracker
    
    class ViewController: UIViewController {
        let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            tracker.debugger = self
        }
        
        override func viewWillAppear(animated: Bool) {
            tracker.cart.set("1")
            
            let p1 = tracker.cart.products.add("ID[p1]")
            p1.category1 = "10[Shoes]"
            p1.quantity = 1
            p1.unitPriceTaxFree = 70
            p1.unitPriceTaxIncluded = 85
            p1.promotionalCode = "ATInternet"
            p1.discountTaxFree = 0
            p1.discountTaxIncluded = 0
            
            let p2 = tracker.cart.products.add("ID[p2]")
            p2.category1 = "20[Socks]"
            p2.quantity = 2
            p2.unitPriceTaxFree = 5
            p2.unitPriceTaxIncluded = 7
            
            let order = tracker.orders.add("cmd1", turnover: 94.30, status: 1)
            // First order from that customer
            order.isNewCustomer = true
            // Order amount
            order.amount.set(80, amountTaxIncluded: 94.30, taxAmount: 14)
            // Order delivery info
            order.delivery.set(5, shippingFeesTaxIncluded: 7.5, deliveryMethod: "1[UPS]")
            // Discount info
            order.discount.set(5, discountTaxIncluded: 7.5, promotionalCode: "SUMMER")
            
            let confirmOrderScreen = tracker.screens.add("Order confirmation")
            confirmOrderScreen.sendView()
            
            tracker.cart.unset()
        }
    }
    #import "ViewController.h"
    #import "SmartTracker/SmartTracker-Swift.h"
    
    @interface ViewController ()
    @property (nonatomic, strong) Tracker* tracker;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.tracker = [ATInternet sharedInstance].defaultTracker;
        self.tracker.debugger = self;
    }
    
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        [self.tracker.cart set:@"1"];
        
        Product *p1 = [self.tracker.cart.products add:@"ID[p1]"];
        p1.category1 = @"10[Shoes]";
        p1.quantity = 1;
        p1.unitPriceTaxFree = 70;
        p1.unitPriceTaxIncluded = 85;
        p1.promotionalCode = @"ATInternet";
        p1.discountTaxFree = 0;
        p1.discountTaxIncluded = 0;
        
        Product *p2 = [self.tracker.cart.products add:@"ID[p2]"];
        p2.category1 = @"20[Socks]";
        p2.quantity = 2;
        p2.unitPriceTaxFree = 5;
        p2.unitPriceTaxIncluded = 7;
        
        Order* order = [self.tracker.orders add:@"cmd1" turnover: 94.30 status: 1];
        // First order from that customer
        order.isNewCustomer = YES;
        // Order amount
        [order.amount set:80 amountTaxIncluded: 94.30 taxAmount: 14];
        // Order delivery info
        [order.delivery set:5 shippingFeesTaxIncluded: 7.5 deliveryMethod: @"1[UPS]"];
        // Discount info
        [order.discount set:5 discountTaxIncluded: 7.5 promotionalCode: @"SUMMER"];
        
        Screen *confirmOrderScreen = [self.tracker.screens add:@"Order confirmation"];
        [confirmOrderScreen sendView];
        
        [self.tracker.cart unset];
    }
    
    @end
  3. Resetting a cart after having completed an order

    @IBAction func finishOrder(sender: UIButton) {
        // Reset cart ID and remove all products
        tracker.cart.unset()
    }
    
    - (IBAction)finishOrder:(UIButton *)sender {
        [self.tracker.cart unset];
    }
  4. Replacing an existing cart

    @IBAction func reinitCart(sender: UIButton) {
        // Set a new identifier for cart
        tracker.cart.set("2")
    }
    - (IBAction)reinitCart:(UIButton *)sender {
        [self.tracker.cart setWithId:@"2"];
    }
  5. Adding products to the cart

    @IBAction func addProduct2Cart(sender: UIButton) {
        let p1 = tracker.cart.products.add("ID[p1]")
        p1.category1 = "10[Shoes]"
        p1.quantity = 1
        p1.unitPriceTaxFree = 60
        p1.unitPriceTaxIncluded = 75
        p1.promotionalCode = "SUMMER"
        p1.discountTaxFree = 5
        p1.discountTaxIncluded = 7.5
    }
    - (IBAction)addProductToCart:(UIButton *)sender {
        Product *p1 = [self.tracker.cart.products add:@"ID[p1]"];
        p1.category1 = @"10[Shoes]";
        p1.quantity = 1;
        p1.unitPriceTaxFree = 60;
        p1.unitPriceTaxIncluded = 75;
        p1.promotionalCode = @"SUMMER";
        p1.discountTaxFree = 5;
        p1.discountTaxIncluded = 7.5;
    }
  6. Removing a product from the cart

    @IBAction func removeProductFromCart(sender: UIButton) {
       tracker.cart.products.remove("ID[p1]")
    }
    - (IBAction)removeProductFromCart:(UIButton *)sender {
        [self.tracker.cart.products remove:@"ID[p1]"];
    }
  7. Removing all products in the cart

    @IBAction func emptyCart(sender: UIButton) {
       tracker.cart.products.removeAll()
    }
    - (IBAction)emptyCart:(UIButton *)sender {
        [self.tracker.cart.products removeAll];
    }
 

Cart class

 

Properties

Name Type Default value Description
cartId String “” Gets or sets the cart ID
products CartProducts nil Gets or sets the cart products
 

Methods

Name Return type Description
set Cart Activates the cart and defines an ID
unset void Resets the cart and removes the products
 

Product class

 

Properties

Name Type Default value Description
productId String null Gets or sets the product ID
category1 String null Gets or sets the first product category
category2 String null Gets or sets the second product category
category3 String null Gets or sets the third product category
category4 String null Gets or sets the fourth product category
category5 String null Gets or sets the fifth product category
category6 String null Gets or sets the sixth product category
quantity Int -1 Gets or sets the product quantity
unitPriceTaxIncluded Double -1 Gets or sets the price per unit (including tax)
unitPriceTaxFree Double -1 Gets or sets the price per unit (without tax)
discountTaxIncluded Double -1 Gets or sets the discount amount (including tax)
discountTaxFree Double -1 Gets or sets the discount amount (without tax)
promotionalCode String null Gets or sets the product’s promotional code
 

Was this post helpful?

Last update: 13/12/2016