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 methodIf 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.

    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();
        }
    }
  2. 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();
        }
    }
  3. Resetting a cart after having completed an order
    private void finishOrder() {
            // Reset cart ID and remove all products
            tracker.Cart().unset();
    }
  4. Replacing an existing cart
    private void reinitCart() {
            // Set a new identifier for cart
            tracker.Cart().set("2");
    }
  5. 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);
    }
  6. Removing a product from the cart
    private void removeProduct(){
            tracker.Cart().Products().remove("ID[p1]");
    }
  7. Removing all products in the cart
    private void removeAllProducts(){
            tracker.Cart().Products().clear();
    }
 

Cart class

 

Properties

NameTypeDefault valueDescription
cartIdString“”Gets or sets the cart ID
productsProductsnullGets or sets the cart products
 

Methods

NameReturn typeDescription
setCartActivates the cart and defines an ID
unsetvoidResets the cart and removes the products
 

Product class

 

Properties

NameTypeDefault valueDescription
productIdStringnullGets or sets the product ID
category1StringnullGets or sets the first product category
category2StringnullGets or sets the second product category
category3StringnullGets or sets the third product category
category4StringnullGets or sets the fourth product category
category5StringnullGets or sets the fifth product category
category6StringnullGets or sets the sixth product category
quantityInt-1Gets or sets the product quantity
unitPriceTaxIncludedDouble-1Gets or sets the price per unit (including tax)
unitPriceTaxFreeDouble-1Gets or sets the price per unit (without tax)
discountTaxIncludedDouble-1Gets or sets the discount amount (including tax)
discountTaxFreeDouble-1Gets or sets the discount amount (without tax)
promotionalCodeStringnullGets or sets the product’s promotional code
 

Was this post helpful?

Last update: 05/04/2018