Can't place site script in external .js file

This question isn’t in the FAQ, so I’d like to answer the forum for help.

I tried to place the site script into an external file, and striped out all tags, with the page to be monitored referring to this file.

It never work.

It seems that I must place the site script content into the page being monitored.

Is this true? Why?

I realize this may be a little late, but I was searching through forrums trying to do the same thing recently, and was getting nowhere. There seems to be a lot of people out there that want to do this, but not a lot of solutions. I finally came up with my own solution. So for anyone who needs it this is what I did.

take your tracking code simaler to the following

create two javascript files. I called mine piwik.js, and piwik_load.js

in piwik.js I put

var pkBaseURL = ((“https:” == document.location.protocol) ? “https://mySite/” : “http://mySite/”);
document.write(unescape("%3Cscript src=’" + pkBaseURL + “piwik.js’ type=‘text/javascript’%3E%3C/script%3E”));

in piwik_load.js I put
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + “piwik.php”, 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}

I then put the following lines in each of my web pages I want to track

Everything is tracking great. I added a few custom variables to piwik_load.js works like a charm.

So bassicly since there are two script blocks in the javascript code you turn each script block into its own javascript file embed the two files in your page with the noscript line at the end of the file, and then if you want to create custom variables create them in the second javascript file

Note ignore the smilely faces.
Hope this helps

Mike

Thank you so much

Thanks alot!