Developers » Windows » Ecommerce » Cart
Cart
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.
To use SDK class and methods, add ATInternet namespace to your Page.
Tagging
The tracker makes a Cart object 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 carts ID
The Cart object also exposes a Products object allowing you to add or remove products to/from the cart.
The Products object 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
- 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.
using System; using System.Collections.Generic; using Windows.Data.Json; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using ATInternet; using Windows.UI.Xaml.Navigation; namespace App1 { public sealed partial class MainPage : Page { Tracker tracker; public MainPage() { this.InitializeComponent(); tracker = SmartTag.Instance.defaultTracker; } protected override void OnNavigatedTo(NavigationEventArgs e) { // Enable cart and set an identifier tracker.Cart.Set("5"); Product p1 = tracker.Cart.Products.Add("ID[p1]"); p1.Category1 = "10Shoes"; p1.Quantity = 1; p1.UnitPriceTaxFree = 70; p1.UnitPriceTaxIncluded = 85; Product p2 = tracker.cart.products.Add("ID[P2]"); p2.Category1 = "20Socks"; p2.Quantity = 2; p2.UnitPriceTaxFree = 7; p2.UnitPriceTaxIncluded = 10; // If isBasketScreen is not set to true, Cart info won't be added to Screen hit Screen s = tracker.Screens.Add("order confirm"); s.IsBasketScreen = true; s.SendView(); } } }
- Tagging an order with cart information
For more information on tagging your orders, visit this page: Orders (SalesTracker)
using System; using System.Collections.Generic; using Windows.Data.Json; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using ATInternet; using Windows.UI.Xaml.Navigation; namespace App1 { public sealed partial class MainPage : Page { Tracker tracker; public MainPage() { this.InitializeComponent(); tracker = SmartTag.Instance.defaultTracker; } protected override void OnNavigatedTo(NavigationEventArgs e) { tracker.Cart.Set("5"); Product p1 = tracker.Cart.Products.Add("ID[p1]"); p1.Category1 = "10Shoes"; p1.Quantity = 1; p1.UnitPriceTaxFree = 70; p1.UnitPriceTaxIncluded = 85; Product p2 = tracker.Cart.Products.Add("ID[P2]"); p2.Category1 = "20Socks"; p2.Quantity = 2; p2.UnitPriceTaxFree = 7; p2.UnitPriceTaxIncluded = 10; Order order = tracker.Orders.Add("cmd1", 94.40, 1); order.NewCustomer = true; order.Amount.TaxAmount = 3.0; order.Amount.AmountTaxFree = 5.0; order.Amount.AmountTaxIncluded = 8.0; order.Delivery.ShippingFeesTaxFree = 4; order.Delivery.ShippingFeesTaxIncluded = 7.5; order.Delivery.DeliveryMethod = "TNT"; order.Discount.DiscountTaxFree = 2; order.Discount.DiscountTaxIncluded = 2.5; order.Discount.PromotionalCode = "SUMMER"; // If isBasketScreen is not set to true, Cart info won't be added to Screen hit Screen s = tracker.Screens.Add("order confirmation"); s.IsBasketScreen = true; s.SendView(); tracker.Cart.Unset(); } } }
- Resetting a cart after having completed an order
private void FinishOrder() { // Reset cart ID and remove all products tracker.Cart.Unset(); }
- Replacing an existing cart
private void ReinitCart() { // Set a new identifier for cart tracker.Cart.Set("2"); }
- Adding products to the cart
private void AddProduct() { Product p1 = tracker.Cart.Products.Add("ID[p1]"); p1.Category1 = "10Shoes"; p1.Quantity = 1; p1.UnitPriceTaxFree = 70; p1.UnitPriceTaxIncluded = 85; p1.PromotionalCode = "ATCode"; p1.DiscountTaxFree = 0; p1.DiscountTaxIncluded = 0; }
- Removing a product from the cart
private void RemoveProduct() { tracker.Cart.Products.Remove("ID[p1]"); }
- Removing all products in the cart
private void RemoveAllProducts() { tracker.Cart.Products.Clear(); }
Cart class
Properties
Name | Type | Default value | Description |
---|---|---|---|
CartId | String | “” | Gets or sets the cart ID |
Products | Products | null | 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 |