From 281fee561c67446f83583ba96fd8e40f6f4781ad Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Wed, 4 Jun 2025 15:23:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(main):=20=E9=9B=86=E6=88=90=E7=A5=9E?= =?UTF-8?q?=E7=AD=96=E6=95=B0=E6=8D=AE=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 main.ts 中引入并注册神策数据插件 - 新增 sa.ts 文件实现神策数据插件功能 - 初始化神策数据并配置相关选项 - 在全局属性中添加 $sensorsData --- src/main.ts | 2 ++ src/utils/plugins/sa.ts | 37 +++++++++++++++++++++++++++++++++++++ src/views/Survey/Index.vue | 5 ----- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/utils/plugins/sa.ts diff --git a/src/main.ts b/src/main.ts index 78209e3..b8a2a9b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,7 @@ import './assets/css/main.scss'; import 'swiper/css'; import 'swiper/css/navigation'; import 'swiper/css/pagination'; +import { sensorsData } from './utils/plugins/sa'; const app = createApp(App); @@ -51,4 +52,5 @@ router.beforeEach((to, from, next) => { }); app.use(createPinia()); app.use(router); +app.use(sensorsData()) app.mount('#app'); diff --git a/src/utils/plugins/sa.ts b/src/utils/plugins/sa.ts new file mode 100644 index 0000000..efa15dd --- /dev/null +++ b/src/utils/plugins/sa.ts @@ -0,0 +1,37 @@ +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; + } + }; +} diff --git a/src/views/Survey/Index.vue b/src/views/Survey/Index.vue index fe5940f..398abef 100644 --- a/src/views/Survey/Index.vue +++ b/src/views/Survey/Index.vue @@ -7,11 +7,6 @@ @search="handleSearchClick" @cancel="handleCancelClick" /> -