Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request adopted-ember-addons#216 from jelhan/update-readme
Browse files Browse the repository at this point in the history
update readme to reflect current best practices
  • Loading branch information
mike-north authored Feb 12, 2019
2 parents 6b236e5 + 03acc03 commit 8d8c8e5
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,10 @@ Writing your own adapters for currently unsupported analytics services is easy t

## Installing The Addon

For Ember CLI >= `0.2.3`:

```shell
ember install ember-metrics
```

For Ember CLI < `0.2.3`:

```shell
ember install:addon ember-metrics
```

## Configuration

To setup, you should first configure the service through `config/environment`:
Expand Down Expand Up @@ -210,19 +202,18 @@ import { scheduleOnce } from '@ember/runloop';
const Router = EmberRouter.extend({
location: config.locationType,
metrics: service(),
router: service(),
didTransition() {
init() {
this._super(...arguments);
this._trackPage();
},
_trackPage() {
scheduleOnce('afterRender', this, () => {
const page = this.get('url');
const title = this.getWithDefault('currentRouteName', 'unknown');
this.on('routeDidChange', () => {
const page = this.router.currentURL;
const title = this.router.currentRouteName || 'unknown';
get(this, 'metrics').trackPage({ page, title });
this.metrics.trackPage({ page, title });
});
}
});
Expand All @@ -244,8 +235,10 @@ metrics.trackPage('GoogleAnalytics', {
Often, you may want to include information like the current user's name with every event or page view that's tracked. Any properties that are set on `metrics.context` will be merged into options for every Service call.
```js
Ember.set(this, 'metrics.context.userName', 'Jimbo');
Ember.get(this, 'metrics').trackPage({ page: 'page/1' }); // { userName: 'Jimbo', page: 'page/1' }
import { set } from '@ember/object';
set(this, 'metrics.context.userName', 'Jimbo');
this.metrics.trackPage({ page: 'page/1' }); // { userName: 'Jimbo', page: 'page/1' }
```
### API
Expand Down Expand Up @@ -286,13 +279,14 @@ If an adapter implements specific methods you wish to call, then you can use `in
If your app implements dynamic API keys for various analytics integration, you can defer the initialization of the adapters. Instead of configuring `ember-metrics` through `config/environment`, you can call the following from any Object registered in the container:
```js
import Ember from 'ember';
import { Route } from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default Ember.Route.extend({
metrics: Ember.inject.service(),
export default Route.extend({
metrics: service(),
afterModel(model) {
const metrics = Ember.get(this, 'metrics');
const id = Ember.get(model, 'googleAnalyticsKey');
const metrics = this.metrics;
const id = model.googleAnalyticsKey;
metrics.activateAdapters([
{
Expand Down Expand Up @@ -370,7 +364,9 @@ module.exports = function(environment) {

## Testing

For unit tests, you will need to specify the adapters in use under `needs`, like so:
For unit tests using old QUnit testing API (prior to
[RFC 232](https://github.com/emberjs/rfcs/blob/master/text/0232-simplify-qunit-testing-api.md)),
you will need to specify the adapters in use under `needs`, like so:

```js
moduleFor('route:foo', 'Unit | Route | foo', {
Expand Down

0 comments on commit 8d8c8e5

Please sign in to comment.