Created
July 6, 2011 17:57
-
-
Save araddon/1067886 to your computer and use it in GitHub Desktop.
Selector based MultiTrack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
// this function is called by webtrends.js after it has loaded | |
window.webtrendsAsyncInit = function() { | |
var dcs=new Webtrends.dcs().init({dcsid:"your_dcs_id",timezone:-8}); | |
// look for any link with a anchor in it | |
dcs.addSelector('a[href*="#"]', | |
{ | |
transform:Webtrends.anchorTransform, // There are predefined transforms, or create your own | |
argsa:["DCS.dcsuri","/multitrackevents/offsites"] // any args you want to track | |
} | |
); | |
// look for any link going to /products/ section and get which product | |
dcs.addSelector('a[href*="/products/"]', | |
{ | |
// any args you want to track | |
argsa:["DCS.dcsuri","/multitrackevents/productsclicks"], | |
// custom transformation function | |
transform:function(dcs,o){ | |
// one of the attributes of o is 'element' the html dom element | |
// that triggered the multitrack | |
if (o.element && o.element.href.indexOf("product_id=") >= 0){ | |
var qps = Webtrends.getQryParams(o.element.href); | |
// extract query params from link url: element.href | |
// and if they contain product_id, then ad the product_id to the multitrack request | |
dcs.WT.cg = qps['product_id']; | |
} else { | |
o.prevent = true; // setting o.prevent = true cancels the multi-track | |
} | |
} | |
} | |
); | |
dcs.track(); | |
}; | |
(function() { | |
var s = document.createElement('script'); s.type="text/javascript"; s.async = true; | |
s.src = 'http://s.webtrends.com/js/webtrends.js'; | |
var s2=document.getElementsByTagName("script")[0];s2.parentNode.insertBefore(s,s2); | |
}()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment