简体   繁体   English

用于AJAX目标跟踪的Google Analytics(分析)虚拟页面

[英]Google Analytics virtual page for AJAX goal tracking

I've got checkform which is triggered upon form submission below. 我有下面的表单提交时触发的检查表单。

function checkform() {

    if (!document.getElementById('terms').checked) {
        alert('Read terms of use');
        return false;
    }

    _gaq.push(['_trackPageview', '/subscribe-successful']);
    return true;

}

I've also put trackPageview after if checked statement so if validation goes through, the gaq.push gets executed. 我还在if checked语句后放置了trackPageview,因此如果验证通过, gaq.push将被执行。

Also Google Analytics code itself is above this code so it's loaded before and I've got goal set up as /subscribe-successful 此外,Google Analytics(分析)代码本身位于此代码之上,因此已在之前加载,并且我已将目标设置为/subscribe-successful

Is this the right way to track AJAX based goals? 这是跟踪基于AJAX的目标的正确方法吗?

Your code looks right, though keep in mind Google Analytics will now think your visitor is on that page for its visitor flow and time-on-page tracking. 您的代码看起来不错,不过请记住,Google Analytics(分析)现在会认为访问者在该页面上是其访问者流和页面停留时间的跟踪。

I prefer using event tracking for things that don't involve navigating away from the page, like this: 我更喜欢将事件跟踪用于不涉及离开页面的事情,例如:

_gaq.push(['_trackEvent', 'Subscribe', 'Success']);

That will let you track successful subscriptions in Analytics without changing the visitor's URL. 这样一来,您就可以在Google Analytics(分析)中跟踪成功的订阅,而无需更改访问者的URL。 (And failures for that matter, if you want to track that.) (与此相关的失败,如果您想跟踪的话。)

There are times when a virtual URL (your solution) is better, such as when the page content has changed fundamentally so that it's not effectively the same page anymore. 有时,虚拟URL(您的解决方案)会更好,例如页面内容发生了根本性变化,以致不再有效地不再是同一页面。 It's up to you to decide which one this is. 由您决定这是哪一个。

See https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide for info on tracking events. 有关跟踪事件的信息,请参见https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM