@@ -16,15 +16,12 @@ import GlobalMessage from '@/components/GlobalMessage.vue'
1616
1717// Composables
1818import { createApp } from 'vue'
19- import Clarity from '@microsoft/clarity' ;
20-
21- const projectId = "rhp8uqoc3l"
2219//import TDesign from 'tdesign-vue-next'
2320//import 'tdesign-vue-next/es/style/index.css'
2421//import '@examaware-cs/player/dist/player.css'
2522
26- Clarity . init ( projectId ) ;
2723import messageService from './utils/message' ;
24+ import { getVisitorId } from './utils/fingerprint' ;
2825
2926const app = createApp ( App )
3027
@@ -37,7 +34,30 @@ app.component('GlobalMessage', GlobalMessage)
3734
3835app . mount ( '#app' )
3936
40- // 移除首屏 CSS 加载覆盖层(在 Vue 挂载完成后)
37+ // 异步加载 Clarity 以提升初始加载速度
38+ if ( document . readyState === 'complete' ) {
39+ loadClarity ( ) ;
40+ } else {
41+ window . addEventListener ( 'load' , loadClarity , { once : true } ) ;
42+ }
43+
44+ async function loadClarity ( ) {
45+ try {
46+ const Clarity = ( await import ( '@microsoft/clarity' ) ) . default ;
47+ const projectId = "rhp8uqoc3l" ;
48+ Clarity . init ( projectId ) ;
49+
50+ // 获取并设置访客标识
51+ const visitorId = await getVisitorId ( ) ;
52+ console . log ( 'Visitor ID:' , visitorId ) ;
53+ Clarity . identify ( visitorId ) ;
54+ Clarity . setTag ( 'fingerprintjs' , visitorId ) ;
55+ } catch ( error ) {
56+ console . warn ( 'Clarity 加载或标识设置失败:' , error ) ;
57+ }
58+ }
59+
60+ // 移除首屏 CSS 加载覆盖层(在 Vue 挂载完成后)
4161try {
4262 const removeLoader = ( ) => {
4363 document . body . classList . add ( 'app-loaded' ) ;
0 commit comments