Skip to content

dankerow/yandex-metrika-module

 
 

Repository files navigation

Yandex Metrika

npm version npm downloads License

Add Yandex Metrika to your Nuxt application.

This plugin automatically sends first page and route change events to Yandex Metrika.

Note: Yandex Metrika is not enabled in dev mode. You can set environment variable NODE_ENV to production for testing in dev mode.

Setup

  • Add @nuxtjs/yandex-metrika dependency to your project
  • Add @nuxtjs/yandex-metrika to modules section of nuxt.config.js
{
  modules: ['@nuxtjs/yandex-metrika']
}

Configure

You can pass options directly in module declaration:

{
  modules: [
    [
      '@nuxtjs/yandex-metrika',
      {
        id: 'XXXXXX',
        webvisor: true,
        // clickmap: true,
        // useCDN: false,
        // trackLinks: true,
        // accurateTrackBounce: true,
      }
    ]
  ]
}

Or you can specify yandexMetrika key:

{
  modules: ['@nuxtjs/yandex-metrika'],
  yandexMetrika: {
    id: 'XXXXXX',
    // ...
  }
}

In Nuxt 2.13+, you can also use public runtime config:

{
  modules: ['@nuxtjs/yandex-metrika'],
  publicRuntimeConfig: {
    yandexMetrika: {
      id: process.env.YANDEX_METRIKA_ID,
      // ...
    }
  }
}

Options

For more information:

Name Default value Type Description
accurateTrackBounce true Boolean Number
childIframe false Boolean Whether to record iframe contents without a tag in a child window
clickmap true Boolean Whether to collect data for a click map
defer false Boolean Whether to disable automatically sending data during tag initialization
ecommerce false Boolean String
params Object Array
userParams Object Parameters of site users that are transmitted when initializing the tag To transmit user parameters at any other time, use the userParams method
trackHash false Boolean Hash tracking in the browser's address bar
trackLinks true Boolean Track clicks on outbound links
trustedDomains Array Indicates a trusted domain for recording the contents of a child iframe. Contains the domain address of the parent window
type 0 Number Tag type. 1 for YAN
webvisor false Boolean Whether to use Session Replay
triggerEvent false Boolean Whether to check if the tag is ready

Development

  • Clone this repository
  • Install dependencies using pnpm install
  • Run pnpm dev:prepare to generate type stubs.
  • Use pnpm dev to start playground in development mode.

License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 83.2%
  • Vue 16.8%