带有jQuery的Google Analytics(分析)-在标签中显示路径名 [英] Google Analytics with jQuery - show pathname in label

查看:80
本文介绍了带有jQuery的Google Analytics(分析)-在标签中显示路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尽力创建了跟踪,它的工作原理如下:

I've got as far as creating the tracking and it works great like so:

  $('a.external').click(function(){
    _gaq.push(['_trackEvent', 'Exit Links', 'Click', $(this).attr('href')]);
  });

<a href="http://example.com" class="external">example</a>

这可以正确地使用href作为标签进行分析.我想要做的就是能够标记他们所在的当前页面.因此,我们可以确定他们在单击链接进入外部页面时所在的页面.

This comes through to analytics correctly with the href as the label. What I'm wanting to do is be able to tag the current page they are on as well. So we can work out which page they were on when they clicked the link to go to an external page.

像这样吗?

  $('a.external').click(function(){
    var pathName = window.location.pathname + document.location.hash;
    alert(pathName);
    _gaq.push(['_trackEvent', 'Exit Links', 'Click', $(this).attr('href')] pathName);
  });

这会提示正确的位置,但是谁能帮助我清理它,以便将pathName添加到gaq.push中的标签上?

That alerts the correct location but could anyone help me clean it up so that the pathName is added to the label within the gaq.push?

谢谢!

塞恩

推荐答案

如果您要传递pathName,则必须采取一些措施,因为ga事件仅允许使用三个允许文本的参数.

Something will have to give if you want to pass the pathName as the ga event only allows three parameters that allow text.

 $('a.external').click(function () {
 var pathName = window.location.pathname + document.location.hash
 var externalLink = $(this).attr('href');
 alert(['_trackEvent', 'Exit Links', pathName, externalLink]);

});

这篇关于带有jQuery的Google Analytics(分析)-在标签中显示路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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