GTM 触发器基于 javascript 个函数
GTM triggers based on javascript functions
我在javascript/jquery中制作了一个应用程序...一种互动课程
我想触发 "Lesson Finished"...
只有在我的 javascript
中触发函数 lessonFinished() 时才会发生这种情况
如何在 GTM 中设置触发器以检测 javascript 中的特定函数已被触发...或者正确的解决方法是什么?
我会用装饰来给函数增加功能。但这仅在您使用全局可访问函数时才有效。您可以创建一个自定义 HTML 事件并使用类似这样的东西。
$(function(){
if( typeof lessonFinished !== 'function'){
// need to delay the execution
console.error('lesson finished not defined');
}
// save the original lesson finished function
var originalLessonFinishedFunction = lessonFinished;
// decorate the lesson finished function with tag manager stuff
lessonFinished = function(){
// call the original function
originalLessonFinishedFunction();
// do the tag manager data layer push
dataLayer.push({
event: 'Lesson Finished',
timing: Date.now(),
extra: 'stuff'
});
}
});
我在javascript/jquery中制作了一个应用程序...一种互动课程
我想触发 "Lesson Finished"...
只有在我的 javascript
中触发函数 lessonFinished() 时才会发生这种情况如何在 GTM 中设置触发器以检测 javascript 中的特定函数已被触发...或者正确的解决方法是什么?
我会用装饰来给函数增加功能。但这仅在您使用全局可访问函数时才有效。您可以创建一个自定义 HTML 事件并使用类似这样的东西。
$(function(){
if( typeof lessonFinished !== 'function'){
// need to delay the execution
console.error('lesson finished not defined');
}
// save the original lesson finished function
var originalLessonFinishedFunction = lessonFinished;
// decorate the lesson finished function with tag manager stuff
lessonFinished = function(){
// call the original function
originalLessonFinishedFunction();
// do the tag manager data layer push
dataLayer.push({
event: 'Lesson Finished',
timing: Date.now(),
extra: 'stuff'
});
}
});