Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/ember-cli-google-analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ export default class ApplicationRoute extends Route {
}
```

The `gtag.configure()` method optionally accepts an `options` object with any of the following properties:

| Property | Type | Desciption |
| --- | --- | --- |
| `measurementId` | `string` | When set, overrides the `measurementId` defined in your app's `config/environment` file. |
| `forceEnable` | `boolean` | If `true`, allows `gtag.configure()` to run in the `development` and `test` environments. (By default, `gtag.configure()` doesn't work unless the environment is `production`.) |
| `debugMode` | `boolean` | If `true`, configures `gtag` to run in debug mode, which can be helpful for development. |

Example using both properties:
```javascript
await this.gtag.configure({
measurementId: 'G-XXXXXXXXXX',
forceEnable: true,
debugMode: true,
});
```

### Sending custom events to Google Analytics

You can easily send custom events to Google Analytics by injecting the `gtag` service, and
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-cli-google-analytics/addon/services/gtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class GtagService extends Service {
const {
measurementId = options.measurementId,
forceEnable = options.forceEnable,
debugMode = options.debugMode,
} = get (ENV, 'ember-cli-google.analytics') || {};

if (ENV.environment === 'production' || forceEnable) {
Expand All @@ -29,7 +30,7 @@ export default class GtagService extends Service {
await this.script.load(`https://www.googletagmanager.com/gtag/js?id=${measurementId}`);

this.push('js', new Date());
this.push('config', measurementId);
this.push('config', measurementId, { debug_mode: !!debugMode });
}
}

Expand Down