Android cordova中的Google跟踪代码管理器

Kam*_*ski 6 android google-analytics cordova google-tag-manager ionic2

我在使用ionic2/cordova构建的Android移动应用程序中集成G​​oogle跟踪代码管理器时遇到问题.在Web浏览器中运行时,一切正常ionic serve,但是本机构建存在问题.

iOS版:

它最初没有用,但在添加https://github.com/driftyco/cordova-plugin-wkwebview-engine插件后,谷歌分析开始接收流量.所以这个问题已经解决,并且可以正常运行.

安卓:

运行应用程序并使用Chrome控制台对其进行调试后,根本没有错误.该dataLayer变量可用,我可以将数据推入其中.true当没有为给定事件触发触发器时以及false当我使用适当类型的事件时,它也会返回有效响应.所以GTM似乎正确地识别了一切.我在网络选项卡中观察到桌面/ iOS正在向后https://www.google-analytics.com/collect?v=1&_v=j49&a=1838345933&t=pageview&[moredatahere]推送对象发送请求dataLayer,但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>
Run Code Online (Sandbox Code Playgroud)

这就是我使用dataLayer变量与GTM沟通的方式:

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

    dataLayer.push(event);
Run Code Online (Sandbox Code Playgroud)

另外在cordova config.xml中我已添加:

<access origin="*"/>
Run Code Online (Sandbox Code Playgroud)

Kam*_*ski 6

我要回答我自己的问题.要解决此问题,您只需调整GTM中的Universal Analytics标记即可.

Universal Analytics标记配置

组:

  • checkProtocolTask 至 null
  • storage 至 none
  • clientId用于识别没有cookie的用户(因为存储是无).我创建了一个新的Javascript变量Device UUID,它指向全局变量device.uuid,它只是一个设备标识符.

在这些更改后,一切都正确记录.