Skip to content

using gtag.js to send data from your site to Google Analytics.

Notifications You must be signed in to change notification settings

FydeOS/umi-plugin-gtag

 
 

Repository files navigation

umi-plugin-gtag

NPM version NPM downloads

using gtag.js to send data from your site to Google Analytics.

Install

Using npm:

$ npm install -D umi-plugin-gtag

or using yarn:

$ yarn add --dev umi-plugin-gtag

Usage

Configure in .umirc.js,

export default {
  plugins: [['umi-plugin-gtag']],
  gtag: {
    GA_MEASUREMENT_ID: 'UA-xxxxxx-x',
    SEND_DATA_NAME: 'gtagData',
  },
  // 服务端渲染开启 ssr
  // ssr: {},
};

如果想使用 set 设置发送每个事件的相关数据

客户端渲染

window['gtagData'] = {
  user_id: 123,
};

服务端渲染

Home.getInitialProps = (async ctx => {
  console.log(ctx);
  return Promise.resolve({
    gtagData: {
      user_id: 123
    },
    data: {
      title: 'Hello World, Hello Umi!',
    },
  });
}) as IGetInitialProps;

Options

GA_MEASUREMENT_ID

  • Type: string

SEND_DATA_NAME

  • Type: string

LICENSE

MIT

About

using gtag.js to send data from your site to Google Analytics.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 56.1%
  • JavaScript 40.3%
  • CSS 3.6%