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:

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