We use two different functions in tandem to track the current product in your app. In addition, we use a separate function to track the products that have been added to the cart.
trackProduct
The first function we use, trackProduct
, tells us about the current product as a Product. It tells us all the possible variations of the product. It is important that you tell us about every variation that is actively available. We use this list as the source data for the setCurrentProduct
function, but the Contextual Commerce Brain will also use this list to match up to any specific specials or hot items.
In addition to the list of possible variations, you also need to provide a Carter
. This simple class will be called from campaigns that offer an "Add To Cart" button. This button is intended to simulate the "Add To Cart" functionality of the product page itself. The callback should add the current product to the cart, using the currently selected options, exactly as if the shopper had clicked the button on the page itself. If the behavior of your app would be to collect additional information before actually adding the product to the cart (eg: if sizes or colors have not been selected yet), then this function should initiate the same behavior.
see trackProduct(...)
for more details
setCurrentProduct
The second function, setCurrentProduct
, tells us which of the variations of the product is currently selected. The function only accepts strings for the sku and productId parameters because these are used to simply lookup the variation from the list supplied in the last trackProduct
call. The sku and productId must match exactly one of those Product
s.
This function must be called immediately after the trackProduct
function is called. This will tell us which variation of the product is currently selected. This would normally be the default item, but there may be some logic to choose a default for each shopper, or the shopper may be returning to a previous choice.
In addition, every time a shopper changes their selection, you must call this function again identifying the new sku as the new current variation.
see setCurrentProduct(...)
for more details
trackCart
You must use the trackCart
function to keep Contextual Commerce up-to-date about your cart details.
Whenever a product is added to the shopper's cart, or the cart is modified in any other way, you must call trackCart
. You should also call trackCart
when the app starts, and whenever the app returns after losing focus for any reason. Pass the complete contents of the cart with every call, even if the cart is empty.
It is not absolutely required that you use the same referenced Product
object for the cart that you did for the trackProduct
call, but the information in the object must be the same. It is especially important that both the productId and the sku are identical for the same product.
see trackCart()
for more details.
When the shopper returns after hiding or suspending the app, or returns after idling for long periods of time (greater than 30 minutes), communication with Contextual Commerce's servers may have ceased. In this case the shopping session has become inactive and a new session will be created.
When a new session starts, the SDK will re-send its most recent cached information about the shopper (i.e. shopper id, cart, and wish list information) to the server to initialize the new session’s data. It is important however to call any of the Contextual Commerce's session tracking functions with updated information if it may have been changed while the app was idle or suspended. For example, if a shopper’s cart is synced with their account across multiple devices, changes made on other devices will require trackCart(...)
to be called when the app becomes aware of the change to the cart.
Information specific to the shopper’s current session will not be cached and automatically sent to Contextual Commerce's servers on app resume. Therefore, it is important to call the trackProduct
, and setCurrentProduct
explicitly with the information for the app view that loads when resuming from a suspended state (after calling trackPageView
, of course).