setDataItem

Description

The setDataItem is a way to pass custom data into CartStack so it can be used to personalize your email templates. It's often thought of as our custom fields solution. Once the data has been passed into our system you can display it by adding a simple variable to your email template. 

Function Call
_cartstack.push(['setDataItem', { 'field name':'field value' }]);
Code Examples 

This shows two custom fields: first name and coupon code.

<script data-siteid="XXXXXX" src="https://api.cartstack.com/js/customer-tracking/XXXXXXXXXX_222b5fb1025a6f580288f22cbd29c1bc.js" type="text/javascript"></script>

//custom fields
<script type="text/javascript">
_cartstack.push(['setDataItem', { 'firstName':'Dave' }]);
_cartstack.push(['setDataItem', { 'coupon':'abc123' }]);
 
</script>

This shows tracking and capture for the first name.

<script data-siteid="XXXXXX" src="https://api.cartstack.com/js/customer-tracking/XXXXXXXXXX_222b5fb1025a6f580288f22cbd29c1bc.js" type="text/javascript"></script>

<script type="text/javascript">
    function updateCartRealTime(value) {
        var _cartstack_update = [];
        _cartstack_update.push(['setSiteID', 'XXXXXX']);
        _cartstack_update.push(['setDataItem', { 'firstname' : value }]);
        cartstack_updatecart(_cartstack_update);
    }

    $(document).ready(function() {
        $("####").blur(function() {
            updateCartRealTime(this.value);
        });
    });
</script>

This assumes you are using jQuery and the input has an id. Replace #### with whatever the id of the input element is, preceded by a #.  If your input is this

<input type="text" id="first_name" value="" />

the jQuery blur line would look like this  

$("#first_name").blur...<br>
Email Template Usage 

After you have integrated your custom fields, simply include your variables using whatever field name you set. So for the above code example, you would use these:

%%firstName%%, %%coupon%%, %%EmailAddress%%

You can also use placeholder values in case your custom values are not always set. For example, if you wanted to display "Friend" if %%firstName%% was not set, use this format:

%%firstName[Friend]%%
How Do I Test This? 

To test your custom fields integration, abandon a cart on your website (make sure you've added the appropriate variable to your email template, eg: %%firstName%%). Then log into your account and go to the Reports >  Send Queue report. Then click on the view icon (see screenshot below). You will see the actual email that will be sent out, so you can make sure the custom values are displayed.

Did this answer your question? Thanks for the feedback. Click the "Contact Us" button to the right if you need further help. There was a problem submitting your feedback. Please try again later.