Tracking code in headers

Mick Dawlings Posted in Technical Support 1 year ago

We use matomo internally to get stats on all our sites to better understand flow and usages.
I need to put similar code into the headers of the ossn site. I obviously do not want to edit every single file.

I've searched Google and this site and cannot find anyone asking about this.
Does someone know how I can add tracking code so that it will be across the entire site?

Replies
us Mick Dawlings Replied 1 year ago

I think you said it :).

CustomHeaderCode perhaps?

Anyhow, the component is working perfectly. Thanks.

German Michael Zülsdorff Replied 1 year ago

Yes, that's what I was trying to express with "This component will add your Google Analytics code or anything similar to the head section of your site."
Feel free to suggest a better component description - I'm not a native English speaker

us Mick Dawlings Replied 1 year ago

Nice, that works perfectly.

If I end up using Google or Bing or something else, can I simply add the code into this as well?

us Mick Dawlings Replied 1 year ago

Ok, I'll download it as soon as I see it and see what happens.

Indonesian Arsalan Shah Replied 1 year ago

7.1 is already available

us Mick Dawlings Replied 1 year ago

I tried it but,

"This component requires OSSN 7.1 or higher"

I guess it means I have to wait for the 7.1 premium?

German Michael Zülsdorff Replied 1 year ago

Give it a try and install Google Analytics
https://www.opensource-socialnetwork.org/component/view/2332
It's basically capable of inserting ANY valid code into the <head> section of Ossn sites.

Re BTW:
No question, 1 line of code will execute faster than 1000 lines. :) Thus, in the end it depends on the very component (will it load 3rd party scripts, extra fonts, whatever?). Just use your browser's developer console to compare load times with a component enabled/disabled.

us Mick Dawlings Replied 1 year ago

Hi,

Sure, it looks like this (edited)

<!-- 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="https://tracking.domain.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '10']);
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 -->

BTW, does adding components start bogging down the site eventually? I would want to limit the number of components the site is using if possible.

German Michael Zülsdorff Replied 1 year ago

Please provide the matamo code snippet in question ...
maybe the Google Analytics component will do