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
This code needs to 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 - will be 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 will mean all calls to window.dmPt below will also need to be changed to window.myNewVar throughout.
Identifying 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 need to already have a process in place in which customers are created as contacts when they log in, or sign up to, your site.
Supplying your cart
The code below needs to 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
This is the ID of the Dotdigital program that will send out the email. We can supply this to you when we set up the email and program for you.cartDelay
This is the time, in minutes, we wait before sending out the emailcartID
The ID of your shopping cart. This should be unique.cartPhase
The state in which the cart is in. It must be set to ORDER_COMPLETE once the order has been completed. This will prevent an abandoned cart email being sent.currency
The currency that the prices are in (e.g. USD or GBP)subtotal
The cart subtotal amountshipping
The amount for shipping the orderdiscountAmount
The amount discounted on the entire orderThis should be a positive value.
taxAmount
The amount of tax included on the entire ordergrandTotal
The final total of the order, including tax, discounts, etc., if knowncartUrl
The modifiedDate URL that will take the user directly back to their cart on your storemodifiedDate
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 itemname
The item name or basic descriptiondescription
A more detailed description of the itemcategory
The category the product falls under, e.g. T-Shirts > Blueother
This can be anything you like, or left blank if not requiredunitPrice
The full unit price of the itemsalePrice
The price the item is sold for on your storequantity
The number of itemstotalPrice
The total price of items (taking sale price and quantity into account)imageUrl
The full URL to an image of this productproductUrl
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 will not 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'll have to do a little more work to get all this functioning.
As above, you will need to include the tracking script on the page before any calls to our servers are made. And, as above, you will need to 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 will 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.