JSON breakdown

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 (in green) will be given to you prior to setup.  The rest of this script block should remain exactly as it is below.

var dm_insight_id ='DM-123SAMPLE123-01';

(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);};w[o]('track');
        })(window, document, '//static.trackedweb.net/js/_dmptv4.js', 'script', 'dmPt');

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", "test@user.com");

Important

The above script doesn't create a contact in your account. You'll need to already have a process in place in which customers are created as contacts when they log into, 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,
   "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": "This can be any string 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": "This can be any string 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 dotmailer 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 email
  • cartId
    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 amount
  • discountAmount
    The amount discounted on the entire order
  • taxAmount
    The amount of tax included on the entire order
  • grandTotal
    The final total of the order, including tax, discounts, etc., if known
  • cartUrl
    The URL that will take the user directly back to their cart on your store

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,  e.g. 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 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.

 

Have more questions? Submit a request

Comments

Powered by Zendesk