How to Add Matamo/Piwiki Tracking Code?
Hi, I wanted to add some tracking code to my WackoWiki instance. I successfully did this in the 5.4 version in the common _header.php. I just upgraded to the latest, 5.5.7 and it's changed to _header.tpl. I'm not familiar enough with the template being used and not able to add my tracking JS in there like I did before. An example of the JS is as follows:
If JS no longer works or is allowed, I can do it by a hidden image but I was curious how I can get the Name of the page so I can accurately track which pages a user visited by passing it as a query string parameter to my image src.
Log in or create an account to post a comment.
Re: How to Add Matamo/Piwiki Tracking Code?
Just copy the JS or HTML code to theme/_common/_header.tpl
If you want pass a variable to the template use
$tpl->h_variable = $value;in the corresponding file, e.g. _header.php.
Add the variable in the template as following
[ ' name | e js ' ].
h_because it becomes part of the definition
[''' h HtmlHead ''']in header.php of your theme
e js– escapes the provided data
Example 1 for Image Tracker:
All examples untested.
You may want add conditions like tracking only pages (show handler) or guests.
Or set it for example in the _header.php with
$this->add_html('header', '<script> ... </script>');.
If you're interested we can write and maintain a Matomo integration HowTo.
[ ' db: idsite | e js ' ]– pull value from config
so the template interpreter thinks
['setTrackerUrl', u+'piwik.php']is some sort of variable information from the php file. Is there an escape character?
Anyways, I tried what was suggested in [B], using
add_htmland that worked! However, one more useful instruction is
add_htmlshould be called before
$tpl->h_additions = $this->get_html_addition('header');in the _header.php file.
Yeah, would be interested in helping with Matomo integration HowTo. However, would need some more reference about what is mentioned, extensions/config. I do agree the variable approach would be great. Also, same about the admin panel module and creating one for Matamo, would need some guidance about modules in admin panel.