Tutorial

Tracking Cart State

Granify.trackCart is used to tell Granify what contents the customer currently has in their cart. This implementation requires all cart data, in order to sync the customer's cart with Granify. It's crucial that this is kept up-to-date.

Placement

Granify.trackCart should be called:

  • After any change is made to the cart. This includes immediately after 'Buy It Now' or other express purchase buttons, as well as item removal.
  • On each page load (in case a return user comes back to a page with items in their cart)
  • On a new session start (in case a return user comes back to a page with items in their cart)

It is very important that we are in sync with the cart contents. Otherwise, cart-related campaigns will not work.

Usage

For usage information, see the Granify.trackCart documentation.

Example

Granify('trackCart', {
  items: [{
    sku: '123456',
    product_id: '123',
    quantity: 1,
    price: 100.00,
    regular_price: 100.00,
    title: 'My Product Title',
    image: 'https://example.com/example.jpg',
  }, {
    sku: '234567',
    product_id: '234',
    quantity: 1,
    price: 50.00,
    regular_price: 100.00,
    title: 'Another Product Title',
    image: 'https://example.com/example2.jpg',
  }]
});

// To clear the cart:
Granify('trackCart', false);

Next: Tracking Product Details