Tracking main domain and sub domain

Hi I have read the documentation tracking multiple subdomain but it seems not working on my site it does not do anything although I see apache access logs piwik is tracking but on piwik dashboard nothing is recorded.

I have main domain and 3 subdomain

www.example.com
imgs.example.com
events.example.com
profile.example.com

I have to track all of above domain in one piwik tracking script. I didn’t create any sub domain tracking script only on www.example.com

Below is script I have tried not working.


<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
  var piwikTracker = Piwik.getTracker(pkBaseURL, 1);
tracker.setCookieDomain('*.example.com'); // Same cookie as: example.com, www.example.com, subdomain.example.com, ...
tracker.setDomains('*.example.com'); // Download & Click tracking alias domains
  piwikTracker.trackPageView();
  piwikTracker.enableLinkTracking();
} catch( err ) {}
</script>
<!-- End Piwik Code -->


Below script is currently running only for www.example.com.


<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
  var piwikTracker = Piwik.getTracker(pkBaseURL, + "piwik.php",1)
  piwikTracker.trackPageView();
  piwikTracker.enableLinkTracking();
} catch( err ) {}
</script>
<!-- End Piwik Code -->

Please help do I need to create seperately tracking for each sub domain?

bump… anyone please?

bump… anyone please?

bump… anyone please?

Your broken script is missing the request to piwik.php, and the references to tracker is undefined.

Thank you for the reply, Happy New year!

How ever I’m still lost don’t know which line.

you mean this line?

var piwikTracker = Piwik.getTracker(pkBaseURL, 1);

Should be like this?
var piwikTracker = Piwik.getTracker(pkBaseURL, + “piwik.php”,1)

Or do I need to remove the id site?

Hi anyone pls. can guide to correct above script.

These 3 lines are wrong:


var piwikTracker = Piwik.getTracker(pkBaseURL, 1);
tracker.setCookieDomain('*.example.com'); // Same cookie as: example.com, www.example.com, subdomain.example.com, ...
tracker.setDomains('*.example.com'); // Download & Click tracking alias domains

Try changing it to:


var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.setCookieDomain('*.example.com'); // Same cookie as: example.com, www.example.com, subdomain.example.com, ...
piwikTracker.setDomains('*.example.com'); // Download & Click tracking alias domains

Thanks I will try it now… :slight_smile: