Piwik.js loading but no tracker request being made


(timwood) #1

On a new site we launched last week we are using the Piwik code on pages served from Drupal CMS (via Drupal Piwik module) as well as static html pages served directly from Apache. The static pages have similar piwik code to the Drupal pages, however only pages from Drupal are being tracked. When the static pages are accessed the piwik.js is loaded in the browser, but the tracker request (http://mypiwik.org/piwik.php) is not made. I’ve added JS alerts inside the tag for the tracker request section to ensure that that code is being run by the browser and the alerts do pop up. Below is our code from the static page, and help would be appreciated!

<script type="text/javascript">
      if (document.location.protocol == "http:") {
      var pkBaseURL = (("http:" == document.location.protocol) ? "http://mypiwik.org/" : "http://mypiwik.org/");
      document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
      }
    </script>
<script type="text/javascript">
      if (document.location.protocol == "http:") {
      try {
      var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 7);
      } catch( err ) {}
      }
</script>

Thanks,
-Tim


(vipsoft) #2

Don’t forget to call trackPageView()!

If your Piwik installation is only accessible via http, then you can simplify your tracking code:

<script type="text/javascript" src="http://mypiwik.org/piwik.js"></script>
<script type="text/javascript">
try {
  var pkBaseURL = "http://mypiwik.org/";
  var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 7);
  piwikTracker.trackPageView();
} catch( err ) {
}
</script>

(timwood) #3

CRAP! Thanks for point out my mistake! Not sure how I lost that part of the code when I was customizing it.

Thanks again!

[quote=vipsoft @ Jun 29 2009, 11:41 AM]Don’t forget to call trackPageView()!

If your Piwik installation is only accessible via http, then you can simplify your tracking code:

<script type="text/javascript" src="http://mypiwik.org/piwik.js"></script>
<script type="text/javascript">
try {
  var pkBaseURL = "http://mypiwik.org/";
  var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 7);
  piwikTracker.trackPageView();
} catch( err ) {
}
</script>

[/quote]