PIWIK tracking code working for HTML-site but not for php-site

Hello,

I have 2 sites: one HTML-site and one php-site.
On the HTML-site PIWIK is working fine sinds a few years now :).

Recently I updated PIWIK (1.8.3) and added a new site (php).
The HTML-site is still working fine, but the php-site does not track anything.
The PIWIK tracking code I use is for both sites the same, except for the ID-numbers.

I had the same problem also with Google Analytics.
I solved the problem with the Google Analytics tracking code by replacing alle the ’ with ". X(

For the PIWIK tracking code replacement of ’ by " did not work?!?

Can anyone help me out this?

Thanx!
StartersCom.nl


StartersCom.nl - Eigen bedrijf beginnen doe je hier!

Which URL is not working for tracking? send it and we can look at the problem… but it should work the same as HTML normally!

Hello,

My PIWIK script is located in the HTML-site.
And recently I added in my PIWIK control panel a new site (that has a php index), but this new site shows no tracking.
The URL of this site which is not working is:

www.starterscom.nl.

As I mentioned before I did not succeed to paste the tracking code before the and make the PIWIK script work. While this was no problem in my other site.

When I paste the tracking code, my homepage of starterscom.nl can not open (template error). I think this is due to the ’ in the tracking code (I think the ’ are cutting of the echo statements).

Replacement of the ’ with " does not work for the PIWIK tracking code.
While the same problem in the Google analytics tracking code was solved by replacing the ’ with ".

Thanks a lot for your help.
StartersCom.nl


StartersCom.nl - Eigen bedrijf beginnen doe je hier!

I’m getting a JavaScript error on your site.

The one line should be


document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));

(src = {single quote} {double quote} … piwik.js {single quote} )

@Robertb,

the {single quote} in the tracking code is just my whole problem.
When I use the original javascript tracking code in my php-index page with the {single quote} then my site can’t open (template error). In my other site (HTML-index) I use the original tracking code with {single quots} without problems.

This is why I replaced all the {single quotes} with {double quotes} in the new site starterscom.nl. Now my site opens but the PIWIK script does’t track anything.

my php-index page looks like this:

echo’

It’s like the {single quotes} in the tracking code are cutting of the echo statement and then give the template error.

PHP: Strings

If you have a php statement which is enclosed by single quotes and want to have another single quote within the string you need to escape the character with a backlash, e.g.


$foo = 'That\'s nice';

would echo out as That’s nice. If you’d just have the single quote without the backslash PHP would think the string is finished and give syntax error for the rest.

So,


echo 'document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\' type=\'text/javascript\'%3E%3C/script%3E"));';

will produce


document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));

in your output.

YEEEEEEEEEEEESSSSSSSSSSSSSS!!! (:smiley:

Woowww @Robertb,

your last advise did it.
Now it works great!!!

Thanks a lot man, you don’t want to know how much time I have spent to make that work.
Thanks to you now it does work!