Files
ylst-h5/src/utils/plugins/sa.ts
Huangzhe 281fee561c feat(main): 集成神策数据插件
- 在 main.ts 中引入并注册神策数据插件
- 新增 sa.ts 文件实现神策数据插件功能
- 初始化神策数据并配置相关选项
- 在全局属性中添加 $sensorsData
2025-06-04 15:23:11 +08:00

38 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { App } from 'vue';
import sensors from '@/assets/js/sa-sdk-javascript/dist/web/sensorsdata.es6.js';
// 定义神策数据插件选项接口
interface SensorsDataOptions {
// 可以根据需要添加具体的选项属性
[key: string]: any;
}
export function sensorsData() {
return {
install(app: App, options?: SensorsDataOptions) {
// console.log(`sensorsData install`);
sensors.init({
show_log: true,
// server_url: '数据接收地址',
is_track_single_page: true, // 单页面配置,默认关闭。开启后自动监听 URL 有变化就会触发 $pageview 事件
use_client_time: true,
send_type: 'beacon',
heatmap: {
//是否开启点击图default 表示开启,自动采集 $WebClick 事件,可以设置 'not_collect' 表示关闭。
clickmap: 'default',
//是否开启触达图not_collect 表示关闭,不会自动采集 $WebStay 事件,可以设置 'default' 表示开启。
scroll_notice_map: 'default'
}
});
sensors.quick('autoTrack'); //用于采集 $pageview 事件。
// 注册公共属性
sensors.registerPage({
current_url: location.href,
referrer: document.referrer
});
app.config.globalProperties.$sensorsData = sensors;
}
};
}