包详细信息

@nuxtjs/google-tag-manager

nuxt-community25.3kMIT不推荐使用2.3.2

自述文件

Google Tag Manager

npm npm (scoped with tag)

Add Google Tag Manager (GTM) to your nuxt.js application. This plugins automatically sends first page and route change events to GTM.

Setup

  • Add @nuxtjs/google-tag-manager dependency using yarn or npm to your project
  • Add @nuxtjs/google-tag-manager to modules section of nuxt.config.js
    modules: [
     ['@nuxtjs/google-tag-manager', { id: 'GTM-XXXXXXX' }],
    ]
    

Options

id

  • Required
  • Can be String in form of GTM-XXXXXXX
  • Can be function returning Promise or String: ```js // Returns Promise id: () => { return axios.get('http://example.com/') .then(({ data }) => {
    return data.gtm_id
    
    }) }

// Returns String const code = '1234567' id: () => { return 'GTM-' + code }


### All options
```js
{
  id: 'GTM-XXXXXXX',
  layer: 'dataLayer',
  pageTracking: false,
  pageViewEventName: 'nuxtRoute',
  respectDoNotTrack: false,
  dev: true, // set to false to disable in dev mode
  query: {
    // query params...
    gtm_auth:        '...',
    gtm_preview:     '...',
    gtm_cookies_win: '...'
  },
  scriptURL: '//example.com',
  noscriptURL: '//example.com'
}

Router Integration

You can optionally set pageTracking option to true to track page views.

This is disabled by default to prevent double events when using alongside with Google Analytics so take care before enabling this option.

The default event name for page views is "nuxtRoute", you can change it by setting the pageViewEventName option.

Usage

Pushing events

You can push events into the configured layer:

this.$gtm.pushEvent({ event: 'myEvent', ...someAttributes })

更新日志

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.1 (2019-11-01)

Bug Fixes

  • google-tag-manager: fixed noscript content sanitization (#322) (7531faf)

2.3.0 (2019-10-07)

Features

  • google-tag-manager: add <noscript> fallback (#263) (#300) (f0dd65f)
  • google-tag-manager: add pageViewEventName option (#314) (f718a6a)

2.2.1 (2019-07-13)

Bug Fixes

  • google-tag-manager: fix respectDoNotTrack (#295) (56cb078)

2.2.0 (2019-04-15)

Features

  • google-tag-manager: refactor, dev option and $gtm.pushEvent (#274) (d0ba40f)

2.1.4 (2019-02-12)

Bug Fixes

  • google-tag-manager: fix broken syntax (#262) (0e9e552)

2.1.3 (2019-02-12)

Note: Version bump only for package @nuxtjs/google-tag-manager

2.1.2 (2019-01-11)

Note: Version bump only for package @nuxtjs/google-tag-manager

2.1.1 (2018-12-19)

Bug Fixes

  • google-tag-manager: delay for route changing before send (#221) (a7e1634)

2.1.0 (2018-10-01)

Features

  • google-tag-manager: Allow GTM ID to be function (#219) (e4bf538)

2.0.0 (2018-05-15)

Features

  • google-tag-manager: rework on options and customization (50c1f27)

BREAKING CHANGES

  • google-tag-manager: pageTracking is disabled by default

1.2.0 (2018-04-27)

Features

1.1.0 (2017-11-20)

Features

  • google-tag-manager: removed lodash dependency (#160) (3c5f674)

1.0.1 (2017-07-24)

Bug Fixes

  • google-tag-manager: default 'layer' should be set to 'dataLayer' (#82) (1ed8b76)

0.0.5 (2017-06-06)

0.0.4 (2017-06-02)

0.0.3 (2017-05-31)

0.0.2 (2017-05-30)

0.0.1 (2017-05-29)