聆听Google事件 [英] Listening google events
本文介绍了聆听Google事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您能告诉我,如何使用本地JavaScript监听Google Analytics(分析)(Google跟踪代码管理器)事件? 例如:
Could you tell me, how can I listening google analytics (google tag manager) event with native javascript? For example:
客户端发送了此事件
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue]);
我需要订阅此活动.
推荐答案
您可以使用 sendHitTask
检索发送的每个匹配的有效载荷:
You can use tasks
, which allow you to hook into the Google Analytics tracker's execution routine, for instance, hook into the sendHitTask
to retrieve the payload of every hit sent:
ga('create', 'UA-XXXXX-Y', 'auto');
ga(function(tracker) {
// Grab a reference to the default sendHitTask function.
var originalSendHitTask = tracker.get('sendHitTask');
// Modifies sendHitTask to send a copy of the request to a local server after
// sending the normal request to www.google-analytics.com/collect.
tracker.set('sendHitTask', function(model) {
originalSendHitTask(model);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/localhits', true);
xhr.send(model.get('hitPayload'));
});
});
ga('send', 'pageview');
这篇关于聆听Google事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文