Piwik & PHP Fusion V7

At first: A Happy New Year to all.

Installed Piwik 0.2.28 and it ran perfect. Good work. Now i’m trying to get the javascript running on a PHP Fusion V7 (Version 7.00.4) based website. When i put it in the same place as google analytics (/includes/footer_includes.php) it will cause a corrupted website, that means that all panels with the exception of the News Panel are disappearing or i get white page without any source code.

I coded it the same way like google analytics (which can run w/o problems):

[b]echo ' .... javascript code .... ';[/b]

Also tried with a " instead a but this will give the same result. Also tried on other places, like the footer.php of the theme but either it will not appear or the design is corrupted. Do you have a idea what can be wrong ?

If you do not know PHP Fusion, here the link to the main website in UK: www.php-fusion.co.uk/

Searched the forum there but there’s no thread dealing with Piwik. Also tested with PHP Fusion V6 and got the same problems.

[quote=fusionfan @ Jan 1 2009, 01:14 PM]I coded it the same way like google analytics (which can run w/o problems):

[b]echo ' .... javascript code .... ';[/b][/quote]


Forgive me if I have misunderstood. I am not sure why you have the “echo” statement there at all. I use modx as a CMS and I just enter the code into the footer exactly as follows:

<script type="text/javascript">
piwik_action_name = '';
piwik_idsite = 1;
piwik_url = pkBaseURL + "piwik.php";
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
piwik_hosts_alias = ["www.mydomain.com", "dev5.mydomain.com","piwik.mydomain.com","mydomain.foxycart.com"];

If you really have to have it within an echo statement then you will need to use escape characters before specific characters in the piwik code. Addslashes is your friend. Have a look here for details:


Hope this helps


Hello leapy,

MODx seems to work with HTML at this point, so there is no need for a echo statemant. Fusion works pure with PHP and so when calling a script, there is a need for a echo.

I also think that it deals with the escape sequences and normally a change from " to solves problems. So i could get the google analytics code work. In this case not. Addslash is only needed when you write to database. In this case we want to execute HTML and Javascript from a PHP file.

This is exactly the code Piwik gave me:

<!-- Piwik -->
<a href="http://piwik.org" title="Open source analytics" onclick="window.open(this.href);return(false);">
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.mydomain.com/" : "http://www.mydomain.com/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
piwik_action_name = '';
piwik_idsite = 1;
piwik_url = pkBaseURL + "piwik.php";
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
<object><noscript><p>Open source analytics <img src="http://www.mydomain.com/piwik.php?idsite=1" style="border:0" alt=""/></p></noscript></object></a>
<!-- End Piwik Tag -->

So the question is how to code the echo to make it work. Tried to put the code into a separate PHP File which i just included using require, but this produces the same effect.

Also tried simply to put the code into a panel, but this resulted in nothing. The panel is not visible (i made sure that it is active) and looking on the page source PHP creates i cannot see the Piwik code and the page is looking normal. When i do not see the Piwik code in the page source it will not executed and so nothing is counted.

Hello again,

Sorry, without using PHP Fusion, I am not able to go further. All I would say is that the PHP function addslashes is used any time you need a string outputted with correct escape characters - not just for writing to a database. I have used it many times for this reason.

Perhaps you could try it and see?


Hi leapy,

thx for info.


echo addslashes (' ... ');


echo addslashes (" ... ");


echo addslashes ( ... );

within the /includes/footer_includes.php ( which the normal place reserved especially for such a code) produces the same result: Corrupted theme. Same happens when i pack the Piwik code into a variable and code the echo like this:

echo addslashes ($analytics);

I have a feeling that the code itself conflicts with PHP Fusion Coding, but i wonder why. Cannot see anything unsusual. Normally i have no problem executing javascripts within Fusion using the normal echo ’ … ’ ); . The Amazon scripts are working, Google Analytics is working, other AD-scripts are working … The Piwik script is the first one which caused problems.

[b]**** UPDATE: I think i got it. ****[/b]

The code which seems to work is:

.... The Piwik code here ....

I put it in the /includes/footer_includes.php. The page is not corrupted and now i can see the Piwik Code in the page source and so i assume that monitoring will work now.

Wow, at least you got there. Life is just a big workaround sometimes ;0)

Can confirm now. The workaround works. Tested on PHP Fusion V7.00 and PHP Fusion V6.01 . On V6 websites the code must be placed in /footer.php.

Perhaps it’s a good idea to add this workaround to the FAQ. I think other PHP software can also be affected by this problem, not only Fusion.