umi-plugin-gtag
v1.0.2
Published
using gtag.js to send data from your site to Google Analytics.
Downloads
4
Readme
umi-plugin-gtag
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