PigTech пре 2 година
родитељ
комит
39c61b8f97
3 измењених фајлова са 50 додато и 0 уклоњено
  1. 1 0
      package.json
  2. 26 0
      src/tracking/GoogleAnalytics.js
  3. 23 0
      src/tracking/TrackAll.js

+ 1 - 0
package.json

@@ -58,6 +58,7 @@
     "react-draggable": "^4.4.6",
     "react-ga4": "^2.1.0",
     "react-grid-layout": "^1.3.4",
+    "react-gtm-module": "^2.0.11",
     "react-headroom": "^3.2.1",
     "react-helmet": "^6.1.0",
     "react-hook-form": "^7.43.3",

+ 26 - 0
src/tracking/GoogleAnalytics.js

@@ -0,0 +1,26 @@
+// src/GTMManager.js
+import TagManager from 'react-gtm-module';
+import {gt} from "react-big-calendar/lib/utils/dates";
+
+const GTM_ID = 'G-B8DCT6M79Y'; // 替换为您的GTM ID
+const GA4_ID = '8516447499'; // 替换为您的GA4 ID
+
+export const gg_setTagID=(GTM_ID="G-B8DCT6M79Y",GA4_ID="8516447499")=>{
+    // Initialize GTM
+    TagManager.initialize({ gtmId: GTM_ID });
+
+    // Initialize GA4
+    window.dataLayer = window.dataLayer || [];
+   function gtag(){
+        window.dataLayer.push(arguments);
+    }
+    gtag('js', new Date());
+    gtag('config', GA4_ID);
+    window.gtag=gtag;
+};
+
+export const gtrack=(eventName,params)=>{
+    // gtag('event','d0',{currency:'BRL',value:data.golds,transaction_id:data.order_sn})
+    window.gtag('event',eventName,params)
+
+}

+ 23 - 0
src/tracking/TrackAll.js

@@ -1,4 +1,5 @@
 import {fb_trackEvent,fb_trackPageView,fb_setPixelID} from "./FacebookPixel";
+import {gg_setTagID,gtrack} from "./GoogleAnalytics";
 import {kwai_setPixelID,kwai_trackEvent} from "./KwaiPixel";
 
 export const initTrackAll = (pf_type,pf_id,ex_id) => {
@@ -6,6 +7,9 @@ export const initTrackAll = (pf_type,pf_id,ex_id) => {
         fb_setPixelID(pf_id,ex_id)
     }else if(pf_type==="kw"){
         kwai_setPixelID(pf_id,ex_id)
+    }else if(pf_type==="gg"){
+        pf_id=pf_id.split("|")
+        gg_setTagID(pf_id[0],pf_id[1]);
     }
     window.addEventListener('installready', function(){
         //Show your own installation UI
@@ -13,6 +17,8 @@ export const initTrackAll = (pf_type,pf_id,ex_id) => {
             trackEvent("InstallPWA")
         }else if(pf_type==="kw"){
             trackEvent("download")
+        }else if(pf_type==="gg"){
+            trackEvent("file_download")
         }
 
     });
@@ -25,6 +31,23 @@ export const trackPageView = () => {
 };
 
 export const trackEvent = (eventName, params) => {
+    if (window.gtag&&global.pf&&global.pf.type==='gg') {
+        if(eventName==="pay"){
+            let data=params;
+            if(data.first) {
+                if (!!data.isd0) {
+                    gtrack("d0", {currency:'BRL',value:data.golds,transaction_id:data.order_sn})
+
+                }
+                gtrack("d1", {currency:'BRL',value:data.golds,transaction_id:data.order_sn})
+
+            }
+
+            gtrack('purchase', {currency:'BRL',value:data.golds,transaction_id:data.order_sn});
+        }else{
+            gtrack(eventName, params);
+        }
+    }
     if (window.fbq&&global.pf&&global.pf.type==='fb') {
         if(eventName==="pay"){
             let data=params;