Skip to main content
Topic: How to use Matomo (Read 620 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to use Matomo

Hi,
I would like to use Matomo but i don't know where insert the code !
To use Matomo a code must be insert and Matomo says "We recommend that you place it immediately before the closing </head> tag.".
But in the index.php there isn't this tag.
Somebody knows how to do with Elkarte ?
Thanck you,
Philippe

Re: How to use Matomo

Reply #1

Quote from: augras  -  Hi,
I would like to use Matomo but i don't know where insert the code !
To use Matomo a code must be insert and Matomo says "We recommend that you place it immediately before the closing </head> tag.".
But in the index.php there isn't this tag.
Somebody knows how to do with Elkarte ?
Thanck you,
Philippe


Hey Philippe! There are several options you could consider to accomplish your goal.

The first employs direct hardcode edits. In ./themes/default edit index.template.php. Find the </head> tag around line 221. Add the needed code just before it. If your site offers other themes, you'll need to edit the index.template files for them as well.

Another option would be adding an integration hook and a file containing the needed code. It could even be packaged as an add-on! If you aren't certain how to accomplish it this way, it probably isn't the option you'd want to use.

Yet another option is using an existing add on to inject the needed code. Simple Ads or Simple Portal add ons could both accomplish this. In a nutshell you'd add an html block, then inject the code like this:

Code: [Select]
<head>
.....custom code here.....
</head>

and set the block location nearest the top of the page (header, or something like that).

The best option depends on your coding skill level. Good luck!

Re: How to use Matomo

Reply #2

Thank you @badmonkey ,

I think i have now all the options.

I was looking in /elkarte/index.php but of course it's in the template !

But it doen't work : i get the error : syntax error unexpected 'trackPageView' (T_STRING), expecting ';' or ','
And it's because the script is not correctly interpreted.

I put the code just before </head> but i can see that the color for the syntax is not good (here it's ok but in the file it's all yellow).

The code is :
Code: [Select]
<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//augras.eu/matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '5']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

<noscript>
<!-- Matomo Image Tracker-->
<img referrerpolicy="no-referrer-when-downgrade" src="https://augras.eu/matomo/matomo.php?idsite=5&amp;rec=1" style="border:0" alt="" />
<!-- End Matomo -->
</noscript>

I will try with an addon.

Thank you,
Philippe

Re: How to use Matomo

Reply #3

Quote from: badmonkey  -  The best option depends on your coding skill level. Good luck!
It's a very small level !

I tried to put the code (the code is ok : it works on other site, there is just to change a number) :
Code: [Select]
<html>
<head>
<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//augras.eu/matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '6']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

<noscript>
<!-- Matomo Image Tracker-->
<img referrerpolicy="no-referrer-when-downgrade" src="https://augras.eu/matomo/matomo.php?idsite=6&amp;rec=1" style="border:0" alt="" />
<!-- End Matomo -->
</noscript>
</head>
</html>
in a addon subst file (UltimateMenu.subs.php, and some others) but get the error
Code: [Select]
syntax error unexpected 'trackPageView' (T_STRING), expecting ';' or ','

But maybe it's not what you mean ?

Maybe it will be a good idea to make an addon to put some scripts easily in head and in body ?
You understand i can't do that :).

Philippe

Re: How to use Matomo

Reply #4

It works !
Maybe it's not the better way...

In ./themes/default/index.template.php, just at the beginning but after
Code: [Select]
<?php
i insert
Code: [Select]
require 'matomo.php';
In ./themes/default/ i created the file matomo.php with the code :
Code: [Select]
<html>
<head>
<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//augras.eu/matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '5']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

<noscript>
<!-- Matomo Image Tracker-->
<img referrerpolicy="no-referrer-when-downgrade" src="https://augras.eu/matomo/matomo.php?idsite=5&amp;rec=1" style="border:0" alt="" />
<!-- End Matomo -->
</noscript>

It is important to don't close <html> and <head>.

And like this it works.

I don't know why it doesn't work as @badmonkey said, because it's nearly the same thing !

Now i need to remember that when there will be an update.




Re: How to use Matomo

Reply #5

Quote from: augras  -  It works !
Maybe it's not the better way...
And it's not !

Matomo works fine but not Elkarte. you can see the problem on this post :
https://www.elkarte.net/community/index.php?topic=5934.15
There is an xml problem and Quote, Quick reply and maybe some others things doen't work anymore.

So, the question to make matomo working is still open.

 

Re: How to use Matomo

Reply #6

Hi,
Anybody has an idea to make Matomo works ?

Re: How to use Matomo

Reply #7

You can try separating the script into js file.

Re: How to use Matomo

Reply #8

Thank's @ahrasis for the idea,
But i don't really know how to do that.
Is it just rename matomo.php to matomo.js and call matomo.js ?

Re: How to use Matomo

Reply #9

I tried like i said : it's around the same thing.
Quick edit is now working but still not Quote, and Modify is now not working.