ember.jsmatomo

How can I use piwik in an ember application?


Is there any component or plugin that I can use, to integrate piwik into an ember application?


Solution

  • It's very simple actually. Sadly I haven't found out yet how I can track the individual views. But this will get you going with a basic set-up that also scales well.

    Put this in your ApplicationRoute it hooks the route's didTransition so that every time you transition between routes data gets send to the Piwik server.

        actions: {
            didTransition: function () {
                Ember.run.once(this, function () {
                    window._paq = _paq || [];
                    _paq.push(['trackPageView']);
                    _paq.push(['enableLinkTracking']);
                    _paq.push(['setTrackerUrl', 'https://[Piwik server]/piwik.php']);
                    _paq.push(['setSiteId', 1]);
                });
            }
        }
    

    And don't forget to put a reference to Piwik.js in your application template to load the Piwik tracking library.

    <script src="https://[Piwik server]/piwik.js" async defer></script>