0.0.5 • Published 9 years ago

ember-cli-piwik v0.0.5

Weekly downloads
133
License
MIT
Repository
github
Last release
9 years ago

ember-cli-piwik

Build Status Dependency Status Inline docs

Inject the Piwik tracking code into an ember-cli application.

Please note that this is not production-ready software and that it may lack many features. Should you feel something is missing or just not right, feel free to file a new issue or submit a new PR. Your contribution is mostly appreciated.

Installation

In your project root, run:

ember install ember-cli-piwik

Configuration

This addon is configured via your application's config/environment.js file by adding two configuration options: ENV.piwik.sid and ENV.piwik.url.

In order to configure your application, add the following object to your environments:

piwik: {
  sid: 123,
  url: 'https://your-piwik.endpoint.com'
}

You can have independent site IDs and URLs per environment, for example:

if (environment === 'development') {
  ENV.piwik = {
    sid: 3,
    url: 'http://your.piwik.domain/and/path'
  }
}

// ...

if (environment === 'production') {
  ENV.piwik = {
    sid: 7,
    url: '//another-piwik.endpoint.com'
  }
}

Usually though the only difference between environments is the site ID. In such a situation, the best approach is the following:

// config/environment.js
module.exports = function(environment) {
  var ENV = {
    // ...
    piwik: {
      url: 'https://piwik.endpoint.com'
    },
    // ...
  };

  if (environment === 'development') {
    // ...
    ENV.piwik.sid = 2;
  }

  if (environment === 'test') {
    // ...
    ENV.piwik.sid = 7;
  }

  if (environment === 'production') {
    // ...
    ENV.piwik.sid = 19;
  }

  return ENV;
};

Automatic PageView Tracking

This addon can take care of notifying pageviews to the Piwik server when transitioning into a route automatically.

All you have to do is to extend the main application router with the provided mixin:

// app/router.js
import Ember from 'ember';
import config from './config/environment';
import Piwik from 'ember-cli-piwik/mixins/page-view-tracker';

var Router = Ember.Router.extend(Piwik, {
  location: config.locationType
});

Router.map(function() {
  // ...
});

export default Router;

Now when the didTransition event fires, the router will call the Piwik tracker which in turn will emit a trackPageView event passing the current URL as the event title.

Content Security Policy (CSP)

Please be aware that since version 0.0.47 ember-cli ships with CSP support out of the box through the ember-cli-content-security-policy addon. This is a good thing, as in the proper Ember spirit, it nudges you towards adopting the best practices from day 1.

There is an "issue" though: by default, it is configured to be extremely strict about script sources and script capabilities.

To make everything run smoothly, make sure you add the URLs you used in your Piwik configuration to the relevant options of the CSP settings.

For more information, please refer to the ember-cli-content-security-policy documentation.

Running Tests

Clone this project, install the dependencies, then run the tests:

$ git clone https://github.com/unwiredbrain/ember-cli-piwik.git
$ npm install && bower install
$ npm test

Acknowledgements

Peter Grippi, for his ember-cli-google-analytics addon.

License

The MIT License (MIT)

Copyright (c) 2015 Massimo Lombardo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Still here!? Go develop something amazing!

EOF