Installation of Web behavior tracking

Overview

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.

Important

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

Creating your Web Behavior Tracking profile

Once you've purchased Web Behavior Tracking as an add-on to your account, 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

WBT_settings_select_access.png

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

WBT_new_profile.png

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 shop.domain.com, 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.

WBT_profile_name_and_domains.png

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.

WBT_profile.png

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 behaviour 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. 

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


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:

window.dmPt('track');

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. 

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

// 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.

(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');
// Associates email address with the user device (hardcoded example, needs to be replaced with actual email)
window.dmPt('identify', 'example@example.com');
window.dmPt('track');

Please note

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

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.