Confluence piwik javascript not rendered in head tags

I think this has been touched on in other questions, but it still doesn't work for me. Trying to use Piwik for web analysis.

Confl. version is 5.9.5

Some docs say insert this in Custom HTML, in "end of head" section (this code comes straight from my Piwik server):

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  (function() {
    var u="//[OUR PIWIK SERVER URL]";
    _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.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
<noscript><p><img src="//[OUR PIWIK BOX]/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->


This script never runs.

In another thread, someone did this:


<!-- Piwik -->
<script type="text/javascript">
    var _paq = _paq || [];
        var u = (("https:" == document.location.protocol) ? "https://<<INSERT YOUR PIWIK URL HERE>>" : "http://<<AND HERE>>");
        _paq.push(['setSiteId', <<INSERT YOUR ID HERE>>>]);
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setCustomVariable', 1, "Space", AJS.params.spaceKey, "visit"]);
        _paq.push(['setCustomVariable', 2, "NTid", AJS.params.remoteUser, "visit"]);
        _paq.push(['setCustomVariable', 3, "User", AJS.params.currentUserFullname, "visit"]);
        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';
<!-- End Piwik Code || Edited 1/9/2015, working with version 5.3.4 of confluence–>


This doesn't work for me either. Apache logs on the server side show no GET request so I think this isn't executing at all.
Anything else I can try? Thanks!

1 answer

I have it at the end of the body, you should try as well (it works for me).

Apart from that, to verify that the code is being executed, you can add a Javascript message box. Every time you load a Confluence page (normal page, not administration one) you should get a modal message window:

alert("Hello! I am an alert box!!");

 Hope this helps.

<script type="text/javascript">
alert("test alert");

works as expected when placed in Custom HTML -> At the end of HEAD. I didn't try in in <body> tags.

So that's encouraging. I'll have to start looking closer at the Piwik-generated JS code to see where things are going wrong.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Tuesday in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

183 views 2 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you