Javascript tracking & action name


(The Grim Sultan) #1

I started building a website and decided today to use Piwik.

This is the Piwik generated code:

<!-- Piwik -->
<a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://thegrimsultan.com/piwik/" : "http://thegrimsultan.com/piwik/");
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);
</script>
<object><noscript><p>Web analytics <img src="http://thegrimsultan.com/piwik/piwik.php?idsite=1" style="border:0" alt=""/></p></noscript></object></a>
<!-- End Piwik Tag -->

I want to modify the piwik_action_name, to improve the tracking. I use switches in PHP and have URLs like index.php?page=Home&lang=NL and index.php?page=Home&lang=EN.

The defualt script doesn’t work as I want, I only see “/index” for every hit. So I modified the action name a little bit:

...
<script type="text/javascript">
piwik_action_name = "<?php echo $_GET["lang"].": ".$_GET["page"] ?>";
piwik_idsite = 1;
piwik_url = pkBaseURL + "piwik.php";
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
</script>
...

Which results in:

...
<script type="text/javascript"> 
piwik_action_name = "EN: Home";
piwik_idsite = 1;
piwik_url = pkBaseURL + "piwik.php";
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
</script> 
...
...
<script type="text/javascript"> 
piwik_action_name = "NL: Home";
piwik_idsite = 1;
piwik_url = pkBaseURL + "piwik.php";
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
</script> 
...

I hoped this would result in “/EN: Home” and “/NL: Home”, instead of “/index”. It results in “/:”.

What do I need to modify to see it working as I want it?


(vipsoft) #2

Except $_GET[“lang”] and $_GET[“page”] are blank.


(The Grim Sultan) #3

What do you mean by ‘blank’?

When I view the page source, it isn’t blank. The same code also works for BBclone.


(vipsoft) #4

Unless you rewrite the url, someone visiting your site without those params in the url (eg “/” or “/index.php”) will result in your php code getting null strings for those query params.