【发布时间】: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