繁体   English   中英

Google Analytics 中点击跟踪的目标空白(在新窗口中打开)

[英]Target blank (open in new window) for click track in Google Analytics

此代码成功跟踪了 Google Analytics 中的点击次数。 但是,尽管链接中有 target="_blank",它不会在新窗口或选项卡中打开。

是否对 GA 脚本进行了简单的调整以在单独的窗口或选项卡中打开?

(我刚刚注意到一个类似的问题在 2014 年被问到,建议删除 js 中的回调(hitCallback);希望有一个新的答案?)

在标题中:

<script>
/**
* Function that captures a click on an outbound link in Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var captureOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){document.location = url;}
   });
}
</script>   

在内容中:

<a target="_blank" href="https://example.com" onclick="captureOutboundLink('https://example.com'); return false;">Test for click to Example</a>

更改'hitCallback': function(){document.location = url;}
'hitCallback': function(){window.open(url);}
例如

<script>
/**
* Function that captures a click on an outbound link in Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var captureOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){window.open(url);}
   });
}
</script>  

暂无
暂无

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

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