Automatic Tracking
  • 06 May 2020
  • 4 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Automatic Tracking

  • Dark
    Light
  • PDF

Article Summary

This article provides information on tracking with the JavaScript tag.

Tracking Transforms

Transforms are functions that take as arguments a reference to the DCS object and the tracking object. They are used to modify the data collected or to change the behavior of the tracking code. In either case, they are called just before the beacon request is generated.

Transforms allow you to modify the Tag and/or Multitrack object just before the beacon request is created. Transforms come in two flavors: inline and global. The global transform applies to all Multitrack calls, where as the inline version only applies to the a single Multitrack call. You can have zero to many global transforms per page, where as inline transforms are zero or one per multitrack call.

Webtrends.addTransform(Function, Event, dcsObject)

Function
The function to execute when the event occurs. This function accepts two arguments (dcsObject and Multitrack object).

Event
A string with one of these 3 values; "all", "multitrack" or "collect". A value of "all" means the transform should be called on all tracking events. A value of "multitrack" means the transform should only be called during a multitrack event. A value of "collect" means the transform should only be called during the first track function call.

dcsObject (optional)
By default, transforms are applied to all instances of the Webtrends.dcs object. You may specify an instance of the Webtrends.dcs object, which will constrain the transform to just that Webtrends.dcs object.

JavaScript Example:

window.webtrendsAsyncInit = function () 
{
        var dcs = new Webtrends.dcs();
        dcs.init( {
                dcsid:    "dcs9x99xxxx9xxx9xx9xxxx9x_9x9x",
                timezone: -7
        });
        
        Webtrends.addTransform( 
                function(dcsObject, multiTrackObject) { 
                        multiTrackObject.argsa.push(
                                "DCSext.custom01", "foo",
                                "DCSext.custom02", "HW"
                        )       
                        console.log("Transform1: std keys added!"); 
                },
                "all", dcs
        );
        
        dcs.track();
};

Selectors

Selectors are a way to unobtrusively attach multiTrack calls to DOM elements. This uses the browser's CSS Selectors engine to find the elements.

CSS Selectors are a powerful way to query the DOM for elements on any number of node attributes. With this support of CSS selectors, you have the option of "tagging" a site without polluting the markup with inline multiTrack calls.

Note

Selectors rely on the JavaScript method querySelectorAll(), which is not fully supported in all versions of Internet Explorer. Because visitors will likely be using older versions of IE, you must use a third party library with the Webtrends JavaScript tag. The tag automatically detects and uses any of the following libraries:

  • JQuery
  • Sizzle
  • Yahoo
  • Qwery
  • YUI

JavaScript example for tracking offsite links:

window.webtrendsAsyncInit = function () {
        var dcs = new Webtrends.dcs();
        dcs.init( {
                dcsid: "dcs9x99xxxx9xxx9xx9xxxx9x_9x9x",
                i18n: false
        })
         //Search for anchor tags without webtrends.com in the href. Assumes no relative links exist on page.
        .addSelector('a:not([href*="webtrends.com"])', {
                transform: function(dcsObject, multiTrackObject) {
                        var e = multiTrackObject.element || {};
                        var hn=e.hostname?(e.hostname.split(":")[0]):"";
                        var pr=e.protocol||"";
                        var qry=e.search?e.search.substring(e.search.indexOf("?")+1,e.search.length):"";
                        var pth=e.pathname?((e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname):"/";
                        multiTrackObject.argsa.push(
                                "DCS.dcssip", hn,
                                "DCS.dcsuri", pth,
                                "DCS.dcsqry", qry,
                                "DCS.dcsref", window.location,
                                "WT.ti", "Offsite:" + hn + pth + (qry.length ? ("?" + qry) : ""),
                                "WT.dl", "24"
                        );
                }
        })
        .track();
}

JavaScript example for tracking downloads:

window.webtrendsAsyncInit = function () {
        var dcs = new Webtrends.dcs();
        dcs.init( {
                dcsid: "dcs9x99xxxx9xxx9xx9xxxx9x_9x9x",
                i18n: false
        })
        //Search for anchor tags with file extentions of interest. Assumes no relative links on page.
        // match .xlsx, .pdf, .doc, docx
          .addSelector('a[href*=".xlsx"],a[href*=".pdf"],a[href*=".doc"],a[href*=".docx"]',
      {  
                transform: function(dcsObject, multiTrackObject) {
                        var e = multiTrackObject.element || {};
                        var hn=e.hostname?( e.hostname.split(":")[0] ):"";
                        var pr=e.protocol||"";
                        var qry=e.search?e.search.substring(e.search.indexOf("?")+1,e.search.length):"";
                        var pth=e.pathname?((e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname):"/";
                        multiTrackObject.argsa.push(
                                "DCS.dcssip", hn,
                                "DCS.dcsuri", pth,
                                "DCS.dcsqry", qry,
                                "DCS.dcsref", window.location,
                                "WT.ti", "Download:" + hn + pth + (qry.length ? ("?" + qry) : ""),
                                "WT.dl", "25"
                        );
                }
        })
        .track();
}

Dual Tagging (Website only)

You may find it useful to send data to two DCSIDs, or to two domains (with the same DCSID or different DCSIDs). In the example, the two domains are a local SmartSource Data Collector sdc.my-domain.com, and the Webtrends server statse.webtrendslive.com.

Sending data to two DCSIDs:

<script type="text/javascript">
         // Async Loader function, called by webtrends.js after load
         window.webtrendsAsyncInit = function() {
                var dcs1=new Webtrends.dcs().init({
                    dcsid:"dcs9x99xxxx9xxx9xx9xxxx9x_9x9x"
                    ,timezone:-5
                    ,fpc:"WT_FPC1"
                });
                  
                var dcs2=new Webtrends.dcs().init({
                    dcsid:"dcs9x99xxxx9xxx9xx9xxxx9x_9x9x"
                    ,timezone:-2
                    ,fpc:"WT_FPC2"
                });
                dcs1.track();
                dcs2.track();
         }; 
                  
         ( function() {
               var s = document.createElement('script'); s.async = true; s.type = "text/javascript";
               s.src = "scripts/webtrends.js";
               var s2 = document.getElementsByTagName("script")[0];
               s2.parentNode.insertBefore(s, s2);
         }());    
         
</script>

Sending data to two domains:

<script type="text/javascript">
         // Async Loader function, called by webtrends.js after load
         window.webtrendsAsyncInit = function() {
               var dcs1=new Webtrends.dcs().init({
                   dcsid:"dcs9x99xxxx9xxx9xx9xxxx9x_9x9x"
                   ,timezone:-5
                   ,domain:"statse.webtrendslive.com"
                   ,fpc:"WT_FPC1"
               });
                  
               var dcs2=new Webtrends.dcs().init({
                   dcsid:"dcs9x99xxxx9xxx9xx9xxxx9x_9x9x"
                   ,timezone:-5
                   ,domain:"sdc.my-domain.com"
                   ,fpc:"WT_FPC2"
               });
               dcs1.track();
               dcs2.track();
         }; 
                  
         ( function() {
               var s = document.createElement('script'); s.async = true; s.type = "text/javascript";
               s.src = "scripts/webtrends.js";
               var s2 = document.getElementsByTagName("script")[0];
               s2.parentNode.insertBefore(s, s2);
         }());
                  
</script>

Visitor Tracking

By default, Webtrends tracks visitors across the primary domain and all sub-domains. This is done by setting a first party cookie on your primary domain with the leading dot, which allows sub-domains to also read this cookie.

The values stored in Webtrends' first party cookie are used for maintaining session and user identification across all your sub-domains. If you need to track your sub-domains independently, then you can use the fpcdom config settings. The default name for Webtrends' first party cookie is WT_FPC, but you can change the name by using the fpc configuration setting.

For cross domain tracking, Webtrends uses a third party cookie set to the domain of your collection server to track users across your domains. For example, if you wanted to track users between myDomain.com and myDomain.net, you couldn't do it using only a first party cookie.

In the lite version of the JavaScript the third party tracking is disabled, since it added two addition requests for first time visitors: one for wtid.js to generate a Webtrends ID, and one during the collection request to actually set the third party cookie. This feature can be turned on or off with the disablecookie configuration setting.


Was this article helpful?