Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More →
Socket
Sign inDemoInstall
Socket

@nuxtjs/gtm

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/gtm - npm Package Compare versions

Comparing version 2.3.2 to 2.4.0

lib/plugin.utils.js

16

CHANGELOG.md

@@ -5,2 +5,18 @@ # Changelog

## [2.4.0](https://github.com/nuxt-community/gtm-module/compare/v2.3.2...v2.4.0) (2020-11-10)
### Features
* support `crossOrigin` option ([#78](https://github.com/nuxt-community/gtm-module/issues/78)) ([e843176](https://github.com/nuxt-community/gtm-module/commit/e8431767b72e63d67968d811fe5919011b441f57))
* **module:** add support for runtimeConfig ([#53](https://github.com/nuxt-community/gtm-module/issues/53)) ([2bc1735](https://github.com/nuxt-community/gtm-module/commit/2bc173538ea255deea13ad575fefc82b7a28e3f0))
* **plugin:** add `debug` option and disable by default ([#61](https://github.com/nuxt-community/gtm-module/issues/61)) ([37f13e5](https://github.com/nuxt-community/gtm-module/commit/37f13e551518efa5aa88c095a544a73c8ac5fc9b))
### Bug Fixes
* **plugin.mock:** handle `event.eventCallback` ([#76](https://github.com/nuxt-community/gtm-module/issues/76)) ([cdb0c5c](https://github.com/nuxt-community/gtm-module/commit/cdb0c5c3a5ce07ca3cadcafa673b0397f31dfc75))
* fix doNotTrack polyfill ([#87](https://github.com/nuxt-community/gtm-module/issues/87)) ([c69d1cf](https://github.com/nuxt-community/gtm-module/commit/c69d1cf87179ad77a245fb7a745731ce666630bf))
* **module:** allow client side push before init ([#60](https://github.com/nuxt-community/gtm-module/issues/60)) ([c9b073a](https://github.com/nuxt-community/gtm-module/commit/c9b073a9c9f84ccb5271fb70fc602b1fe6f187c4))
### [2.3.2](https://github.com/nuxt-community/gtm-module/compare/v2.3.1...v2.3.2) (2020-07-23)

@@ -7,0 +23,0 @@

0

lib/compatibility.js

@@ -0,0 +0,0 @@ const chalk = require('chalk')

const defaults = {
enabled: undefined,
debug: false,

@@ -17,2 +18,3 @@ id: undefined,

scriptURL: 'https://www.googletagmanager.com/gtm.js',
crossOrigin: false,

@@ -19,0 +21,0 @@ noscript: true,

15

lib/module.js

@@ -7,3 +7,3 @@ const path = require('path')

// https://gist.github.com/pi0/a76fd97c4ea259c89f728a4a8ebca741
const dnt = "(function(w,n,d,m,e,p){w[d]=(w[d]==1||n[d]=='yes'||n[d]==1||n[m]==1||(w[e]&&w[e].p&&e[e][p]()))?1:0})(window,'navigator','doNotTrack','msDoNotTrack','external','msTrackingProtectionEnabled')"
const dnt = "(function(w,n,d,m,e,p){w[d]=(w[d]==1||n[d]=='yes'||n[d]==1||n[m]==1||(w[e]&&w[e][p]&&w[e][p]()))?1:0})(window,navigator,'doNotTrack','msDoNotTrack','external','msTrackingProtectionEnabled')"

@@ -33,2 +33,8 @@ module.exports = async function gtmModule (_options) {

this.addTemplate({
src: path.resolve(__dirname, 'plugin.utils.js'),
fileName: 'gtm.utils.js',
options
})
if (!options.enabled) {

@@ -61,9 +67,8 @@ // Register mock plugin

// Compile scripts
const initLayer = "w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'})" // deps: w,l
const injectScript = `var f=d.getElementsByTagName(s)[0],j=d.createElement(s);${options.crossOrigin ? 'j.crossOrigin=\'' + options.crossOrigin + '\';' : ''}j.${options.scriptDefer ? 'defer' : 'async'}=true;j.src='${options.scriptURL + '?id=\'+i' + (queryString ? (`+'&${queryString}` + '\'') : '')};f.parentNode.insertBefore(j,f)` // deps: d,s,i
const injectScript = `var f=d.getElementsByTagName(s)[0],j=d.createElement(s);j.${options.scriptDefer ? 'defer' : 'async'}=true;j.src='${options.scriptURL + '?id=\'+i' + (queryString ? (`+'&${queryString}` + '\'') : '')};f.parentNode.insertBefore(j,f)` // deps: d,s,i
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};}`
const initLayer = "w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'})" // deps: w,l
let script = `w[x]={};w._gtm_inject=function(i){${doNotTrackScript}w[x][i]=1;${initLayer};${injectScript};}`

@@ -70,0 +75,0 @@ if (options.autoInit && options.id) {

@@ -0,1 +1,3 @@

import { log } from './gtm.utils'
const _layer = '<%= options.layer %>'

@@ -12,2 +14,3 @@ const _id = '<%= options.id %>'

initialized[id] = true
log('init', id)
},

@@ -19,2 +22,3 @@ push(obj) {

window[_layer].push(obj)
log('push', obj)
}

@@ -55,5 +59,7 @@ }

initialized[id] = true
log('init', id)
},
push(obj) {
events.push(obj)
log('push', JSON.stringify(obj))
}

@@ -78,6 +84,14 @@ }

export default function (ctx, inject) {
const initialized = {<%= (options.autoInit && options.id) ? ` '${options.id}': true ` : '' %>}
ctx.$gtm = process.client ? gtmClient(ctx, initialized) : gtmServer(ctx, initialized)
const runtimeConfig = (ctx.$config && ctx.$config.gtm) || {}
const autoInit = <%= options.autoInit %>
const id = '<%= options.id %>'
const runtimeId = runtimeConfig.id
const initialized = autoInit && id ? {[id]: true} : {}
const $gtm = process.client ? gtmClient(ctx, initialized) : gtmServer(ctx, initialized)
if (autoInit && runtimeId && runtimeId !== id) {
$gtm.init(runtimeId)
}
ctx.$gtm = $gtm
inject('gtm', ctx.$gtm)
<% if (options.pageTracking) { %>if (process.client) { startPageTracking(ctx); }<% } %>
}
// This is a mock version because gtm module is disabled
// You can explicitly enable module using `gtm.enabled: true` in nuxt.config
import { log } from './gtm.utils'

@@ -22,6 +23,3 @@ const _layer = '<%= options.layer %>'

export default function (ctx, inject) {
// eslint-disable-next-line no-console
const logSyle = 'background: #2E495E;border-radius: 0.5em;color: white;font-weight: bold;padding: 2px 0.5em;'
const log = (...args) => console.log('%cGTM', logSyle, ...args)
log('Using mocked API. Real GTM events will not be reported.')
const gtm = {

@@ -33,2 +31,5 @@ init: (id) => {

log('push', process.client ? event : JSON.stringify(event))
if (typeof event.eventCallback === 'function') {
event.eventCallback()
}
}

@@ -35,0 +36,0 @@ }

{
"name": "@nuxtjs/gtm",
"version": "2.3.2",
"version": "2.4.0",
"description": "Google Tag Manager Module for Nuxt.js",

@@ -5,0 +5,0 @@ "repository": "nuxt-community/gtm-module",

@@ -35,3 +35,24 @@ # @nuxtjs/gtm

```
### Runtime Config
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.
```js
export default {
modules: [
'@nuxtjs/gtm'
],
gtm: {
id: 'GTM-XXXXXXX', // Used as fallback if no runtime config is provided
},
publicRuntimeConfig: {
gtm: {
id: process.env.GOOGLE_TAG_MANAGER_ID
}
},
}
```
## Options

@@ -45,2 +66,3 @@

enabled: undefined, /* see below */
debug: false,

@@ -60,2 +82,3 @@ id: undefined,

scriptURL: 'https://www.googletagmanager.com/gtm.js',
crossOrigin: false,

@@ -84,2 +107,6 @@ noscript: true,

### `debug`
Whether `$gtm` API calls like `init` and `push` are logged to the console.
### Manual GTM Initialization

@@ -86,0 +113,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡ī¸ by Socket Inc