# @onehilltech/ember-cli-google-analytics

> The default blueprint for ember-cli addons.

Latest version **2.0.3** (published 2024-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @onehilltech/ember-cli-google-analytics
pnpm add @onehilltech/ember-cli-google-analytics
yarn add @onehilltech/ember-cli-google-analytics
bun add @onehilltech/ember-cli-google-analytics
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2024-04-27 |
| First published | 2018-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 18 |
| Dependencies | 3 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | onehilltech |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/@onehilltech/ember-cli-google-analytics
- npm.io page: https://npm.io/package/@onehilltech/ember-cli-google-analytics

## Dependencies (3)

- [@babel/core](https://npm.io/package/@babel/core.md) ^7.23.6
- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^8.2.0
- [ember-cli-htmlbars](https://npm.io/package/ember-cli-htmlbars.md) ^6.3.0

## Recent versions

- 2.0.3 (latest) — 2024-04-27
- 2.0.2 — 2024-01-30
- 2.0.1 — 2024-01-30
- 1.5.0 — 2022-10-27
- 1.4.1 — 2022-10-26
- 1.4.0 — 2022-10-13
- 1.3.1 — 2022-09-16
- 1.3.0 — 2022-09-16
- 1.2.1 — 2022-09-14
- 1.2.0 — 2021-07-18
- 1.1.0 — 2021-01-11
- 1.0.0 — 2020-11-27
- 0.6.0 — 2020-08-16
- 0.5.0 — 2019-12-22
- 0.4.2 — 2018-12-15
- … 6 more at https://npm.io/package/@onehilltech/ember-cli-google-analytics/versions

## README

# ember-cli-google-analytics

EmberJS add-on for Google Analytics

    ember install @onehilltech/ember-cli-google-analytics

## Compatibility

* Ember.js v4.8 or above
* Ember CLI v4.8 or above
* Node.js v18 or above

## Configuration

After you install this add-on, you only need to add your Google analytics settings
to the `config/environment.js` file for basic usage.

```javascript
// config/environment.js

let ENV = {
  'ember-cli-google': {
    analytics: {
      version: 'v4',
      measurementId: 'G-XXXXXXXXXX'
    }
  }
}
```

## Initialization

Ember 5.x deprecated implicit injections from its initializers. This means you have
to manually initialize Google Analytics in your application. The easiest way to initialize
the add-on is to inject the `gtag` service in the `ApplicationRoute`, and override the
`activate()` method to call `gtag.configure()` as shown below.

> Use the following command to generate the application route: `ember g route application`

```javascript
import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default class ApplicationRoute extends Route {
  @service
  gtag;

  async activate () {
    // Pass control to the base class.
    await super.activate (...arguments);
    
    // Configure Google Analytics for our application.
    await this.gtag.configure ();
  }
}
```

### Sending custom events to Google Analytics

You can easily send custom events to Google Analytics by injecting the `gtag` service, and
calling the `event(name, params)` method. Here is an example of tracking the search term from an input
field.

```javascript
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';

class SearchComponent extends Component {
  // Inject the Google Tag Manager service into our component.
  @service
  gtag;
  
  @action
  searching (ev) {
    const { target } = ev;
    
    // Send an event to Google Analytics.
    this.gtag.event ('searching', { term: target.value } );
  }
}
```

Happy Coding!

---
_Source: https://npm.io/package/@onehilltech/ember-cli-google-analytics · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
