|
1 | | -# Google Analytics |
| 1 | +# @nuxtjs/google-analytics |
| 2 | + |
| 3 | +[](https://google-analytics.nuxtjs.org) |
2 | 4 |
|
3 | 5 | [![npm version][npm-version-src]][npm-version-href] |
4 | 6 | [![npm downloads][npm-downloads-src]][npm-downloads-href] |
5 | 7 | [![Github Actions CI][github-actions-ci-src]][github-actions-ci-href] |
6 | 8 | [![Codecov][codecov-src]][codecov-href] |
7 | 9 | [![License][license-src]][license-href] |
8 | 10 |
|
9 | | -> Google Analytics integration for Nuxt.js with [vue-analytics](https://github.com/MatteoGabriele/vue-analytics) |
10 | | -
|
11 | | -[📖 **Release Notes**](./CHANGELOG.md) |
12 | | - |
13 | | -## Setup |
14 | | - |
15 | | -1. Add `@nuxtjs/google-analytics` dependency to your project |
16 | | - |
17 | | -```bash |
18 | | -yarn add --dev @nuxtjs/google-analytics # or npm install --save-dev @nuxtjs/google-analytics |
19 | | -``` |
20 | | - |
21 | | -2. Add `@nuxtjs/google-analytics` to the `buildModules` section of `nuxt.config.js` |
22 | | - |
23 | | -```js |
24 | | -export default { |
25 | | - buildModules: [ |
26 | | - ['@nuxtjs/google-analytics', { |
27 | | - id: 'UA-12301-2' |
28 | | - }] |
29 | | - ] |
30 | | -} |
31 | | -``` |
32 | | - |
33 | | -:warning: If you are using Nuxt **< v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`. |
34 | | - |
35 | | -### Using top level options |
36 | | - |
37 | | -```js |
38 | | -export default { |
39 | | - buildModules: [ |
40 | | - '@nuxtjs/google-analytics' |
41 | | - ], |
42 | | - googleAnalytics: { |
43 | | - id: 'UA-12301-2' |
44 | | - } |
45 | | -} |
46 | | -``` |
47 | | - |
48 | | -### Runtime Config |
49 | | - |
50 | | -You can use [runtime config](https://nuxtjs.org/guide/runtime-config) if need to use dynamic environment variables in production. Otherwise, the options will be hardcoded during the build and won't be read from `nuxt.config` anymore. |
51 | | - |
52 | | -```js |
53 | | -export default { |
54 | | - buildModules: [ |
55 | | - '@nuxtjs/google-analytics' |
56 | | - ], |
57 | | - |
58 | | - googleAnalytics: { |
59 | | - id: 'UA-12301-2', // Used as fallback if no runtime config is provided |
60 | | - }, |
61 | | - |
62 | | - publicRuntimeConfig: { |
63 | | - googleAnalytics: { |
64 | | - id: process.env.GOOGLE_ANALYTICS_ID |
65 | | - } |
66 | | - }, |
67 | | -} |
68 | | -``` |
69 | | - |
70 | | -## Usage |
| 11 | +> [Google Analytics](https://analytics.google.com/analytics/web/) integration for [Nuxt](https://nuxtjs.org) using [vue-analytics](https://github.com/MatteoGabriele/vue-analytics). |
71 | 12 |
|
72 | | -Click [here](https://matteogabriele.gitbooks.io/vue-analytics/) for all options and features of vue-analytics |
| 13 | +[✨ Release Notes](./CHANGELOG.md) |
| 14 | +[📖 Documentation](https://google-analytics.nuxtjs.org) |
73 | 15 |
|
74 | | -Differences between vue-analytics and the Nuxt.js implementation: |
| 16 | +## Features |
75 | 17 |
|
76 | | -- The router instance is already added out of the box (read [here](https://github.com/MatteoGabriele/vue-analytics/blob/master/docs/page-tracking.md#disable-page-auto-tracking) if you need to disable it) |
77 | | -- The `id` and `ua` properties have the exact same behaviour. The `ua` property has been added for backwards compatibily with previous releases |
78 | | -- You can disable module for `nuxt dev` by setting `dev: false` option in module options |
79 | | -- Note: By default, you won't see hits going out in dev mode. For testing analytics in dev mode, you must add the following to the `googleAnalytics` options in `nuxt.config.js`: |
| 18 | +- Automatic page tracking |
| 19 | +- Event batching |
| 20 | +- User timings |
| 21 | +- Screen view |
| 22 | +- Multiple domain ID |
| 23 | +- Automatic Google Analytics script loading |
| 24 | +- E-commerce support |
80 | 25 |
|
81 | | - ```js |
82 | | - debug: { |
83 | | - enabled: true, |
84 | | - sendHitTask: true |
85 | | - } |
86 | | - ``` |
| 26 | +[📖 Read more](https://google-analytics.nuxtjs.org) |
87 | 27 |
|
88 | | -## Development |
| 28 | +## Contributing |
89 | 29 |
|
90 | 30 | 1. Clone this repository |
91 | 31 | 2. Install dependencies using `yarn install` or `npm install` |
|
0 commit comments