Developers » AS2 tagging » Android » Ecommerce » SalesTracker » Cart 2.3.0
Cart
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.
If you want to use variables, be sure to import ATInternet, Tracker, Screen and Cart classes in your Activity.
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 cart’s 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 link your cart with your screen using setCart Screen object method. 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.
package com.atinternet.atinternetdemo; import android.app.Activity; import android.os.Bundle; import com.atinternet.tracker.ATInternet; import com.atinternet.tracker.Tracker; public class MainActivity extends Activity { private Tracker tracker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tracker = ATInternet.getInstance().getDefaultTracker(); } @Override protected void onResume() { super.onResume(); // Enable cart and set an identifier Cart cart = tracker.Cart().set("3"); cart.Products().add("ID[p1]") .setCategory1("10[Shoes]") .setQuantity(1) .setUnitPriceTaxFree(70) .setUnitPriceTaxIncluded(85) .setPromotionalCode("ATCode") .setDiscountTaxFree(0) .setDiscountTaxIncluded(0); cart.Products().add("ID[p2]") .setCategory1("20[Socks]") .setQuantity(2) .setUnitPriceTaxFree(70) .setUnitPriceTaxIncluded(85); Screen s = tracker.Screens().add("Order confirmation"); s.setCart(cart); s.sendView(); } }
- Tagging an order with cart information
For more information on tagging your orders, visit this page: Orders (SalesTracker)
package com.atinternet.atinternetdemo; import android.app.Activity; import android.os.Bundle; import com.atinternet.tracker.ATInternet; import com.atinternet.tracker.Tracker; public class MainActivity extends Activity { private Tracker tracker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tracker = ATInternet.getInstance().getDefaultTracker(); } @Override protected void onResume() { super.onResume(); Cart cart = tracker.Cart().set("3"); cart.Products().add("ID[p1]") .setCategory1("10[Shoes]") .setQuantity(1) .setUnitPriceTaxFree(70) .setUnitPriceTaxIncluded(85) .setPromotionalCode("ATCode") .setDiscountTaxFree(0) .setDiscountTaxIncluded(0); cart.Products().add("ID[p2]") .setCategory1("20[Socks]") .setQuantity(2) .setUnitPriceTaxFree(70) .setUnitPriceTaxIncluded(85); Screen s = tracker.Screens().add("Order confirmation"); s.Order("cmd1", 94.40) .setStatus(1) .setNewCustomer(true) .Amount().set(80, 94.40, 14) .Delivery().set(4, 7.5, "1[TNT]") .Discount().set(5, 7.5, "SUMMER"); s.setCart(cart); 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(){ tracker.Cart().Products().add("ID[p1]") .setCategory1("10[Shoes]") .setQuantity(1) .setUnitPriceTaxFree(70) .setUnitPriceTaxIncluded(85) .setPromotionalCode("ATCode") .setDiscountTaxFree(0) .setDiscountTaxIncluded(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 product’s promotional code |