Skip to main content
All CollectionsIntegrationsShopify and Shopify PlusSetup
Additional scripts for Shopify features
Additional scripts for Shopify features

Learn what changes we apply to your Shopify store, and what scripts you need to implement features manually.

Gareth Burroughes avatar
Written by Gareth Burroughes
Updated this week

As part of the installation process for Shopify, a number of scripts which power different Dotdigital features are applied automatically for you. The scripts themselves are referenced externally; we add a small amount of JavaScript to your store theme for this purpose through the Script Tag API.

If you chose not to have the code installed automatically, or your installation pre-dates this option, you can also apply the necessary scripts to your store manually.


Site and ROI tracking

We apply {tracking app url}/_dmspt.js?shop={your store domain} to your store theme.

To install manually, the site tracking script must be applied before the the closing </body> tag of all the pages on your website.

<script src="https://r1-t.trackedlink.net/_dmpt.js" type="text/javascript"></script>

The ROI tracking script must be inserted on the post purchase page of your site.

<script src="https://r1-t.trackedlink.net/_dmpt.js" type="text/javascript"></script>
<script> _dmTrack("CheckOutAmount", %%ORDER_AMOUNT%%); </script>

Abandoned carts

The following scripts are needed to power the abandoned carts module:

We apply {tracking app url}/shopify/wbt.js?shop={your store domain} to your store theme.

Web behavior tracking

To install manually, the Web behavior tracking script must be inserted before the </head> tag of each site page.

<script>

// Initiate Web Behaviour Tracking (this section MUST come prior to
any other dmPt calls)
(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');

// Replace DM-000000000-00 with your web behaviour profile's Unique ID
// Replace test.com with the domain of your store
window.dmPt('create', 'DM-000000000-00', 'test.com');
// Setup the last browsed product
var viewed_product = {
product_name: "Name of Product",
product_url: "https://test.com/productname",
product_image_path: "https://test.com/images/product.png",
product_description: "The description of the product",
product_sku: "ABC123",
product_price: "99.99",
product_status: "In stock",
product_currency: "GBP",
product_specialPrice: "89.99",
product_categories: "Category1, Category 2, Category 3",
product_brand: "Brandname"
};

// Initiate the tracking script, pass the product object
window.dmPt('track', viewed_product);

// Replace test@test.com with the email address of the identified
contact
window.dmPt("identify", "test@test.com");
</script>


CartInsight

To install manually, this script must be placed before the </body> tag of each page of your site.

// <<< Dotdigital Abandoned cart script >>>
var dmPt = dmPt ? dmPt : {};
// Change this value to true if you want to enable guest abandoned
cart
dmPt.enableGuestAbandonedCart = false;
// Id or selector expression to return the newsletter sign up forms of
your store
dmPt.newsletter_form_id="#ContactFooter";
!function(u){function e(t){var e,n,r,i=(e=t.target,n="input[type=email]",
(r=e.querySelector(n))&&r.value?r.value:null);i&&a(i)}function a(t)
{n("dm-subscriber",t,365)}function n(t,e,n){var r;e&&((r=new
Date).setTime(r.getTime()+24*n*60*60*1e3),u.cookie=t+"="+e+";
expires="+r.toGMTString()+"; path=/")}
function t(t){for(var e=t+"=",n=u.cookie.split(";"),r=0;r<n.length;r++){for(var i=n[r];""==i.charAt(0);)i=i.substring(1,i.length);if
(0==i.indexOf(e))return i.substring(e.length,i.length)}return null}
dmPt&&(dmPt.enableGuestAbandonedCart&&u.querySelectorAll
(dmPt.newsletter_form_id).forEach(function(t)
{t.addEventListener("submit",e,!1)}),dmPt.emailSubmitted=t("dm-
subscriber"),a(dmPt.emailSubmitted),dmPt.cartId=t("cart"),n("dm-
cart",dmPt.cartId,15))}(document);
{% if customer.email and customer.accepts_marketing %}
dmPt("identify", "##{{ customer.email }}");
{% else %}
if(dmPt.enableGuestAbandonedCart && dmPt.emailSubmitted && dmPt.emailSubmitted !== "")
{dmPt("identify", dmPt.emailSubmitted);
}
{% endif %}
if(dmPt.cartId && dmPt.cartId !== ""){
dmPt("cartInsight",
{"programID": %programID%,
"cartDelay": %cartDelay%,
"cartID": dmPt.cartId,
//This value is retrieved from a Shopify cookie
"cartPhase": "CUSTOMER_LOGIN",
"currency": "##{{ shop.currency }}",
"subtotal": ##{{ cart.total_price }}/100,
"discountAmount": ##{{ cart.original_total_price | minus: cart.total_price
}}/100,
"taxAmount": 0,
"grandTotal": ##{{ cart.total_price }}/100,
"cartUrl": "##{{ shop.url }}/cart/{% for item in cart.items %}##
{{item.variant_id}}:##{{ item.quantity }}{% if forloop.last == false %}
,{% endif %}{% endfor %}",
"lineItems": [
{% for item in cart.items %}
{
"sku": "##{{ item.sku }}",
"name": "##{{ item.title }}",
"description": "##{{ item.product.description | strip_html | escape |
strip_newlines }}",
"category": "{% for collection in item.product.collections %}##{{
collection.title }} {% endfor %}",
"other": "{% for tag in product.tags %}##{{ tag }} {% endfor %}",
"unitPrice": ##{{ item.original_price }}/100,
"salePrice": ##{{ item.price }}/100,
"quantity": ##{{ item.quantity }},
"totalPrice": ##{{ item.line_price }}/100,
"imageUrl": "##{{ item.image | img_url: 'small' | prepend:'https:'}}",
"productUrl": "##{{ shop.url }}##{{ item.url}}",
} {% if forloop.last == false %},{% endif %}
{% endfor %}
]
});
}


Order success

To install manually, this script must be implemented on the Order Processing page of your site.

var dm_insight_id ='uniqueID';

(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');

// <<< Dotdigital Abandoned cart script >>>
var dmPt = dmPt ? dmPt : {};
// Change this value to true if you want to enable guest abandoned cart
dmPt.enableGuestAbandonedCart = false;

!function(i){function t(t){for(var n=t+"=",r=i.cookie.split
(";"),e=0;e<r.length;e++){for(var d=r[e];" "==d.charAt
(0);)d=d.substring(1);if(0==d.indexOf(n))return d.substring
(n.length,d.length)}return""}dmPt.enableGuestAbandonedCart&&
(dmPt.emailSubmitted=t("dm-subscriber")),dmPt.cartId=t("dm-cart")}
(document);

{% if customer.email and customer.accepts_marketing %}
dmPt("identify", "##{{ customer.email }}");
{% else %}
if(dmPt.enableGuestAbandonedCart && dmPt.emailSubmitted &&
dmPt.emailSubmitted !== ""){dmPt("identify", dmPt.emailSubmitted);}
{% endif %}
if(dmPt.cartId && dmPt.cartId !== ""){
dmPt("cartInsight", {
"programID": %programID%,
"cartDelay": %cartDelay%,
"cartID": dmPt.cartId,
"cartPhase": "ORDER_COMPLETE",
"grandTotal": ##{{ total_price | money_without_currency }},
"currency": "##{{ shop.currency }}",
"subtotal": ##{{ total_price | money_without_currency }},
"discountAmount": 0,
"taxAmount": 0,
"cartUrl": "##{{ shop.url }}",
"lineItems": []
});
}


Chat

We apply {tracking app url}/shopify/chat.js?shop={your store domain} to your store theme.

If you choose to install manually, you must apply the chat script to each page of your site.

<script>
window._ddgChatConfig = {
apiSpace: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
urlBase: 'https://webchat.dotdigital.com'

};
(function(d, s, id){
var js, cjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = 'https://webchat.dotdigital.com/widget/bootstrap.js';
cjs.parentNode.insertBefore(js, cjs);
}(document, 'script', 'ddg-chat-widget'));
</script>


Identifying users

We apply a small section of code to your store’s theme.liquid for the purpose of identifying logged in users.

{% if content_for_header contains "@@WBTSCRIPTURL@@" and customer.email %}
{% assign track_non_subscribed = @@TRACKNONSUBSCRIBEDCUSTOMERS@@ %}
{% if customer.accepts_marketing or track_non_subscribed %}
<script>
window.dmPtId = function() {
window.dmPt('identify', '##{{ customer.email }}');
}
</script>
{% endif %}
{% endif %}
Did this answer your question?