Google Analytics - 单页网站 - 点击跟踪 [英] Google Analytics - Single Page Site - Click Tracking
问题描述
有问题的网站是 http://getstefan.com
它是一个单一的页面组合网站,我尝试使用jQuery将Google Analytics的点击跟踪添加到站点上的每个锚定标签,希望能够跟踪用户点击的位置。有一个脚本为页面上的每个定位点添加了一个唯一的ID,因此我设置了一个超时以确保在分配id后分配Google Analytics点击跟踪。像这样:
jQuery(window).load(function(){
setTimeout(loadOnClick,8000)
});
函数loadOnClick(){
jQuery('a')。each(function(){
jQuery(this).attr(onclick,_gaq.push( ['_trackEvent','anchor','click',''+ jQuery(this).attr('id')+']););
});
}
建立如下链接的结果:
< a href =http://getstefan.com/wp-content/themes/inc v2 / downloads / CV-StefanHinck-FR.pdf id =cvonclick =_ gaq.push(['_ trackEvent','anchor','click','cv']);>< / a>
一切看起来不错。
问题是,当我查看我的分析时,只有已注册的点击标记为未命名。
任何人都知道我在这里做错了什么?
您的锚点没有分配ID,因此代码正在执行它应该报告未定义作为不存在的东西的值。
例如
< a class =entry-linkhref =http://getstefan.com /组合/内部设计-标志/>< / A>
第二,请勿使用计时器。
pre $
jQuery(window).load(function(){
setTimeout(loadOnClick,8000)
});
应由
jQuery(document).ready(function(){
loadOnClick();
});
所以您不必等待8秒,并且可以在DOM准备好时分配所有内容。
The site in question is http://getstefan.com
Its a single page portfolio site and I have tried using jQuery to add Google Analytics click tracking to every anchor tag on the site hoping to track where people are clicking. There is a script that adds a unique ID to each anchor on the page, so I set a timeout to make sure and place the Google Analytics click tracking after the id has been assigned. Like so:
jQuery(window).load(function(){
setTimeout(loadOnClick,8000)
});
function loadOnClick() {
jQuery('a').each(function(){
jQuery(this).attr("onclick", "_gaq.push(['_trackEvent', 'anchor', 'click', '" + jQuery(this).attr('id') + "']);" );
});
}
Which results in building a link like so:
<a href="http://getstefan.com/wp-content/themes/inc v2/downloads/CV-StefanHinck-FR.pdf" id="cv" onclick="_gaq.push(['_trackEvent', 'anchor', 'click', 'cv']);"></a>
Everything looks good. Problem is that when I look at my analytics, the only clicks registered are labeled "untitled"
Anyone know what im doing wrong here?
First Your anchors don't have an ID assigned, so the code is doing exactly what it should be reporting 'undefined' as the value for something that doesn't exist. For example
<a class="entry-link" href="http://getstefan.com/portfolio/interior-design-logo/"></a>
Second, don't use the timer.
jQuery(window).load(function(){
setTimeout(loadOnClick,8000)
});
should be replaced by
jQuery(document).ready(function(){
loadOnClick();
});
so you don't have to wait 8 seconds and can just assign everything when the DOM is ready.
这篇关于Google Analytics - 单页网站 - 点击跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!