Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Matomo tracking #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

daneov
Copy link

@daneov daneov commented May 26, 2018

This PR adds the following options to Params:

  • matomoUrl
    • the url where the Matomo instance can be reached
  • matomoSiteId
    • the id of the site on Matomo (defaults to 1)
  • matomoEnableFallback
    • Flag to enable way to track when JS is disabled
  • matomoDomainPrefixed
    • Flag to prefix the tracked page with the domain
  • matomoClientSideDNT
    • Flag to respect DNT header on client-side already (otherwise the request still goes to the server, where it then'll be ignored - if it respects the DNT)

P.S. This is my first encounter with Hugo's templating, if something can be done better, please suggest / correct 👍

@daneov daneov force-pushed the matomo_support branch 2 times, most recently from c56687c to 4da4f63 Compare May 26, 2018 16:46
@daneov daneov force-pushed the matomo_support branch 2 times, most recently from 64635c5 to 3fe0c07 Compare May 26, 2018 17:33
@jbub jbub self-assigned this May 27, 2018
Copy link
Owner

@jbub jbub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Lets do it more like the google analytics internal template, maybe we can then merge it upstream as a internal hugo template.

@@ -17,6 +17,7 @@
{{ if .RSSLink }}
<link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml">
{{ end }}
{{ if .Site.Params.MatomoUrl }}{{ partial "matomo.html" . }}{{ end }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this at the top of body just after the google_analytics in the header.html ? Also lets do the if check inside the template.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do 👍

@@ -0,0 +1,21 @@
{{ $siteId := cond (isset .Site.Params "matomositeid") .Site.Params.MatomoSiteId "1" }}
{{ $clientSideDNT := cond (isset .Site.Params "matomoclientsidednt") .Site.Params.MatomoClientSideDNT true }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do the DNT check just like in the google analytics template https://raw.githubusercontent.com/gohugoio/hugo/master/tpl/tplimpl/embedded/templates/google_analytics.html and introduce a param like matomoRespectDoNotTrack. If that option is true it should not even include the tracking snippet, just like in the google analytics. Also be sure to check for user DNT setting in browser var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I see where you're getting at.

However, this specific flag serves to include a JS snippet that prevents the request from being sent at all if the user's DNT setting is turned on.
So the check you're referring to is in the javascript that is included. https://github.com/matomo-org/matomo/blob/6f5b85b6f7d2195362ae03480120f4cef5ec4dc1/js/piwik.js#L6564

Knowing this, would you still add it yourself? :)

g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
{{ if .Site.Params.MatomoEnableFallback }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this fallback ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a Matomo specific option, not really a fallback for the option on its own, but if the user has JS disabled this 'fallback' provides a way of tracking it using an img element.

So, a better suggestion for the name?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do people still disable javascript ? I mean most of today pages are JS heavy :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally know a few ¯\_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants