Add to cart tracking code
Description
This tracking code should be passed the product ID that corresponds to the product ID passed in the product database. It should be executed when clicking on all buttons that lead to adding a product to the cart. (On the product card page/in the category listing/on the quick view modal window)
It should also be called when the user clicks on the "Buy in 1 click" or "Quick order" button, even if the product is not added to the cart. Clicking on these buttons are actions that are as close as possible to placing an order, so it is important to record this user behavior.
If the integration involves the use of regions (stocks), then the tracking code must additionally pass the ID of the region in which the user is located.
All code examples below are provided in two tabs - with and without region support.
<stock_id> - region identifier, can be a string. Must match the region identifier passed in the product database.
Code example
- Without regionality
- With regionality
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
try { rrApi.addToBasket(<product_id>); } catch(e) {}
})
</script>
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
try { rrApi.addToBasket(<product_id>,{'stockId': '<stock_id>'}); } catch(e) {}
})
</script>
Support for string identifiers
If the product identifiers in the product database have string identifiers, an object with the isProductIdString parameter must be additionally passed to the tracking code, an example is shown below
- Without regionality
- With regionality
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
try{ rrApi.addToBasket(<product_id>, {"isProductIdString": true}); } catch(e) {}
})
</script>
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
try{ rrApi.addToBasket(<product_id>,{"stockId": "<stock_id>", "isProductIdString": true}); } catch(e) {}
})
</script>