OnClick 用于 google 分析和目标 _blank.链接失效了? [英] OnClick for google analytics and target _blank. The link does not work?

查看:27
本文介绍了OnClick 用于 google 分析和目标 _blank.链接失效了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<a href="http://example.com/test.html" 
   onclick="_gaq.push(['_link', 'http://example.com/test.html']);"     
   class="noFloat" 
   target="_blank"> 
   Click Me
</a>

我对这段代码有疑问.不返回假;我有一个新窗口,没关系,但在同一个父窗口中也打开了相同的 url.然后我有两个内容相同的窗口.我觉得是_gaq.push的重定向问题请大家帮帮我!谢谢!

I have a problem with this code. Without return false; i have a new window and it's ok, but the same url is also open in the same parent window. Then i have two windows with the same content. I think the problem is the redirect of the _gaq.push Please help me! Thank you!

推荐答案

_link 将用链接页面替换您当前的页面.因此,您应该始终返回 false,因为 Google Analytics(分析)将负责此链接的重定向.

_link will replace your current page with the link page. So you should always return false because Google Analytics will be in charge of the redirection for this link.

此外,Google 也不支持 _blank 属性.所以你必须想办法解决.

Also Google doesn't support the attribute _blank. So you have to find a way around.

_gaq.push(['_setAllowLinker', true]);
function _gaLink(a) {
    url = a.href
    _gaq.push(function() {
        if (a.target == '_blank') {
            window.open(_gat._getTrackers()[0]._getLinkerUrl(url));
        } else {
            _gaq.push(['_link', url]);
        }
    });
    return false;
}​

现在您可以调用它而不是 Google Analytics _link.

Now you can call it instead of Google Analytics _link.

<a href="http://example.com/test.html" 
   onclick="return _gaLink(this);"     
   class="noFloat" 
   target="_blank"> 
   Click Me
</a>

这篇关于OnClick 用于 google 分析和目标 _blank.链接失效了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆