2017-03-23 50 views
2

我在使用ionic2/cordova構建的Android移動應用中集成Google跟蹤代碼管理器時遇到問題。當通過ionic serve在網絡瀏覽器中運行時,一切正常,但它在本機構建中存在問題。Android中的Google跟蹤代碼管理器cordova

的iOS:

它沒有在工作第一,但加入https://github.com/driftyco/cordova-plugin-wkwebview-engine插件之後,谷歌分析開始接收流量。所以這個解決方案就像它應該的那樣工作。

安卓:

運行的應用程序,並使用Chrome控制檯調試它後有完全沒有錯誤。 dataLayer變量可用,我可以將數據推送到它。當我使用適當類型的事件時,它也返回有效的響應true,當沒有觸發器被觸發給定的事件和false。所以GTM似乎能夠正確識別一切。我在Network選項卡中觀察到,在將對象推送到dataLayer後,Desktop/iOS都向https://www.google-analytics.com/collect?v=1&_v=j49&a=1838345933&t=pageview&[moredatahere]發送請求,但Android應用程序不發送任何內容(網絡選項卡中沒有任何內容)。我很好奇爲什麼呢?爲什麼在Android上沒有對GA的請求?

這是我的index.html文件:

<!DOCTYPE html> 
<html lang="en" dir="ltr"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Ionic App</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> 
    <meta name="format-detection" content="telephone=no"> 
    <meta name="msapplication-tap-highlight" content="no"> 

    <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico"> 
    <link rel="manifest" href="manifest.json"> 
    <meta name="theme-color" content="#4e8ef7"> 

    <!-- Google Tag Manager --> 
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': 
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], 
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); 
    })(window,document,'script','dataLayer','GTM-5CH5MGN');</script> 
    <!-- End Google Tag Manager --> 

    <!-- cordova.js required for cordova apps --> 
    <script src="cordova.js"></script> 

    <link href="build/main.css" rel="stylesheet"> 

</head> 
<body> 
    <!-- Google Tag Manager (noscript) --> 
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KMJLK35" 
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> 
    <!-- End Google Tag Manager (noscript) --> 

    <!-- Ionic's root component and where the app will load --> 
    <ion-app></ion-app> 

    <!-- The polyfills js is generated during the build process --> 
    <script src="build/polyfills.js"></script> 

    <!-- The bundle js is generated during the build process --> 
    <script src="build/main.js"></script> 

</body> 
</html> 

這就是我如何使用dataLayer變量GTM通信:

let event = { 
     event: 'virtualpageview', 
     pagepath: url, 
     pagetitle: title 
    }; 

    dataLayer.push(event); 

此外,在我已經添加了科爾多瓦config.xml文件:

<access origin="*"/> 

回答

3

我要回答我自己的問題。要解決問題,您只需調整GTM中的Universal Analytics代碼即可。

Universal Analytics tag configuration

集:

  • checkProtocolTasknull
  • storagenone
  • clientId被用來識別用戶沒有cookies(作爲存儲是無)。我創建了一個名爲Device UUID的新Javascript變量,它指向全局變量device.uuid,它只是一個設備標識符。

經過這些更改後,所有記錄都正確。

+0

它像一個魅力工作!非常感謝好友! – Sushil

+0

謝謝你 – pkudel4

相關問題