using gtag.js to send data from your site to Google Analytics.
Using npm:
$ npm install -D umi-plugin-gtag
or using yarn:
$ yarn add --dev umi-plugin-gtag
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;
- Type:
string
- Type:
string
MIT