Skip to main content
All CollectionsCommerceAbandoned carts
Abandoned cart JSON breakdown
Abandoned cart JSON breakdown
Gareth Burroughes avatar
Written by Gareth Burroughes
Updated over a week ago

Dotdigital for Adobe Commerce (Magento) or Shopify connector user?

If so, abandoned cart functionality is configured and implemented differently - and the information below does not apply. Please instead read the Dotdigital for Adobe Commerce or Shopify connector articles.


Tracking script

You can add the script using our Dotdigital tag, or if you'd prefer manually to your site.

Using the Dotdigital Tag

You can install the tracking script by adding the Dotdigital tag to your site and enabling Web behavior tracking. Learn more in Add the Dotdigital Tag to your website.

Manually

This code must be included on every page and must be included before any calls are made to window.dmPt.

Your site identification number, shown below as DM-SAMPLE-01, is given to you prior to setup. The rest of this script block should remain exactly as it is below.

(function(w,d,u,t,o,c){w['dmtrackingobjectname']=o;c=d.createElement(t);c.async=1;c.src=u;t=d.getElementsByTagName 
                (t)[0];t.parentNode.insertBefore(c,t);w[o]=w[o]||function(){(w[o].q=w[o].q||[]).push(arguments);};
                })(window, document, '//static.trackedweb.net/js/_dmptv4.js', 'script','dmPt');window.dmPt('create', 'DM-SAMPLE-01'); window.dmPt('track');

Advanced use

If dmPt clashes with another variable on your page, you can change this above (before the identification code). Changing this means all calls to window.dmPt below also need to be changed to window.myNewVar throughout.

Identify your user

When you're able to identify your user, for example, after they've signed in, you must tell us who the user is. Without this, we may not be able to send them an abandoned cart email.

window.dmPt('identify', 'example@example.com');

Important

The above script doesn't create a contact in your account. You must already have a process in place in which customers are created as contacts when they log in or sign up to your site.


Supply your cart

The code below must be executed on every single page after the cart has been created. Failure to do so may result in them getting an abandoned cart email too early.

A breakdown of what every field means can be found below.

window.dmPt("cartInsight", {
   "programID": 12345,
   "cartDelay": 25,
   "cartID": "123ABC",
   "cartPhase": "CUSTOMER_LOGIN",
   "currency": "USD",
   "subtotal": 35.98,   "shipping": 0,
   "discountAmount": 0,
   "taxAmount": 0,
   "grandTotal": 35.98,
   "cartUrl": "https://www.my-website.com/checkout/cart",
   "lineItems": [
      {
        "sku": "576879",
        "name": "Shirt",
        "description": "A super great description of the product",
        "category": "Shirts > T-Shirts > Blue",
        "other": {"fieldName": "This can be a string or any value you like"},
        "unitPrice": 11.99,
        "salePrice": 11.99,
        "quantity": 2,
        "totalPrice": 23.98,
        "imageUrl": "http://www.my-website.com/a/p/shirt.jpeg",
        "productUrl": "http://www.my-website.com/index.php/shirt.html"
      },
      {
        "sku": "1112296",
        "name": "Fleece Jacket",
        "description": "A well appointed Fleece jacket",
        "category": "Shirts > T-Shirts > Blue",
        "other": {"fieldName": "This can be a string or any value you like"},
        "unitPrice": 65.99,
        "salePrice": 55.50,
        "quantity": 1,
        "totalPrice": 55.50,
        "imageUrl": "http://www.my-website.com/a/p/fleece.jpeg",
        "productUrl": "http://www.my-website.com/index.php/fleece.html"
      }
   ]
});

Cart JSON field breakdown

Cart detail fields

  • programID
    The ID of the Dotdigital program that sends out the email. We can supply this to you when we set up the email and program for you.

  • cartDelay
    The time, in minutes, we wait before sending out the email.

  • cartID
    The ID of your shopping cart. This must be unique.

  • cartPhase
    The state of the cart. It must be set to ORDER_COMPLETE once the order has been completed. This prevents an abandoned cart email being sent.

  • currency
    The currency that the prices are in, for example, USD or GBP.

  • subtotal
    The cart subtotal amount.

  • shipping
    The amount for shipping the order.

  • discountAmount
    The amount discounted on the entire order.

    This must be a positive value.

  • taxAmount
    The amount of tax included on the entire order.

  • grandTotal
    The final total of the order, including any taxes or discounts, if known.

  • cartUrl
    The cart URL that takes the user directly back to their cart on your store.

  • modifiedDate
    The date when the cart was last modified.

Line items fields

As per the example above, there can be one or more line items. All items in the basket should be included.

  • sku
    The identifier for the line item.

  • name
    The item name or basic description.

  • description
    A more detailed description of the item.

  • category
    The category the product falls under, for example, T-Shirts > Blue.

  • other
    This can be anything you like, or left blank if not required.

  • unitPrice
    The full unit price of the item.

  • salePrice
    The price the item is sold for on your store.

  • quantity
    The number of items.

  • totalPrice
    The total price of items, taking sale price and quantity into account.

  • imageUrl
    The full URL to an image of this product.

  • productUrl
    The URL of the product on your website.

Including these on your site

The above tracking and cart tracking scripts should appear on every page of your site, where possible.

You should also include the identify script as soon as you know who the current user is. You don't then have to include this on every page, but it doesn't affect anything if you do.


Working with single-page apps

If your site is a single-page app, or, at least, parts of it are, then you have to do a little more work to get all this functioning.

As above, you must include the tracking script on the page before any calls to our servers are made. And, as above, you must identify the user at the first possible opportunity.

The main cart tracking code, however, should be called as often as is sensible. This could be, for example, every time the user clicks something on the site, or it may just be whenever the cart is updated.

The important thing to note is that when this code is executed, our clocks start ticking. So if you have the abandoned cart email being sent after 20 minutes, then we send the email if we have not heard from the site after 20 minutes.

The point is, if your site does not send through this data often enough, it could mean that we send out the email prematurely.

Did this answer your question?