【问题标题】:Google Tag Manager in Android cordovaAndroid 科尔多瓦中的谷歌标签管理器
【发布时间】:2017-03-23 08:17:08
【问题描述】:

我在使用 ionic2/cordova 构建的 Android 移动应用中集成 Google 跟踪代码管理器时遇到问题。通过ionic serve 在网络浏览器中运行时一切正常,但在本地构建时会出现问题。

iOS:

一开始没用,但是添加https://github.com/driftyco/cordova-plugin-wkwebview-engine插件后,google分析开始接收流量。所以这个问题解决了,可以正常工作了。

安卓:

运行应用程序并使用 Chrome 控制台对其进行调试后,完全没有错误。 dataLayer 变量可用,我可以将数据推送到其中。当没有为给定事件触发触发器时,它还会返回有效响应true,当我使用正确类型的事件时返回false。因此,GTM 似乎可以正确识别所有内容。我在“网络”选项卡中观察到,在将对象推送到dataLayer 后,桌面/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);

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

<access origin="*"/>

【问题讨论】:

    标签: android cordova google-analytics ionic2 google-tag-manager


    【解决方案1】:

    我将回答我自己的问题。要解决此问题,您只需调整 GTM 中的 Universal Analytics 代码即可。

    设置:

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

    在这些更改之后,所有内容都会正确记录。

    【讨论】:

    • 有什么想法可以在新的 GTM 布局中找到它吗?我找不到将这些变量放在哪里...
    • 在新的 GTM 布局中,您必须转到 GTM 工作区/标签/单击标签名称/单击铅笔按钮(编辑)/向下滚动并展开更多设置部分,然后展开要设置的字段.您可以在此处添加自定义字段。
    猜你喜欢
    • 2017-12-19
    • 2016-11-21
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 2015-06-14
    • 2016-07-16
    相关资源
    最近更新 更多