Google Analytics事件跟踪不会从iframe解雇

时间:2014-06-09 21:37:19

标签: google-analytics

我有一个我正在使用的网站,它正在iFrame中使用电子邮件注册表单(出于随机CMS原因,这已经解决了)。我正在尝试将事件跟踪安装到iFrame中,以便我们可以看到实际的转化。

<script type="text/javascript">
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
    (i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

ga('create', 'UA-#######-1', 'site.org');
</script>
</head>

<body>
<div id='header'><span>Get the latest treatment tips</span> <span style='color:     #c9c9c9; padding: 0 5px;'>|</span> Sign up for e-news</div>
<form name='signup' id='signup' method='post' action='index.php'>
<input type='text' class='input' name='email' id='email' onfocus="if(this.value == 'Your email') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Your email'; }" value='Your email' />
<input type='text' class='input' name='zip' id='zip' onfocus="if(this.value == 'Zip code') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Zip code'; }" value='Zip code' />
<input onclick="ga('send', 'event', 'newsletter', 'sign-up', {'nonInteraction': 1});" type='submit' id='submit' value='Sign up &raquo;' class='submit' name='submit' />
</form>

之前,有人将ga(&#39; send&#39;,&#39; event&#39; ...)代码放在脚本部分的ga下(&#39;创建&#39;, &#39; UA - &#39; ...)并且每次加载页面时都会触发。所以,我发现它确实有效。它似乎没有点击按钮点击本身。

我也尝试在子节目上触发它,但也无效。

所以,我不确定为什么它不会在这个阶段进行。

帮助!谢谢!

1 个答案:

答案 0 :(得分:0)

This codepen为您的HTML工作添加了缺失的开头和结尾,我可以看到它将数据发送到Google Analytics。

我已将return false;添加到您的onclick,以便它无法在任何地方提交。

正如您在codepen中看到的那样,它是从iframe中调用的。