Support for Piwik Analytics as an alternative to Google Analytics

(Erlend Sogge Heggen) #64

This is getting off topic, but I’m gonna reply here in hopes that a moderator will split Sam’s post into a new “Preliminary plugin directory” topic.

I realise you were just making an example, but I’d still like to point out that Discourse doesn’t need ratings et.al. for plugins right now, it just needs better distribution, period. An equivalent of WordPress’ GitHub Updater or WP Pusher would suffice.

0 Likes

#65

Yep, a plugin either works or it doesn’t, a rating wouldn’t be useful IMO.

0 Likes

(gingerling) #66

Hi, I would really like this feature for a long list of reasons, from supporting other Open Source projects to helping protect the privacy of our users from googles evil prying eyes :slight_smile: Just wanted to give my +1 to this and hope it will be fully supported soon :smile:

0 Likes

(Sam Saffron) #67

The feature exists, the problem is that we don’t have a clean package for it.

0 Likes

(gingerling) #68

What does this mean? What is it that you need exactly?

0 Likes

(Sam Saffron) #69

Someone who cares about pwiki enough to build a plugin for it.

Or … this

0 Likes

(gingerling) #70

So, it IS possible without a plugin? Or it is possible only if someone builds a plugin…

0 Likes

(Sam Saffron) #71

Its possible without a plugin, by adding a site customization.

0 Likes

(gingerling) #72

Ok, @rata apparently this is possible - can you look into it more?

0 Likes

(Nate D.) #73

I would definitely replace analytics with piwik! :thumbsup:

2 Likes

(Matthieu) #74

Hi guys,

Matthieu from Piwik team here! We are testing Discourse at the moment to use it ultimately on forum.piwik.org -

Here is the correct Piwik to insert in Admin > Customize > CSS/HTML > </body>

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//<!-- URL HERE -->";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', <!-- WEBSITE ID HERE -->]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
  
  Discourse.PageTracker.current().on("change", function(url) {
  _paq.push(["setCustomUrl", url]);
  _paq.push(["setDocumentTitle", document.title]);
  _paq.push(["trackPageView"]);
  });
</script>
<!-- End Piwik Code -->

(compared to latest posted code, I moved setDocumentTitle call just above trackPageView to ensure we track the pageview with the correct document title). It seems to work fine so far!

13 Likes

(Sam Saffron) #75

Awesome

I made the op wiki, maybe add this snippet there, or perhaps just do a new howto topic, your call, will make it much easier for people to find

2 Likes

(Brahn) #76

Some time back the change trigger was being called before the _docTitle had completed but I have tested again and can confirm that it has long since been fixed. Thanks for the refresh :smile:

A couple of other changes I am trying out:

Use the docTitle parameter rather than document.title

Discourse.PageTracker.current().on("change", function(url, docTitle) {
  _paq.push(["setCustomUrl", url]);
  _paq.push(["setDocumentTitle", docTitle]);
  _paq.push(["trackPageView"]);
});

I also noticed that in the _google_analytics.html.erb there is a _setCustomVar for Anonymous true/false. Here is my attempt, I would appreciate any comments or suggestions!

var currentUser = PreloadStore.get('currentUser');
_paq.push(['setCustomVariable', 1, 'Anonymous', !currentUser, 'visit']);
_paq.push(["setTrackerUrl", u+"piwik.php"]);
//etc...
0 Likes

(Rafael dos Santos Silva) #77

Does anyone know why my Discourse.PageTracker is undefined?

<script type="text/javascript">
  Discourse.PageTracker.current().on("change", function(url) {
  console.log(url);
  console.log(document.title);
  });
</script>
0 Likes

(Sam Saffron) #78

@eviltrout do we still have a shim for page tracker?

0 Likes

(Erlend Sogge Heggen) #79

I think a dedicated howto page is greatly preferable. He’s TL1 though, so I took the liberty to make it myself:

@mattab please make any edits you’d like (as soon as the post is wikified)

2 Likes

(Robin Ward) #80

Discourse.PageTracker still works but is deprecated. I just confirmed this on meta.

It is likely a load order thing. Perhaps it is trying to be accessed before the Discourse app boots up?

1 Like

Script to enable Matomo analytics on Discourse
(Rafael dos Santos Silva) #81

Here on meta I can open devtools and type Discourse.PageTracker and it’s defined.

On my instance, at this commit it’s undefined. Is it a new feature?

0 Likes

(Rafael dos Santos Silva) #82

Nevermind, you added it on August 11, I’m on August 10 version. :sadpanda:

PS.: Today I was facing a rails bug fixed on June 26, and was using rails 4.2.3 from June 25, lucky day huh?

0 Likes

(Sam Saffron) #83

it sure is … that is my birthday

3 Likes