feat: 添加神策数据统计SDK及相关插件
This commit is contained in:
45
src/main.ts
45
src/main.ts
@@ -1,7 +1,7 @@
|
|||||||
import 'amfe-flexible';
|
import 'amfe-flexible';
|
||||||
import 'core-js/stable';
|
import 'core-js/stable';
|
||||||
import 'regenerator-runtime/runtime';
|
import 'regenerator-runtime/runtime';
|
||||||
import { createApp } from 'vue';
|
import { createApp, inject } from 'vue';
|
||||||
import { createPinia } from 'pinia';
|
import { createPinia } from 'pinia';
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import router from './router';
|
import router from './router';
|
||||||
@@ -16,6 +16,7 @@ import 'swiper/css';
|
|||||||
import 'swiper/css/navigation';
|
import 'swiper/css/navigation';
|
||||||
import 'swiper/css/pagination';
|
import 'swiper/css/pagination';
|
||||||
import { sensorsData } from './utils/plugins/sa';
|
import { sensorsData } from './utils/plugins/sa';
|
||||||
|
import { isCollectUrl } from './utils/url/tools';
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
@@ -30,12 +31,31 @@ declare global {
|
|||||||
appBridge?: any;
|
appBridge?: any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 页面停留时间
|
||||||
|
let pageStayTime = 0;
|
||||||
|
|
||||||
// 定义路由是否可以返回的判断
|
// 定义路由是否可以返回的判断
|
||||||
const routerCanGoBack = () => {
|
const routerCanGoBack = () => {
|
||||||
const position = router.options.history.state?.position;
|
const position = router.options.history.state?.position;
|
||||||
return typeof position === 'number' && position > 0;
|
return typeof position === 'number' && position > 0;
|
||||||
};
|
};
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
|
// 离开页面的时候结束记录时间
|
||||||
|
const duration = Date.now() - pageStayTime;
|
||||||
|
pageStayTime = 0;
|
||||||
|
|
||||||
|
const collectUrl = ['/ad/', '/share/'];
|
||||||
|
console.log(`is collect page`, collectUrl.some((url) => from.path.startsWith(url)));
|
||||||
|
|
||||||
|
// 判断是否离开需要采集的页面
|
||||||
|
if (collectUrl.some((url) => from.path.startsWith(url))) {
|
||||||
|
// alert(`duration: ${duration}`);
|
||||||
|
const sensors = inject<any>('sensors');
|
||||||
|
sensors.track('pageStayTime', {
|
||||||
|
duration
|
||||||
|
});
|
||||||
|
}
|
||||||
if (to.meta?.title) document.title = to.meta.title as string;
|
if (to.meta?.title) document.title = to.meta.title as string;
|
||||||
|
|
||||||
if (to.query.digitalYiliToken) {
|
if (to.query.digitalYiliToken) {
|
||||||
@@ -52,6 +72,12 @@ router.beforeEach((to, from, next) => {
|
|||||||
};
|
};
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.afterEach((to, from) => {
|
||||||
|
// 页面导航结束的时候开始记录时间
|
||||||
|
pageStayTime = Date.now();
|
||||||
|
|
||||||
|
});
|
||||||
app.use(createPinia());
|
app.use(createPinia());
|
||||||
app.use(router);
|
app.use(router);
|
||||||
// 神策数据插件
|
// 神策数据插件
|
||||||
@@ -63,22 +89,21 @@ app.use(sensorsData(), {
|
|||||||
scrollmap: {
|
scrollmap: {
|
||||||
// Web 视区停留
|
// Web 视区停留
|
||||||
collect_url: function () {
|
collect_url: function () {
|
||||||
// 根据不同的页面采集不同的数据
|
// 需要采集的页面
|
||||||
if (location.href.includes('/ad/')) {
|
const urls = ['/ad/', '/share/'];
|
||||||
console.log('采集广告页面');
|
console.log(`collect_url`, isCollectUrl(urls));
|
||||||
|
|
||||||
return true;
|
return isCollectUrl(urls);
|
||||||
}
|
|
||||||
console.log('不采集');
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
heatmap: {
|
heatmap: {
|
||||||
//是否开启触达图,default 表示开启,自动采集 $WebStay 事件,可以设置 'not_collect' 表示关闭。
|
//是否开启触达图,default 表示开启,自动采集 $WebStay 事件,可以设置 'not_collect' 表示关闭。
|
||||||
//需要 Web JS SDK 版本号大于 1.9.1
|
//需要 Web JS SDK 版本号大于 1.9.1
|
||||||
scroll_notice_map: 'not_collect',
|
scroll_notice_map: 'default',
|
||||||
scroll_delay_time: 4000,
|
scroll_delay_time: 4000,
|
||||||
scroll_event_duration: 18000 //单位秒,预置属性停留时长 event_duration 的最大值。默认5个小时,也就是300分钟,18000秒。
|
//单位秒,预置属性停留时长 event_duration 的最大值。默认5个小时,也就是300分钟,18000秒。
|
||||||
|
scroll_event_duration: 18000,
|
||||||
|
get_vtrack_config: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export function sensorsData() {
|
|||||||
|
|
||||||
// 注册公共属性
|
// 注册公共属性
|
||||||
sensors.registerPage({
|
sensors.registerPage({
|
||||||
|
platform: 'h5',
|
||||||
current_url: location.href,
|
current_url: location.href,
|
||||||
referrer: document.referrer
|
referrer: document.referrer
|
||||||
});
|
});
|
||||||
|
|||||||
3
src/utils/url/tools.ts
Normal file
3
src/utils/url/tools.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function isCollectUrl(urls: string[]) {
|
||||||
|
return urls.some((url) => location.href.includes(url));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user