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" /> -