probberechts / hexo-theme-cactus

:cactus: A responsive, clean and simple theme for Hexo.
https://probberechts.github.io/hexo-theme-cactus/
MIT License
3.15k stars 783 forks source link

Adding Matomo tracking #258

Closed gokomer closed 3 years ago

gokomer commented 3 years ago

Hello,

I'm trying to add Matomo tracking script to cactus. Matomo gave me a js code and I modified it as below and add it to the _partial/scritps.ejs.

<!-- Matomo -->
<% if (theme.matomo_analytics.enabled && theme.matomo_analytics.site_id && theme.matomo_analytics.site_url && theme.matomo_analytics.subdomain){ %>
  <script type="text/javascript">
    var _paq = window._paq = window._paq || [];
    /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
    _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
    _paq.push(["setCookieDomain", "*.<%= theme.matomo_analytics.site_url %>"]);
    _paq.push(["setDomains", ["*.<%= theme.matomo_analytics.site_url %>"]]);
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
      var u="https://<%= theme.matomo_analytics.subdomain %>.matomo.cloud/";
      _paq.push(['setTrackerUrl', u+'matomo.php']);
      _paq.push(['setSiteId', '<%= theme.matomo_analytics.site_id %>']);
      var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
      g.type='text/javascript'; g.async=true; g.src='//cdn.matomo.cloud/<%= theme.matomo_analytics.subdomain %>.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s);
    })();
  </script>
  <noscript><p><img src="https://<%= theme.matomo_analytics.subdomain %>.matomo.cloud/matomo.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript>
<% } %>

Add the following to the _config files.

matomo_analytics:
  enabled: true
  id: 1
  subdomain: subdomain
  domain: domain.com

But matomo can't get any data from my site. Can you give me any info about what's wrong with my approach?

probberechts commented 3 years ago

I do not know Matomo, but it seems that you forgot to add site_id and site_url to the config.

gokomer commented 3 years ago

I'm sorry. It looks like I posted older config file. It looks like the below.

matomo_analytics:
  enabled: true
  site_id : 1
  subdomain: subdomain
  site_url: domain.com

If this is all I need to do to implement this tracking then I'll check the configuration of matomo side.

probberechts commented 3 years ago

Simply look at the html source of your site and check whether the tracking code is there. It seems ok to me.