你能告诉我,如何使用 native JavaScript 监听 google 分析(google 标签管理器)事件? 例如:
客户端发送了此事件
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue]);
我需要订阅此事件。
最佳答案
您可以使用tasks
,它允许您 Hook Google Analytics 跟踪器的执行例程,例如 Hook sendHitTask
检索发送的每个命中的有效负载:
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');
关于javascript - 监听谷歌事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48806235/