We use Webtrends at work to track usage of our websites.
Here’s the offending bit of code…
// Code section for Set the First-Party Cookie domain
This works for anything served from a Kerrang.com domain. However, what if we want to use a different domain for some reason?
document object called
domain, we can use this at runtime to find out the full domain name the page was served from.
However, we don’t need the full domain name, just parent domain. For example, www.kerrang.com should become kerrang.com.
We can fix this by using several approaches, but the easiest is the split, splice, join method.
Firstly we split the domain into it’s components by splitting on the periods.
This gives us the array (“www”,”kerrang”,”com”).
Secondly we splice this to remove the first element.
This is saying to take 3 elements after the 1st element in the array. This should cover us if we want to use something like kerrang.co.uk. So after running this we need to should have an array looking like this, (“kerrang”,”com”).
Finally we join this back together again, making sure a period is between each joined element.
Running this should give us kerrang.com, which is acceptable to use in the Webtrends tag.
So our final code looks like this…
var gFpcDom = document.domain.split('.').splice(1,3).join('.');