Link trackig in external javscript only works in chrome

Hello all,

we have a problem with external link tracking. Everything works fine, when I use the generated JS code, provided by the piwik backend. Cause we want to use external JS only, I wrote a little piece of code:

$j(window).load(function () {
var pkBaseURL = ((“https:” == document.location.protocol) ? “” : “”);
$j.getScript(pkBaseURL+‘piwik.js’, function(){
// script is now loaded and executed
var piwik = Piwik.getTracker(pkBaseURL+“piwik.php”, “1”);

This code works fine, but external link tracking is only working in chrome, but not on other browsers.

Did I miss something to get I going? Any idea is welcome…



Are you getting a JavaScript error in Firefox?
Have you check your Network console to see if the script is actually being loaded?

No errors, tracking pageviews etc. works fine, only external links are not tracked. I assume it is dependent on how javascript is treated, when the page is left. The behaviour is the same, when usign target="_blank" or not.

Okay… another thing that may be affecting is if you have “do not track” enabled in Firefox but not in Chrome… If that’s not the case, maybe you have plugins in Firefox that are messing up your code?

Also, have you checked this?

If you have, then could you share the code in your piwik.js file? maybe there’s something else there that Firefox and other browsers, but Chrome, don’t like…

It’s pretty late for me, so it may take a while for me to reply. I’ll do it in the morning as soon as I have a chance.

Also, out of curiosity… is there a reason why you’re loading your script using jQuery? Have you consider doing it like this?

<script src="//></script>

Just my two cents.

Thanks for your tips. I have checked out the faq, but the tips didn`t help. Also I have checked for ‘Do not track’ and Plugins, but thats also not the case.

The code in my posting above is all there is. No more magic, just the default piwik.js from the Piwik Installation. The problem is somehow old and was present also in older versions, but the current piwik version used is 2.16.0.

Regarding your question with JQuery: The piwik.js is also loaded in via normal sript tag before. But the loading via jQuery seems to be needed to get the traking running. No Idea why, as I am not a JS crack :frowning:

You’re right the piwik.js file is loaded in the tracking script… it was pretty late last night and wasn’t thinking clearly… :stuck_out_tongue:

Since I am new to the software, am not too familiar with it yet. I’ll check the code out later today and will get back to you as soon as I can.

I remember why I did the loading via jquery…otherwise i cannot be assured, that the piwik.js is totaly loaded when trying to execute the tracking code.

To me this seems to be a bug in the handling of JS when leaving the page. I have opened an issue at GitHub: Outlink tracking not working with JS tracker in FF and IE · Issue #10088 · matomo-org/piwik · GitHub