让事件依赖于另一个事件的完成
Getting events to be dependent on the completion of another event
我网站的一部分从同一操作中生成了一些事件。 Google Analytics 的默认设置是让事件 运行 独立。但是,其中一个事件需要最后发生。有没有办法强制完成事件的顺序,或者至少让一个事件依赖于另一个事件?
我没有找到关于该主题的文档。在此先感谢您的帮助。
Analytics 中没有这样做的内置方法。要实现这种行为,您必须根据您的要求自行设计 and/or 应用程序逻辑。
如果您正在使用 JavaScript 实现网站,您可能会对使用 q library 感兴趣,它可以帮助您在 JavaScript 中创建和编写异步承诺。
如果不涉及太多细节(因为它可能超出您的问题范围),可能会产生如下内容:
Q.all([handleEventOne(), handlerEventTwo()]) // Wait for 2 handlers to complete
.done(function (values) { // Execute this callback once the 2 handlers have completed
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
});
你能做一个简单的旗帜吗?
事件#1
var flag = false;
function eventOne(){
ga('send', 'event', 'Event Chain', 'Trigger', 'First Event');
flag = true;
}
function eventTwo(){
if (flag) {
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
}
}
Google Universal Analytics 有 hit callbacks ,在跟踪调用完成时调用的函数。您至少可以尝试在事件命中中嵌套事件跟踪调用
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action', // Required.
'eventLabel': 'label',
'hitCallback': function() {
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action 2', // Required.
'eventLabel': 'label 2'
});
}
});
未经测试,但从文档来看我不明白为什么这行不通。
我网站的一部分从同一操作中生成了一些事件。 Google Analytics 的默认设置是让事件 运行 独立。但是,其中一个事件需要最后发生。有没有办法强制完成事件的顺序,或者至少让一个事件依赖于另一个事件?
我没有找到关于该主题的文档。在此先感谢您的帮助。
Analytics 中没有这样做的内置方法。要实现这种行为,您必须根据您的要求自行设计 and/or 应用程序逻辑。
如果您正在使用 JavaScript 实现网站,您可能会对使用 q library 感兴趣,它可以帮助您在 JavaScript 中创建和编写异步承诺。
如果不涉及太多细节(因为它可能超出您的问题范围),可能会产生如下内容:
Q.all([handleEventOne(), handlerEventTwo()]) // Wait for 2 handlers to complete
.done(function (values) { // Execute this callback once the 2 handlers have completed
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
});
你能做一个简单的旗帜吗?
事件#1
var flag = false;
function eventOne(){
ga('send', 'event', 'Event Chain', 'Trigger', 'First Event');
flag = true;
}
function eventTwo(){
if (flag) {
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
}
}
Google Universal Analytics 有 hit callbacks ,在跟踪调用完成时调用的函数。您至少可以尝试在事件命中中嵌套事件跟踪调用
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action', // Required.
'eventLabel': 'label',
'hitCallback': function() {
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action 2', // Required.
'eventLabel': 'label 2'
});
}
});
未经测试,但从文档来看我不明白为什么这行不通。