@nuxtjs/gtm
Advanced tools
Comparing version 2.2.3 to 2.3.0
@@ -5,2 +5,15 @@ # Changelog | ||
## [2.3.0](https://github.com/nuxt-community/gtm-module/compare/v2.2.3...v2.3.0) (2020-06-01) | ||
### Features | ||
* require nuxt > 2.12 to avoid ssr memory leak ([43f41c8](https://github.com/nuxt-community/gtm-module/commit/43f41c8e7ce58ca40476cc9624be8464908b2d91)) | ||
* use mock version for nuxt dev ([ec85699](https://github.com/nuxt-community/gtm-module/commit/ec856996a7caa6f6ef0c21c7c03457ec1a27552c)), closes [#32](https://github.com/nuxt-community/gtm-module/issues/32) | ||
### Bug Fixes | ||
* check respectDoNotTrack option value ([#37](https://github.com/nuxt-community/gtm-module/issues/37)) ([b1a938c](https://github.com/nuxt-community/gtm-module/commit/b1a938c44f953bd35f9a00e42189ee0291015d41)) | ||
### [2.2.3](https://github.com/nuxt-community/gtm-module/compare/v2.2.2...v2.2.3) (2020-03-17) | ||
@@ -7,0 +20,0 @@ |
const defaults = { | ||
dev: true, | ||
enabled: undefined, | ||
id: null, | ||
id: undefined, | ||
layer: 'dataLayer', | ||
@@ -6,0 +6,0 @@ variables: {}, |
const path = require('path') | ||
const defaults = require('./defaults') | ||
const { requireNuxtVersion } = require('./compatibility') | ||
@@ -9,2 +10,4 @@ // doNotTrack polyfill | ||
module.exports = async function gtmModule (_options) { | ||
requireNuxtVersion(this.nuxt, '2.12.0') | ||
const options = { | ||
@@ -16,4 +19,23 @@ ...defaults, | ||
// Don't include when run in dev mode unless dev: true is configured | ||
if (this.options.dev && !options.dev) { | ||
// By default enable only for non development | ||
if (options.enabled === undefined) { | ||
options.enabled = !this.options.dev | ||
} | ||
if (options.dev !== undefined) { | ||
// eslint-disable-next-line no-console | ||
console.warn('[gtm] `dev` option is deprecated! Please use `enabled`') | ||
if (options.dev === true && this.options.dev) { | ||
options.enabled = true | ||
} | ||
delete options.dev | ||
} | ||
if (!options.enabled) { | ||
// Register mock plugin | ||
this.addPlugin({ | ||
src: path.resolve(__dirname, 'plugin.mock.js'), | ||
fileName: 'gtm.js', | ||
options | ||
}) | ||
return | ||
@@ -43,4 +65,6 @@ } | ||
let script = `${initLayer};w[x]={};w._gtm_inject=function(i){if(w.doNotTrack||w[x][i])return;w[x][i]=1;${injectScript};}` | ||
const doNotTrackScript = options.respectDoNotTrack ? 'if(w.doNotTrack||w[x][i])return;' : '' | ||
let script = `${initLayer};w[x]={};w._gtm_inject=function(i){${doNotTrackScript}w[x][i]=1;${injectScript};}` | ||
if (options.autoInit && options.id) { | ||
@@ -47,0 +71,0 @@ script += `;w[y]('${options.id}')` |
{ | ||
"name": "@nuxtjs/gtm", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"description": "Google Tag Manager Module for Nuxt.js", | ||
"repository": "nuxt-community/gtm-module", | ||
"license": "MIT", | ||
"contributors": [ | ||
{ | ||
"name": "Pooya Parsa <pyapar@gmail.com>" | ||
} | ||
], | ||
"main": "lib/module.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib/module.js", | ||
"scripts": { | ||
@@ -23,8 +18,9 @@ "dev": "nuxt example", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"chalk": "^4.0.0", | ||
"semver": "^7.3.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "latest", | ||
"@babel/preset-env": "latest", | ||
"@commitlint/cli": "latest", | ||
"@commitlint/config-conventional": "latest", | ||
"@nuxtjs/eslint-config": "latest", | ||
@@ -37,3 +33,2 @@ "@nuxtjs/module-test-utils": "latest", | ||
"eslint": "latest", | ||
"husky": "latest", | ||
"jest": "latest", | ||
@@ -40,0 +35,0 @@ "nuxt-edge": "latest", |
@@ -5,3 +5,3 @@ # @nuxtjs/gtm | ||
[![npm downloads][npm-downloads-src]][npm-downloads-href] | ||
[![Circle CI][circle-ci-src]][circle-ci-href] | ||
[![Checks][checks-src]][checks-href] | ||
[![Codecov][codecov-src]][codecov-href] | ||
@@ -27,3 +27,3 @@ [![License][license-src]][license-href] | ||
```js | ||
{ | ||
export default { | ||
buildModules: [ | ||
@@ -43,33 +43,44 @@ '@nuxtjs/gtm', | ||
```js | ||
{ | ||
// Set to false to disable module in development mode | ||
dev: true, | ||
export default { | ||
gtm: { | ||
enabled: undefined, /* see below */ | ||
id: null, | ||
layer: 'dataLayer', | ||
variables: {}, | ||
id: undefined, | ||
layer: 'dataLayer', | ||
variables: {}, | ||
pageTracking: false, | ||
pageViewEventName: 'nuxtRoute', | ||
pageTracking: false, | ||
pageViewEventName: 'nuxtRoute', | ||
autoInit: true, | ||
respectDoNotTrack: true, | ||
autoInit: true, | ||
respectDoNotTrack: true, | ||
scriptId: 'gtm-script', | ||
scriptDefer: false, | ||
scriptURL: 'https://www.googletagmanager.com/gtm.js', | ||
scriptId: 'gtm-script', | ||
scriptDefer: false, | ||
scriptURL: 'https://www.googletagmanager.com/gtm.js', | ||
noscript: true, | ||
noscriptId: 'gtm-noscript', | ||
noscriptURL: 'https://www.googletagmanager.com/ns.html' | ||
noscript: true, | ||
noscriptId: 'gtm-noscript', | ||
noscriptURL: 'https://www.googletagmanager.com/ns.html' | ||
} | ||
} | ||
``` | ||
### Manual GTM Initialization | ||
### `enabled` | ||
đ¨ IMPORTANT đ¨ | ||
GTM module uses a debug-only version of `$gtm` during development (`nuxt dev`). | ||
There is a known issue with Nuxt < 2.12.0 fixed by nuxt/nuxt.js#6807 which causes shared state and adding multiple tags. | ||
Please use `nuxt-edge` for now if want to use `init` on server-side. | ||
You can explicitly enable or disable it using `enabled` option: | ||
```js | ||
export default { | ||
gtm: { | ||
// Always send real GTM events (also when using `nuxt dev`) | ||
enabled: true | ||
} | ||
} | ||
``` | ||
### Manual GTM Initialization | ||
There are several use cases that you may need more control over initialization: | ||
@@ -143,4 +154,4 @@ | ||
[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/gtm-module.svg?style=flat-square | ||
[circle-ci-href]: https://circleci.com/gh/nuxt-community/gtm-module | ||
[checks-src]: https://img.shields.io/github/workflow/status/nuxt-community/gtm-module/test/master?style=flat-square | ||
[checks-href]: https://github.com/nuxt-community/gtm-module/actions | ||
@@ -147,0 +158,0 @@ [codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/gtm-module.svg?style=flat-square |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24176
12
9
238
159
2
2
+ Addedchalk@^4.0.0
+ Addedsemver@^7.3.2
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsupports-color@7.2.0(transitive)