Skip to content

Commit

Permalink
Merge branch 'release/0.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Aug 31, 2015
2 parents 19cf0cb + bed1f28 commit 496ac5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,33 @@ ember install:addon ember-metrics

## Usage

In order to use the addon, you must first [configure](#configuration) it, then inject it into any Object registered in the container that you wish to track. For example, you can call a `trackPage` event across all your analytics services like so:
In order to use the addon, you must first [configure](#configuration) it, then inject it into any Object registered in the container that you wish to track. For example, you can call a `trackPage` event across all your analytics services whenever you transition into a route, like so:

```js
// app/router.js
import Ember from 'ember';
import config from './config/environment';

export default Ember.Route.extend({
metrics: Ember.inject.service(),

activate() {
const metrics = get(this, 'metrics');
const Router = Ember.Router.extend({
location: config.locationType,
metrics: inject.service(),

metrics.trackPage({
title: 'My Awesome App'
didTransition() {
this._super(...arguments);
this._trackPage();
},

_trackPage() {
Ember.run.scheduleOnce('afterRender', this, () => {
const page = document.location.href;
const title = Ember.getWithDefault(this, 'routeName', 'unknown');

Ember.get(this, 'metrics').trackPage({ page, title });
});
}
});

export default Router.map(/* ... */);
```

If you wish to only call a single service, just specify it's name as the first argument:
Expand Down
2 changes: 1 addition & 1 deletion addon/services/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default Service.extend({
const dasherizedAdapterName = dasherize(adapterName);
const availableAdapter = container.lookupFactory(`ember-metrics@metrics-adapter:${dasherizedAdapterName}`);
const localAdapter = container.lookupFactory(`metrics-adapter:${dasherizedAdapterName}`);
const adapter = availableAdapter ? availableAdapter : localAdapter;
const adapter = localAdapter ? localAdapter : availableAdapter;

return adapter;
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-metrics",
"version": "0.1.3",
"version": "0.1.4",
"description": "Send data to multiple analytics integrations without re-implementing new API",
"directories": {
"doc": "doc",
Expand Down

0 comments on commit 496ac5c

Please sign in to comment.