diff --git a/README.md b/README.md index 920cc689..a3eb4d2d 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/addon/services/metrics.js b/addon/services/metrics.js index 4da239f1..b5247768 100644 --- a/addon/services/metrics.js +++ b/addon/services/metrics.js @@ -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; }, diff --git a/package.json b/package.json index bc698cbf..3eaa6f25 100644 --- a/package.json +++ b/package.json @@ -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",