How to Target Visitors Based on How Many Items are in Their Cart

With Digioh’s custom JavaScript, you can target visitors based on the contents of their cart. This allows eCommerce brands to prevent cart abandonment by offering incentives to shoppers who are about to abandon your site.

The setup will vary from site to site, so email us, and we can write the custom JS for you.

Writing this JavaScript requires looking in your HTML/CSS to see what class is associated with the number of cart items. Below is the custom JS where the class is “shopping-cart” and the number of items is displayed in a badge. This custom JS will live in the “After Document Ready” section of your Custom JS.

//Badge Targeting
var badgeVal = '';
if (JQUERY_DIGIOH('#shopping-cart').length) {
    badgeVal = JQUERY_DIGIOH('#shopping-cart').find('span.badge').eq(0).html();
}

if (!badgeVal || badgeVal === '' || badgeVal === '0') {
    //They have zero items in their cart
    JQUERY_DIGIOH('body').append('<div id="digioh-cart-zero"></div>'); DIGIOH_CUSTOM_JS.log('digioh-cart-zero'); } else { 
//They have one or more items in their cart 
JQUERY_DIGIOH('body').append('<div id="digioh-cart-one-or-more"></div>'); DIGIOH_CUSTOM_JS.log('digioh-cart-one-or-more'); }

You now have 2 new rules available to you:

#digioh-cart-zero (Target people with nothing in their cart)

— or —

#digioh-cart-one-or-more (Target people with 1 or more item in their cart)

You would use the HTML Exists JQuery rule for this.