事件跟踪 - 需要链接在新窗口中打开,而不会被视为弹出窗口
Event tracking - need the link to open in a new window without being treated as pop-up
这是 https://support.google.com/analytics/answer/1136920?hl=en 的脚本
<script type="text/javascript">
function trackOutboundLink(link, category, action) {
try {
_gaq.push(['_trackEvent', category , action]);
} catch(err){}
setTimeout(function() {
document.location.href = link.href;
}, 2000);
}
</script>
<a href="http://www.example.com" onClick="trackOutboundLink(this, 'Outbound Links', 'example.com'); return false;">Visit example</a>
Google Analytics建议的脚本运行良好,但只有一件事,我希望链接在2秒后在新选项卡或窗口中打开,而不会被Chrome和IE等主要浏览器上的弹出窗口阻止程序阻止
。我尝试使用_blank使其变得<a target="_blank" href="http://www.example.com" onClick="trackOutboundLink(this, 'Outbound Links', 'example.com'); return false;">Visit example</a>
但它不起作用。
在 setTimeout() 中使用 window.open() 打开一个新窗口将被视为弹出窗口并被弹出窗口阻止程序阻止。我不希望将新窗口(或选项卡)视为弹出窗口。
GA 代码中的所有内容都很好,除了我需要的新选项卡/窗口。请帮忙。
谢谢并感谢您的时间。
南卡罗来纳州
好吧,您可以使用jquery库触发点击。
-
将jquery库连接到您的项目,例如:
-
你应该使一个链接不可见,然后触发它:
http://jsfiddle.net/PingOfDeath/5tkAz/2/
$( "#link" ).trigger( "click" );
那么你的 html 应该看起来像这样:
<a href="#" onClick="trackOutboundLink('http://www.example.com', 'Outbound Links', 'example.com'); return false;">Visit example</a>
<a id="link" href="http://www.example.com" target="blank_" hidden="true">Visit example</a>
- 跟踪打开的窗口
- 如何跟踪在javascript中打开的子窗口
- Javascript来跟踪点击是否打开了一个新的标签/窗口
- 事件跟踪 - 需要链接在新窗口中打开,而不会被视为弹出窗口
- 跟踪由 window.open() 方法打开的窗口上的用户活动
- 如何仅跟踪浏览器窗口大小调整
- 如何跟踪用户是否关闭选项卡并向他显示研究窗口
- 何时在窗口上提供正确的堆栈跟踪.错误函数
- 如何使用引导模式窗口在IE中跟踪表单提交
- Javascript:跟踪函数父对象层次结构,以便从窗口上下文调用它
- 开发人员工具:在弹出窗口中跟踪网络请求
- 添加谷歌分析点击(事件)跟踪代码到Javascript窗口
- 谷歌地图-跟踪点击事件上的信息窗口内容
- 我如何让谷歌分析跟踪Javascript窗口.位置.href重定向
- 跟踪窗口的更改.JavaScript中的location
- 未定义跟踪器JS窗口
- 跟踪聊天窗口事件,我如何让这两个脚本一起工作
- 跟踪窗口“关闭”;(X)在iOS Safari上
- 我可以跟踪一个新的窗口链接的推荐人
- 从Url'获取Html数据;的父窗口,不使用IE浏览器-多个包裹上的UPS跟踪信息