Tracking main domain and sub domain


#1

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?


#2

bump… anyone please?


#3

bump… anyone please?


#4

bump… anyone please?


(vipsoft) #5

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


#6

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?


#7

Hi anyone pls. can guide to correct above script.


(vipsoft) #8

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


#9

Thanks I will try it now… :slight_smile: