Hi
I’ve tried to search & create my own asynchronous tracking tag to include multiple trackers (we want to track sub-domains separately to our main domain).
Could anyone give an example of how to set up multiple trackers asynchronously?
I have tried to replicate the GA way like this:
<script type="text/javascript">
//Load Piwik.js file
var pkBaseURL = (("https:" == document.location.protocol) ? "https://10.0.0.169/piwik/piwik/" : "http://10.0.0.169/piwik/piwik/" );
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E") );
</script>
<script type="text/javascript">
try {
var thisUrl;
thisUrl = document.URL;
thisUrl = thisUrl.toLowerCase();
var _paq = _paq || [];
(function(u, d, t) {
//intranet - first tracker
if (thisUrl.indexOf("intranet.mycompany.com" ) > 0) {
_paq.push(['i.setSiteId', 1], ['i.setTrackerUrl', pkBaseURL + 'piwik.php'], ['i.trackPageView']);
}
//Intelligence - New Tracker
if (thisUrl.indexOf("intelligence.intranet.mycompany.com" ) > 0 ) {
_paq.push(['iz.setSiteId', 5], ['iz.setTrackerUrl', pkBaseURL + 'piwik.php'], ['iz.trackPageView']);
}
// + a few others...
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.async = true;
g.src = pkBaseURL + 'piwik.js';
s.parentNode.insertBefore(g, s);
})('//10.0.0.169/piwik/', document, 'script');
} catch (err) { }
</script>
- As you can guess, I’m trying to evaluate the document URL and get new trackers as necessary. Will this work? the syntax appears to be wrong somewhere as it isn’t working quite right.
Many thanks in adviance.