Piwik tracking code through a javascript


Hi there

I am new Piwik user. I had a good experience with the setup and tracking the pages using the generated tracking code.

What I am trying to do is, have the tracking code in a seperate JS file and include that in the html page (SomeHtml.html) that I want to track. I have a js file called track.js which contains the tracking code (something like below)
var _paq = _paq || [];
(function() {
var u=((“https:” == document.location.protocol) ? “https” : “http”) + “://myserver.com/piwik/”;
_paq.push([‘setTrackerUrl’, u+‘piwik.php’]);
_paq.push([‘setSiteId’, 1]);
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);

I have include the track.js in the SomeHtml.html file which I want to track.
When I load the SomeHtml.html page, I notice that the piwik.js call goes through where as the piwik.php call is not made. So the actual tracking does not happen.

I am not sure what I might be doing incorrect here. Any pointers to resolve this is really appreciated.



Found the issue to be with the scope of the variable _paq. This issue is now resolved.