Google Analytics - 单页网站 - 点击跟踪 [英] Google Analytics - Single Page Site - Click Tracking

查看:30
本文介绍了Google Analytics - 单页网站 - 点击跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题的网站是 http://getstefan.com

它是一个单页组合网站,我尝试使用 jQuery 将 Google Analytics 点击跟踪添加到网站上的每个锚标签,希望能够跟踪人们点击的位置.有一个脚本可以为页面上的每个锚点添加一个唯一的 ID,因此我设置了一个超时,以确保在分配了 id 之后放置 Google Analytics 点击跟踪.像这样:

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?

推荐答案

第一您的锚点没有分配 ID,因此代码正在执行它应该报告的内容未定义"作为不存在的值.例如

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>

第二,不要使用定时器.

jQuery(window).load(function(){
        setTimeout(loadOnClick,8000)
    });

应该换成

jQuery(document).ready(function(){
        loadOnClick();
    });

因此您不必等待 8 秒,只需在 DOM 准备好时分配所有内容即可.

so you don't have to wait 8 seconds and can just assign everything when the DOM is ready.

这篇关于Google Analytics - 单页网站 - 点击跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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