谷歌Analyics不跟踪与AJAX生成的链接链接、谷歌、Analyics、AJAX

2023-09-11 22:31:46 作者:深处无怨尤

我运行一个网站,有大量会员链接。这些链接是通过AJAX加载。我希望能够跟踪这些链接出站点击。

标准的方式来使用谷歌Analytics(分析)来跟踪链接是使用pageTracker._trackPageview()函数。我已经试过这无济于事。这是我的code:

 < A HREF =<?PHP的echo $ link_loc>目标=_blank级=affiliateLink的onclick =pageTracker._trackPageview('/事件/去?');>链接文字< / A>
 

至于建议,我把我的谷歌Analytics(分析)标准跟踪code在开放body标签和上面的code之间。

有谁看到什么毛病我code?难道问题是:该链接通过AJAX加载的事实?

解决方案

  pageTracker._trackPageview('/事件/去?');
 

这应该被记录在参观/事件/去?。您的意思是记录访问 $ link_loc ?如果是这样,你必须把$ link_loc作为参数_trackPageview的一部分。你或许应该创建一个包含出站链接的只有主机和路径的字符串,减去的http:// ,并将它放入您的跟踪code

(我也想知道是否你或许应该把周围的PHP code发出的HREF引号)。

图文教程 创建Google Analytics网站流量和转化率报告

I run a website that has lots of affiliate links. These links are loaded via AJAX. I'd like to be able to track outbound clicks on these links.

The standard approach to using Google Analytics to track links is to use the pageTracker._trackPageview() function. I've tried this to no avail. Here's my code:

<a href=<?php echo $link_loc ?> target = "_blank" class="affiliateLink" onclick="pageTracker._trackPageview('/event/outgoing?');">Link Text</a>

As is suggested, I put my Google Analytics standard tracking code in between the opening body tag and the above code.

Does anyone see anything wrong with my code? Could the problem be the fact that the links are loaded via AJAX?

解决方案

pageTracker._trackPageview('/event/outgoing?');

That should be recording a visit to "/event/outgoing?". Did you mean to record a visit to $link_loc? If so, you'll have to put $link_loc as part of the argument to _trackPageview. You should probably create a string containing only the host and path of the outbound link, minus the http://, and put that into your tracking code.

(I also wonder whether you should perhaps be putting quotes around the href emitted by the php code).

 
精彩推荐
图片推荐