12345678910111213141516171819202122232425262728293031 |
- export default function (c, i) {
- const { app, $auth, store } = c;
- window._hmt = window._hmt || [];
- window._hmt.push(['_setAutoPageview', false]);
- window._hmt.push(['_setCustomVar', 1, 'MODE', process.env.MODE, 1]);
- app.router.afterEach((to, from) => {
- // 上报PV
- window._hmt.push(['_trackPageview', to.fullPath]);
- });
- app.head.script = app.head.script || [];
- app.head.script.push({
- src: `https://hm.baidu.com/hm.js?${process.env.BAIDU_TONGJI_KEY}`,
- id: 'baidu-tongji',
- });
- // $auth.
- const setUserId = () => {
- window._hmt.push(['_setCustomVar', 2, 'userId', $auth.user?.id ?? 0, 2]);
- };
- store.watch(
- (state, getter) => {
- return $auth.user;
- },
- (user) => setUserId,
- {},
- );
- setUserId();
- }
|