Installation of Web behavior tracking


Web Behavior Tracking has a few variations of code that you can install on your site depending on the requirements you have, or your technical ability.

Most users install our basic implementation as this is the least time consuming and simplest to get going. If you're ever in doubt or don't fully understand the other options available then it's best to use the basic implementation.


The implementation code given below must be wrapped within <script></script> tags, otherwise the code won't work.

Creating your Web Behavior Tracking profile

With Web Behavior Tracking, you'll be able to create your unique tracking profiles which can then be added to any website page where you'd like to gather browsing insights by sessions. A session is any activity that occurs on a domain between the time a user arrives and the session expires.

In Engagement Cloud, if the Web Behavior Tracking script is set up to track a top-level domains and sub-level domains, it tracks as one continuous session.

Follow these steps to create a profile:

1. Click on the Settings icon in the bottom left-hand corner of the screen to produce the settings menu and select Access


2. Click on the Web behavior profiles tab and then click New profile or Create on now.


3. Enter a name for your profile, for example 'Main website', as well as up to 15 unique website domains where this code might be placed. These website domains don't need to include 'http(s)://www.' 

Subdomains belonging to a specified parent domain are automatically tracked and don't need to be specified. However, specific subdomains, such as, can be listed without their parent domain. 

Only website domains that are listed under this profile will be able to send data through to your account.

Click Create once you've finished.


4. You'll now be able to see your unique ID, which relates only to this Web Behavior Tracking profile. In order to start using it to send browsing session data to your account, you'll need to copy and paste everything from the 'Tracking code' field and insert it into the head of any website page on any of the website domains specified in this profile.

Ajax/Single page
If you have a single page website, or load content via Ajax, you can change the tracking code using this option. If you're not sure which method you need, please check with your website administrator.

Track abandoned carts (applicable for our non-Magento users)
If you have a store and want to track the contents and value of abandoned carts that don't reach your checkout, you can change the tracking code using this option. After clicking 'Yes', you'll then need to click on the 'Follow these steps to complete this script's setup' link, which will take you through to our support article about setting up our abandoned carts module.

Enable guest carts (applicable for our non-Magento users)
If any visitors to your site abandon their carts and those visitors' email address aren't contacts in Engagement Cloud, you can automatically create a new contact for each visitor using this option. Selecting 'Yes' will ensure all unknown visitors to your site who abandon a cart will become Engagement Cloud contacts, and they can then be sent abandoned cart emails.

Please note when enabling abandoned carts for guests:

  • It's your responsibility to ensure you're clearly displaying the correct consent text on your site
  • We strongly recommend leaving your 'Regulatory settings' on 'Enforce double opt-in for signups from signup forms and some API methods only (default)'. If you have to enforce double opt-in for all signups, then we don't recommend using abandoned cart emails for guests as the process won't work correctly. 

Click Save once you've finished.


Basic implementation

The following code is the most basic and popular implementation of our Web Behavior Tracking code. The implementation is as simple as placing the following code on every page of your website that you wish Web Behavior Tracking to track a user's behavior on. This process is identical to other similar tracking tools, e.g. Google Analytics.

This code can either be manually added to your site, or it is also compatible with various tag management tools such as Google Tag Manager. 

                })(window, document, '//', 'script', 'dmPt');

window.dmPt('create', 'DM-SAMPLE-01');

Manual page tracking implementation

This is the same as basic implementation, except you can call this function to manually notify web behavior tracking that the page has been viewed:


Custom values implementation

As default, Web Behavior Tracking sends Engagement Cloud the following values:

  • Session start time
  • IP address
  • Agent
  • Website
  • Number of pages viewed
  • Duration
  • Page title
  • Page URL
  • Date and time of visit

If you require more data than this to truly make your segmentation or automation more effective using Web Behavior Tracking, we provide the ability to submit custom page values with each page request. Using the below code as an example, you can provide Web Behavior Tracking with a series of key/value pairs along with the default 'track' request. 

                })(window, document, '//', 'script', 'dmPt');

window.dmPt('create', 'DM-SAMPLE-01');

// Tracks with custom key values (object with name/value pairs, only primitive types!)
window.dmPt('track', { customVar: 'Hello', anotherKey: 'World' });

User identification implementation

Web Behavior Tracking's most common method of identifying a user is when a recipient clicks from one of your Engagement Cloud campaigns and goes through to you website. However, you may have ways that a user tells you their email address whilst visiting your site, e.g. a customer login form, checkout or newsletter subscribe box. Using the 'identify' method, you can submit the user's email address as they provide it to you.

                })(window, document, '//', 'script', 'dmPt');

window.dmPt('create', 'DM-SAMPLE-01');
// Associates email address with the user device (hardcoded example, needs to be replaced with actual email)
window.dmPt('identify', '');

Please note

You must replace the example email address in the above code -'' - with the actual user's email address dynamically, as they provide it to you.

Tracking subdomain implementation

To add a domain to window.dmPt('create', 'DM-SAMPLE-01');, note that all specified domains should be subdomains, like in the examples above. For example, you can't track across, and

We add a cookie, based on the subdomains in the list that match the website URL. A domain always matches a subdomain URL. Ensure the domain name is at the top of the list.

Sub domain tracking implementation (new section, needs copy):

                })(window, document, '//', 'script', 'dmPt');

// Enables tracking for domains and
window.dmPt('create', 'DM-SAMPLE-01', ',');
Did you find this article helpful?

Can we help?

Thanks for using Engagement Cloud. If you need more help or support, then contact our support team.