Asynchronous across multiple subdomains?

Hi!

I’m using the async tracker with Piwik 1.2. Now I want to track accross multiple subdomains. Is this code correct?


var _paq = _paq || [];
(function(){
  var u=(("https:" == document.location.protocol) ? "https://piwik.example.com/" : "http://piwik.example.com/" );
  _paq.push(['setSiteId', 2]); // Your ID here.
  _paq.push(['setTrackerUrl', u+'piwik.php']);
  _paq.push(['setCookieDomain', '*.example.com']);
  _paq.push(['trackPageView']);
  var d=document,
        g=d.createElement('script'),
        s=d.getElementsByTagName('script')[0];
        g.type='text/javascript';
        g.defer=true;
        g.async=true;
        g.src=u+'piwik.js';
        s.parentNode.insertBefore(g,s);
})();

Edit: I’ve tried it for myself and the updated version above works as expected.

Regards from Hamburg,

Johannes

Hi Johannes,

I would have a need for tracking subdomains too but I am not sure how to do this. Right now I am tracking a normal website with the code supplied.
Is the code above the full code which would go into the sites surrounded by the script tags ?

Where could I read up on this ? The Docu is somewaht not so clear, at least to me.
Could you help me out ?

Dein Namensvetter, aber aus Canada.
Johannes

Hi!

Yes, its the complete content of the script tag, which should be placed in the head of the page. Dont forget to adjust the site id as well as all example.coms.

Regards, Johannes

Hi Johannes,

thank you for the info & help. Changing the address and id was clear.
Where could I read-up on this ? Is there anywhere some documentation ?

Johannes

The JavaScript API is mostly documented here. http://piwik.org/docs/javascript-tracking

(Overall documentation is an ongoing project. Feel free to suggest improvements.)

Thank you vipsoft.

Now it starts to get interesting.(tu)