New and old style tracking code – problems with additional sites

Hello,

as I’ve seen the tracking script code has changed. Using the new one works with the site that is placed on the same server where piwik itself. But it does not work for other sites with different site IDs. Those other sites are http:// the main site and the piwik installation are on a https:// server (via ssl proxy).

The old script got modified over the time, so it worked perfectly. Now, the new script seemed to be clear … but? No reaction. Why?

An example:

OLD style:


<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = "https://ssl.proxy.de/example.de/piwik/";
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", 2);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script>
<noscript>
<img src="https://ssl.proxy.de/example.de/piwik/piwik.php?idsite=2&rec=1" style="border:0" alt="">
</noscript>
<!-- End Piwik Tracking Code -->

NEW style:


<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://ssl.proxy.de/example.de/piwik/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "2"]);
    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);
  })();
</script>
<noscript>
<!-- Piwik Image Tracker -->
<img src="https://ssl.proxy.de/example.de/piwik/piwik.php?idsite=2&rec=1&action_name=xmpl" style="border:0" alt="">
<!-- End Piwik -->
</noscript>
<!-- End Piwik Code -->

With the new style there is no reaction. No visit is shown. With the old style it works. BTW, I think the notation should ask if using HTML old style or new style for the tag, if using old html code, does not find, but this is not the problem here and now.

Cheers

When you say the new JS code does not work, can you check if there’s any JS error on your site? CAn you reproduce the bug with a small HTML file that contains only the JS COde ?

What do you mean with JS error on the site? The source is, what I posted here. I tried it with three sites, the one where piwik is (https) – that works. Additional page 2 and additional page 3. Those are totally primitive sites with one, two pages, no scripts, just a little bit information and the above mentioned source. When visiting these sites, piwik does not react (with the new code). Before, and with the old (also above mentioned) source piwik reacts immediately. So, what is the difference between those two sources?

Maybe you use some JS on these sites that have errors ? or try with different browsers ?

No, there is no JS on that sites. And the browsers react the same. The script works for the site where p resides, it does not work for the other sites.

Maybe it’s necessary to show that:
http://www.thetrial.de/ – forwards to https and works
http://www.thetrial.eu/ – does not work e. g.
http://www.zodiakom.de/ – does not work either (with the new code, with the old, it works)

Seems, you don’t know the reason?!

It lookslike thepiwik.js is not loading correctly on the pages, that’s strange. Can you try remove the TRY CATCH block in the JS and see if a JS error shows up ?

If I remove (or comment out) that try-catch block piwik is not called anymore. It seems that this block »rescues«. Tested at www.thetrial.eu. After removing piwik did not recognize a visit.

And:
What are the benefits from using the new js tracking code?

It’s a lot of work changing all pages to new tracking code… :sunglasses:

The new tracking code is asynchronous - that means your page loads even if Piwik is down.

[quote=“Fabian Becker”]
The new tracking code is asynchronous - that means your page loads even if Piwik is down.[/quote]Thanks so far.
But Piwik is running on same server as whole website, so if Piwik is down, whole server has a problem…:S

Or how do you mean ‘asynchronous’?

Piwik can run on any server, not necessarily the same as your webpage. Asynchronous in this case means that browsers will not wait for the piwik.js file to be downloaded in order to show your page.

Well, but that new code does not work! It works on the same server, but not with pages on different servers (as mentioned before). The old code did that job.

Maybe the code generating should be finetuned? It’s not logic to add something like to a html 4 site. And, maybe all the “&” should be masked as “&”?

Hum what? Can you post the generated tracking code at http://gist.github.com

Code works perfectly fine for most people, so there is an issue with either your website or setup.

You haven’t read, what I’ve posted here on this site (above), have you? We start to rotate in a catch-22 …

I did read you post, but I don’t see how

relates to the code you posted. All ampersands in there are shown as & and there is no .

Well, let your piwik give you some code and look at it.

The closing “/>” has been removed manually by myself. And no, not all ampersands are masked. Only my own, old ones. Carefully look at the code. Above and in your own piwik. One could call it buggy.

I just tried it with a corrected code now (ampersand masquerade), but it does not work. Maybe it has to do something with the 1&1 ssl proxy. The new code is not functionable when not used in a site on the server itself. Upsetting.

Post a link to your website with the new tracking code installed.

Works perfectly fine for me and many other people.

Ah, you use an SSL proxy from 1&1? Good, please give me the URL or post the code of sites that are not on that server, means http sites point to another server that’s redirected via ssl proxy to https. I’m waiting.

New async js tracking code should be inserted in … area.

But howto describes inserting it before tag:
http://piwik.org/docs/javascript-tracking/#toc-where-can-i-find-the-piwik-tracking-code

Same in Piwik- administration settings:
http://img23.imageshack.us/img23/32/newtracking.jpg

oder ?

(Alternative img tracking code (for usage without js) will be inserted before .)
Thx…

both should work the same