Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nuxt-community/google-analytics-module
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.0
Choose a base ref
...
head repository: nuxt-community/google-analytics-module
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.2.1
Choose a head ref
  • 10 commits
  • 26 files changed
  • 6 contributors

Commits on Mar 20, 2019

  1. Copy the full SHA
    909a21a View commit details

Commits on Mar 23, 2019

  1. Copy the full SHA
    d1683ba View commit details

Commits on May 22, 2019

  1. chore(deps): update dependency vue-analytics to ^5.16.4 (#46)

    renovate[bot] authored and Pooya Parsa committed May 22, 2019
    Copy the full SHA
    49a0b06 View commit details
  2. chore: renew yarn.lock

    pooya parsa committed May 22, 2019
    Copy the full SHA
    9678194 View commit details

Commits on Jul 23, 2019

  1. Copy the full SHA
    58d9248 View commit details

Commits on Oct 25, 2019

  1. Copy the full SHA
    0871f84 View commit details
  2. chore: update module (#64)

    * style: formatting
    
    * chore: remove babel
    
    * chore: update deps
    
    * test: refactor
    
    * chore: update yarn.lock
    
    * docs: recommend buildModules and update badges
    ricardogobbosouza authored and pi0 committed Oct 25, 2019
    Copy the full SHA
    e18aae2 View commit details
  3. docs: fix badges

    ricardogobbosouza authored and pi0 committed Oct 25, 2019
    Copy the full SHA
    711e11f View commit details
  4. chore: update vue-analytics (#65)

    ricardogobbosouza authored and pi0 committed Oct 25, 2019
    Copy the full SHA
    9675d42 View commit details
  5. chore(release): 2.2.1

    pi0 committed Oct 25, 2019
    Copy the full SHA
    48cc7d7 View commit details
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
},
extends: [
'@nuxtjs'
]
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
IMPORTANT: Please use the following link to create a new issue:
https://nuxtjs.cmty.io/issues/new
https://cmty.app/nuxt/issues/new?repo=analytics-module
If your issue was not created using the app above, it will be closed immediately.
-->
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Change Log
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [2.2.1](https://github.com/nuxt-community/analytics-module/compare/v2.2.0...v2.2.1) (2019-10-25)


### Bug Fixes

* send hits in production mode by default ([#60](https://github.com/nuxt-community/analytics-module/issues/60)) ([0871f84](https://github.com/nuxt-community/analytics-module/commit/0871f848051ce8f5646493552c405b0c4dd44e0a))

<a name="2.2.0"></a>
# [2.2.0](https://github.com/nuxt-community/analytics-module/compare/v2.1.0...v2.2.0) (2019-03-08)

50 changes: 29 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,22 +4,27 @@
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Circle CI][circle-ci-src]][circle-ci-href]
[![Codecov][codecov-src]][codecov-href]
[![Dependencies][david-dm-src]][david-dm-href]
[![Standard JS][standard-js-src]][standard-js-href]
[![License][license-src]][license-href]

> Google Analytics integration for Nuxt.js with [vue-analytics](https://github.com/MatteoGabriele/vue-analytics)
[📖 **Release Notes**](./CHANGELOG.md)

## Setup

1. Add the `@nuxtjs/google-analytics` dependency with `yarn` or `npm` to your project
2. Add `@nuxtjs/google-analytics` to the `modules` section of `nuxt.config.js`:
3. Configure it:
1. Add `@nuxtjs/google-analytics` dependency to your project

```bash
yarn add --dev @nuxtjs/google-analytics # or npm install --save-dev @nuxtjs/google-analytics
```

2. Add `@nuxtjs/google-analytics` to the `buildModules` section of `nuxt.config.js`

:warning: If you are using Nuxt older than **v2.9** you have to install module as a `dependency` (No `--dev` or `--save-dev` flags) and also use `modules` section in `nuxt.config.js` instead of `buildModules`.

```js
{
modules: [
export default {
buildModules: [
['@nuxtjs/google-analytics', {
id: 'UA-12301-2'
}]
@@ -30,11 +35,10 @@
### Using top level options

```js
{
modules: [
export default {
buildModules: [
'@nuxtjs/google-analytics'
],

googleAnalytics: {
id: 'UA-12301-2'
}
@@ -50,12 +54,14 @@ Differences between vue-analytics and the Nuxt.js implementation:
- 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)
- The `id` and `ua` properties have the exact same behaviour. The `ua` property has been added for backwards compatibily with previous releases
- You can disable module for `nuxt dev` by setting `dev: false` option in module options
- 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 `nuxt.config.js`:

## Development

1. Clone this repository
2. Install dependencies using `yarn install` or `npm install`
3. Start development server using `npm run dev`
```js
debug: {
enabled: true,
sendHitTask: true
}
```

## License

@@ -64,15 +70,17 @@ Differences between vue-analytics and the Nuxt.js implementation:
Copyright (c) - Matteo Gabriele <m.gabriele.dev@gmail.com>

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/dt/@nuxtjs/google-analytics.svg?style=flat-square
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/google-analytics/latest.svg?style=flat-square
[npm-version-href]: https://npmjs.com/package/@nuxtjs/google-analytics
[npm-downloads-src]: https://img.shields.io/npm/v/@nuxtjs/google-analytics/latest.svg?style=flat-square

[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/google-analytics.svg?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/google-analytics

[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/analytics-module.svg?style=flat-square
[circle-ci-href]: https://circleci.com/gh/nuxt-community/analytics-module

[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/analytics-module.svg?style=flat-square
[codecov-href]: https://codecov.io/gh/nuxt-community/analytics-module
[david-dm-src]: https://david-dm.org/nuxt-community/analytics-module/status.svg?style=flat-square
[david-dm-href]: https://david-dm.org/nuxt-community/analytics-module
[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square
[standard-js-href]: https://standardjs.com

[license-src]: https://img.shields.io/npm/l/@nuxtjs/google-analytics.svg?style=flat-square
[license-href]: https://npmjs.com/package/@nuxtjs/google-analytics
11 changes: 0 additions & 11 deletions babel.config.js

This file was deleted.

18 changes: 3 additions & 15 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
module.exports = {
testEnvironment: 'node',
forceExit: true,
collectCoverage: true,
collectCoverageFrom: [
'lib/**/*.js',
'!lib/plugin.js'
],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/lib/$1',
'^~~$': '<rootDir>',
'^@@$': '<rootDir>',
'^@/(.*)$': '<rootDir>/lib/$1'
},
transform: {
'^.+\\.js$': 'babel-jest'
}
collectCoverageFrom: ['lib/**/*.js', '!lib/plugin.js'],
forceExit: true,
testEnvironment: 'node'
}
8 changes: 4 additions & 4 deletions lib/module.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { resolve } = require('path')

function analyticsModule(moduleOptions) {
function analyticsModule (moduleOptions) {
const options = {
dev: true,
debug: {
sendHitTask: undefined
sendHitTask: this.options.dev ? undefined : true
},
...this.options['google-analytics'],
...this.options.googleAnalytics,
@@ -30,10 +30,10 @@ function analyticsModule(moduleOptions) {
}

this.addPlugin({
ssr: false,
src: resolve(__dirname, 'plugin.js'),
fileName: 'google-analytics.js',
options,
ssr: false
options
})
}

40 changes: 13 additions & 27 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
{
"name": "@nuxtjs/google-analytics",
"version": "2.2.0",
"version": "2.2.1",
"description": "Google Analytics Module for Nuxt.js",
"repository": "https://github.com/nuxt-community/analytics-module",
"license": "MIT",
"contributors": [
"Matteo Gabriele <m.gabriele.dev@gmail.com>"
],
"main": "lib/module.js",
"repository": "https://github.com/nuxt-community/analytics-module",
"publishConfig": {
"access": "public"
},
"scripts": {
"dev": "nuxt test/fixture",
"lint": "eslint lib test",
"test": "yarn lint && jest",
"release": "yarn test && standard-version && git push --follow-tags && npm publish"
},
"files": [
"lib"
],
"main": "lib/module.js",
"scripts": {
"lint": "eslint --ext .js,.vue .",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && jest"
},
"dependencies": {
"vue-analytics": "^5.16.2"
"vue-analytics": "^5.17.2"
},
"devDependencies": {
"@babel/core": "latest",
"@babel/preset-env": "latest",
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@nuxtjs/eslint-config": "latest",
"babel-eslint": "latest",
"babel-jest": "latest",
"@nuxtjs/module-test-utils": "latest",
"codecov": "latest",
"eslint": "latest",
"eslint-config-standard": "latest",
"eslint-plugin-import": "latest",
"eslint-plugin-jest": "latest",
"eslint-plugin-node": "latest",
"eslint-plugin-promise": "latest",
"eslint-plugin-standard": "latest",
"eslint-plugin-vue": "latest",
"get-port": "latest",
"husky": "latest",
"jest": "latest",
"nuxt-edge": "latest",
"request": "latest",
"request-promise-native": "latest",
"standard-version": "latest"
},
"publishConfig": {
"access": "public"
}
}
36 changes: 36 additions & 0 deletions test/dev.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { setup, loadConfig, get, url } = require('@nuxtjs/module-test-utils')

describe('dev', () => {
let nuxt, addTemplate

beforeAll(async () => {
const beforeNuxtReady = (nuxt) => {
addTemplate = nuxt.moduleContainer.addTemplate = jest.fn(
nuxt.moduleContainer.addTemplate
)
}
({ nuxt } = (await setup(loadConfig(__dirname, 'dev'), { waitFor: 2000, beforeNuxtReady })))
}, 60000)

afterAll(async () => {
await nuxt.close()
})

test('render', async () => {
const html = await get('/')
expect(html).toContain('Works!')
})

test('$ga should be defined', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
expect(window.$nuxt.$ga).toBeDefined()
})

test('option id', () => {
expect(addTemplate).toBeDefined()
const call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
expect(call).toBeDefined()
const options = call[0].options
expect(options.id).toBe('UA-XXX')
})
})
36 changes: 36 additions & 0 deletions test/disabled-send-hit-task.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { setup, loadConfig, get, url } = require('@nuxtjs/module-test-utils')

describe('disabled sendHitTask', () => {
let nuxt, addTemplate

beforeAll(async () => {
const beforeNuxtReady = (nuxt) => {
addTemplate = nuxt.moduleContainer.addTemplate = jest.fn(
nuxt.moduleContainer.addTemplate
)
}
({ nuxt } = (await setup(loadConfig(__dirname, 'disabled-send-hit-task'), { waitFor: 2000, beforeNuxtReady })))
}, 60000)

afterAll(async () => {
await nuxt.close()
})

test('render', async () => {
const html = await get('/')
expect(html).toContain('Works!')
})

test('$ga should be defined', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
expect(window.$nuxt.$ga).toBeDefined()
})

test('sendHitTask should be false', () => {
expect(addTemplate).toBeDefined()
const call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
expect(call).toBeDefined()
const options = call[0].options
expect(options.debug.sendHitTask).toBe(false)
})
})
34 changes: 34 additions & 0 deletions test/disabled.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { setup, loadConfig, get, url } = require('@nuxtjs/module-test-utils')

describe('disabled', () => {
let nuxt, addTemplate

beforeAll(async () => {
const beforeNuxtReady = (nuxt) => {
addTemplate = nuxt.moduleContainer.addTemplate = jest.fn(
nuxt.moduleContainer.addTemplate
)
}
({ nuxt } = (await setup(loadConfig(__dirname, 'disabled'), { waitFor: 2000, beforeNuxtReady })))
}, 60000)

afterAll(async () => {
await nuxt.close()
})

test('render', async () => {
const html = await get('/')
expect(html).toContain('Works!')
})

test('$ga should be undefined', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
expect(window.$nuxt.$ga).toBeUndefined()
})

test('plugin should be undefined', () => {
expect(addTemplate).toBeDefined()
const call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
expect(call).toBeUndefined()
})
})
13 changes: 13 additions & 0 deletions test/fixture/dev/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
dev: true,
rootDir: __dirname,
render: {
resourceHints: false
},
buildModules: [
{ handler: require('../../../') }
],
googleAnalytics: {
id: 'UA-XXX'
}
}
File renamed without changes.
16 changes: 16 additions & 0 deletions test/fixture/disabled-send-hit-task/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
dev: true,
rootDir: __dirname,
render: {
resourceHints: false
},
buildModules: [
{ handler: require('../../../') }
],
googleAnalytics: {
id: 'UA-XXX',
debug: {
sendHitTask: false
}
}
}
Loading