The following are some key things to note about the Add to cart Javascript event:
- Nearly the same as "Item Page View" event, but just adding one more line of code for setting of the action.
- This event should fire on any "Add to Cart" button on the site, and is what enables our "Cart Abandon" stage for users in Cortex.
Add to cart event details
The add to cart event is used for tracking each item that is added to the shopping cart. The add to cart will be very similar to the item page view, but with one additional call to ‘_setAction’.
The item_id should correspond to the item’s unique record ID within your database.
Insert this code into the /*** EVENT SPECIFIC CODE ***/ section:
/*** EVENT SPECIFIC CODE ***/
_rsq.push(['_addItem', {
'id':'item_id', // replace item_id with your dynamic item_id variable
'name':"item_title", // replace item_title with your dynamic item_title variable
'price':'item_price'// replace item_price with your dynamic item_price variable
}]);
_rsq.push(['_setAction', 'shopping_cart']);
/*** END EVENT SPECIFIC CODE ***/
Add to cart code sample
<!-- RetentionScience start -->
<script type='text/javascript'>
var _rsq = _rsq || [];
_rsq.push(['_setSiteId', 'site_id']); // replace site_id with your static Site ID
_rsq.push(['_enableOnsite']);
if (condition) { // replace condition with your parameters for checking if a user is logged in
_rsq.push(['_setUserId', 'user_id']); // replace user_id with your dynamic user_id variable
_rsq.push(['_setUserEmail','user_email']); // replace user_email with your dynamic user_email variable
}
/*** EVENT SPECIFIC CODE ***/
_rsq.push(['_addItem', {
'id':'item_id', // replace item_id with your dynamic item_id variable
'name':"item_title", // replace item_title with your dynamic item_title variable
'price':'item_price'// replace item_price with your dynamic item_price variable
}]);
_rsq.push(['_setAction', 'shopping_cart']);
/*** END EVENT SPECIFIC CODE ***/
_rsq.push(['_track']);
(function() {
var rScix = document.createElement('script');
rScix.type = 'text/javascript';
rScix.async = true;
rScix.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'd1stxfv94hrhia.cloudfront.net/waves/v3/w.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(rScix);
})();
</script>
<!-- RetentionScience end -->
Comments
0 comments
Please sign in to leave a comment.