Developers » Apple » Ecommerce » Cart
Cart
- iOS
- watchOS
- tvOS
Foreword
AT Internets SDK allows you to tag your applications 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 the headers ATInternet.h, ATTracker.h, ATScreen.h, ATCart.h and ATProduct.h.
Tagging
The tracker makes a cart property available. This property exposes the following methods:
- set (or setWithId in Objective-C): 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 carts 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 (or addWithId in Objective-C): Adds a product to the cart and returns a Product object
- remove (or removeWithId in Objective-C): 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
- 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.
12345678910111213141516171819202122232425262728293031323334353637import UIKitimport Trackerclass ViewController: UIViewController {let tracker: Tracker = ATInternet.sharedInstance.defaultTrackeroverride func viewDidLoad() {super.viewDidLoad()}override func viewWillAppear(animated: Bool) {// Enable cart and set an identifiertracker.cart.set("1")let p1 = tracker.cart.products.add("ID[p1]")p1.category1 = "10[Shoes]"p1.quantity = 1p1.unitPriceTaxFree = 70p1.unitPriceTaxIncluded = 85p1.promotionalCode = "ATInternet"p1.discountTaxFree = 0p1.discountTaxIncluded = 0let p2 = tracker.cart.products.add("ID[p2]")p2.category1 = "20[Socks]"p2.quantity = 2p2.unitPriceTaxFree = 5p2.unitPriceTaxIncluded = 7let cartScreen = tracker.screens.add("Cart resume")// If isBasketScreen is not set to true, Cart info won't be added to Screen hitcartScreen.isBasketScreen = truecartScreen.sendView()}}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#import "ViewController.h"#import "ATInternet.h"#import "ATTracker.h"#import "ATScreen.h"#import "ATCart.h"#import "ATProduct.h"@interface ViewController ()@property (nonatomic, strong) ATTracker* 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 setWithId:@"1"];ATProduct *p1 = [self.tracker.cart.products addWithId:@"ID[p1]"];p1.category1 = @"10[Shoes]";p1.quantity = 1;p1.unitPriceTaxFree = 70;p1.unitPriceTaxIncluded = 85;p1.promotionalCode = @"ATInternet";p1.discountTaxFree = 0;p1.discountTaxIncluded = 0;ATProduct *p2 = [self.tracker.cart.products addWithId:@"ID[p2]"];p2.category1 = @"20[Socks]";p2.quantity = 2;p2.unitPriceTaxFree = 5;p2.unitPriceTaxIncluded = 7;ATScreen* cartScreen = [self.tracker.screens addWithName:@"Cart resume"];// If isBasketScreen is not set to true, Cart info won't be added to Screen hitcartScreen.isBasketScreen = YES;[cartScreen sendView];}@end - Tagging an order with cart information
For more information on tagging your orders, visit this page: Orders (SalesTracker)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import UIKitimport Trackerclass ViewController: UIViewController {let tracker: Tracker = ATInternet.sharedInstance.defaultTrackeroverride 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 = 1p1.unitPriceTaxFree = 70p1.unitPriceTaxIncluded = 85p1.promotionalCode = "ATInternet"p1.discountTaxFree = 0p1.discountTaxIncluded = 0let p2 = tracker.cart.products.add("ID[p2]")p2.category1 = "20[Socks]"p2.quantity = 2p2.unitPriceTaxFree = 5p2.unitPriceTaxIncluded = 7let order = tracker.orders.add("cmd1", turnover: 94.30, status: 1)// First order from that customerorder.isNewCustomer = true// Order amountorder.amount.set(80, amountTaxIncluded: 94.30, taxAmount: 14)// Order delivery infoorder.delivery.set(5, shippingFeesTaxIncluded: 7.5, deliveryMethod: "1[UPS]")// Discount infoorder.discount.set(5, discountTaxIncluded: 7.5, promotionalCode: "SUMMER")let confirmOrderScreen = tracker.screens.add("Order confirmation")confirmOrderScreen.sendView()tracker.cart.unset()}}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#import "ViewController.h"#import "ATInternet.h"#import "ATTracker.h"#import "ATScreen.h"#import "ATCart.h"#import "ATProduct.h"#import "ATOrder.h"@interface ViewController ()@property (nonatomic, strong) ATTracker* 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 setWithId:@"1"];ATProduct *p1 = [self.tracker.cart.products addWithId:@"ID[p1]"];p1.category1 = @"10[Shoes]";p1.quantity = 1;p1.unitPriceTaxFree = 70;p1.unitPriceTaxIncluded = 85;p1.promotionalCode = @"ATInternet";p1.discountTaxFree = 0;p1.discountTaxIncluded = 0;ATProduct *p2 = [self.tracker.cart.products addWithId:@"ID[p2]"];p2.category1 = @"20[Socks]";p2.quantity = 2;p2.unitPriceTaxFree = 5;p2.unitPriceTaxIncluded = 7;ATOrder* order = [self.tracker.orders addWithId:@"cmd1" turnover: 94.30 status: 1];// First order from that customerorder.isNewCustomer = YES;// Order amount[order.amount setWithAmountTaxFree:80 amountTaxIncluded: 94.30 taxAmount: 14];// Order delivery info[order.delivery setWithShippingFeesTaxFree:5 shippingFeesTaxIncluded: 7.5 deliveryMethod: @"1[UPS]"];// Discount info[order.discount setWithDiscountTaxFree:5 discountTaxIncluded: 7.5 promotionalCode: @"SUMMER"];ATScreen *confirmOrderScreen = [self.tracker.screens addWithName:@"Order confirmation"];[confirmOrderScreen sendView];[self.tracker.cart unset];}@end - Resetting a cart after having completed an order
123456@IBAction func finishOrder(sender: UIButton) {// Reset cart ID and remove all productstracker.cart.unset()}12345- (IBAction)finishOrder:(UIButton *)sender {[self.tracker.cart unset];}
- Replacing an existing cart
123456@IBAction func reinitCart(sender: UIButton) {// Set a new identifier for carttracker.cart.set("2")}12345- (IBAction)reinitCart:(UIButton *)sender {[self.tracker.cart setWithId:@"2"];}
- Adding products to the cart
123456789101112@IBAction func addProduct2Cart(sender: UIButton) {let p1 = tracker.cart.products.add("ID[p1]")p1.category1 = "10[Shoes]"p1.quantity = 1p1.unitPriceTaxFree = 60p1.unitPriceTaxIncluded = 75p1.promotionalCode = "SUMMER"p1.discountTaxFree = 5p1.discountTaxIncluded = 7.5}123456789101112- (IBAction)addProductToCart:(UIButton *)sender {ATProduct *p1 = [self.tracker.cart.products addWithId:@"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;}
- Removing a product from the cart
12345@IBAction func removeProductFromCart(sender: UIButton) {tracker.cart.products.remove("ID[p1]")}12345- (IBAction)removeProductFromCart:(UIButton *)sender {[self.tracker.cart.products removeWithId:@"ID[p1]"];}
- Removing all products in the cart
12345@IBAction func emptyCart(sender: UIButton) {tracker.cart.products.removeAll()}12345- (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 products promotional code |
Was this post helpful?
Yes
No