Files
tangguo_landpage/src/pages/index.vue
T
2026-09-15 16:25:45 +07:00

62 lines
2.2 KiB
Vue
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.
<script setup>
import PcDeck from '~/components/landing/PcDeck.vue'
import MobileLanding from '~/components/landing/MobileLanding.vue'
import LandingB from '~/components/landing-b/LandingB.vue'
import { computed, onBeforeMount, onBeforeUnmount } from 'vue'
import { useRoute } from 'vue-router'
import { useEventTracker, getSessionTraceId } from '~/utils/useEventTracker'
import { getLandingVersion } from '~/utils/landingVersion'
const route = useRoute()
const isMobile = computed(() =>
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
)
// A/B 分流:与 getButtonList 共用同一份版本(见 landingVersion.ts)
const landingVersion = getLandingVersion(route.query, route.path)
const isVersionB = landingVersion === 'B'
const landingComponent = computed(() => {
if (isVersionB) return LandingB
return isMobile.value ? MobileLanding : PcDeck
})
const LANDING_PAGE_ID = isVersionB ? 'JHA-209-B' : 'JHA-209'
const { trackLandingPageView, trackLandingPageClick, generateSessionId } = useEventTracker()
const handleClick = (e) => {
// 优先读最近祖先的 data-track(下载按钮标 download),其次 img alt,最后取文字
const rawText = e?.target?.closest?.('[data-track]')?.getAttribute('data-track') || e?.target?.alt || e?.target?.innerText || ''
const tabKey = rawText.replace(/[^A-Za-z0-9_一-鿿]/g, '_').replace(/_{2,}/g, '_').replace(/^_+|_+$/g, '') || ''
const isDownload = tabKey.toLowerCase() === 'download'
trackLandingPageClick({
landing_page_id: LANDING_PAGE_ID,
tab_key: tabKey,
tab_name: rawText,
click_coordinates_x: e.clientX,
click_coordinates_y: e.clientY,
click_x_percent: Math.round((e.clientX / window.innerWidth) * 100),
click_y_percent: Math.round((e.clientY / window.innerHeight) * 100),
screen_width: window.innerWidth,
screen_height: window.innerHeight,
trace_id: isDownload ? getSessionTraceId() : generateSessionId(),
})
}
onBeforeMount(() => {
trackLandingPageView({ landing_page_id: LANDING_PAGE_ID })
window.addEventListener('click', handleClick)
})
onBeforeUnmount(() => {
window.removeEventListener('click', handleClick)
})
</script>
<template>
<component :is="landingComponent" />
</template>
<style scoped></style>