简体   繁体   English

Google Analytics(分析)事件跟踪未从iframe中触发

[英]Google Analytics Event Tracking isn't firing from iframe

I have a site that I'm working on which is using a email sign up form inside an iFrame (for random CMS reasons, this has been the work around). 我有一个正在工作的网站,该网站正在iFrame内使用电子邮件注册表单(出于随机CMS的原因,这已得到解决)。 I am attempting to install the Event tracking in to the iFrame so that we can see the actual conversion. 我正在尝试将事件跟踪安装到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>

Previously, someone had put the ga('send', 'event'...) code in the script section, under ga('create', 'UA-'...) and it fired every time the page loaded. 以前,有人将ga('send','event'...)代码放在脚本部分的ga('create','UA -'...)下,并在每次加载页面时触发。 So, I've seen it actually work. 因此,我已经看到它确实有效。 It just doesn't seem to be firing on the button click itself. 它似乎并没有触发按钮单击本身。

I have also tried firing it onSubmit and that also is not working. 我也尝试过在onSubmit上触发它,这也没有用。

So, I'm not really sure why it isn't going at this stage. 因此,我不太确定为什么现在不这样做。

Help! 救命! Thank you! 谢谢!

This codepen which adds the missing start and end to your HTML works and I can see it sending data to Google Analytics. 该Codepen将缺少的开头和结尾添加到您的HTML作品中,我可以看到它向Google Analytics(分析)发送了数据。

I've added return false; 我添加了return false; to your onclick just so that it didn't submit anywhere. 到您的onclick ,以便它不会在任何地方提交。

As you can see from the codepen, it is called from within the iframe. 如您从代码笔所看到的,它是在iframe中调用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM