|
|
@@ -1,4 +1,5 @@
|
|
|
import { onMounted } from 'vue'
|
|
|
+import { useGlobalStore } from '@/stores'
|
|
|
|
|
|
// https://developers.facebook.com/docs/meta-pixel/reference
|
|
|
declare global {
|
|
|
@@ -8,12 +9,14 @@ declare global {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function useMetaPixel(pixelId = '1427950378223149') {
|
|
|
+export function useMetaPixel() {
|
|
|
+ const { getSystemInfo } = useGlobalStore()
|
|
|
+
|
|
|
// 初始化 MetaPixel
|
|
|
const initPixel = () => {
|
|
|
if (window.fbq) return
|
|
|
|
|
|
- const fbq = <T>(...args: T[]) => {
|
|
|
+ const fbq: any = <T>(...args: T[]) => {
|
|
|
fbq.callMethod
|
|
|
? fbq.callMethod(...args)
|
|
|
: fbq.queue.push(args)
|
|
|
@@ -26,7 +29,7 @@ export function useMetaPixel(pixelId = '1427950378223149') {
|
|
|
fbq.push = fbq
|
|
|
fbq.loaded = true
|
|
|
fbq.version = '2.0'
|
|
|
- fbq.queue = [] as any[]
|
|
|
+ fbq.queue = []
|
|
|
|
|
|
const el = document.createElement('script')
|
|
|
el.async = true
|
|
|
@@ -36,7 +39,7 @@ export function useMetaPixel(pixelId = '1427950378223149') {
|
|
|
tag.parentNode?.insertBefore(el, tag)
|
|
|
|
|
|
window.fbq = fbq
|
|
|
- window.fbq('init', pixelId)
|
|
|
+ window.fbq('init', getSystemInfo('metaPixelId'))
|
|
|
}
|
|
|
|
|
|
// 跟踪页面视图
|