2015-12-05 77 views
0

我在使用Javascript/jQuery的...一種交互式課程GTM觸發基於

我想爲「課程完成」觸發的...

而本作的應用程序的JavaScript函數只有當函數lessonFinished()在我的javascript內觸發時纔會發生如何在GTM中設置觸發器來檢測JavaScript中的特定函數是否已被觸發......或者正確的解決方法是什麼?

回答

0

我會用裝飾來爲功能添加功能。但只有在使用全球可訪問的功能時才能使用。你可以創建一個自定義的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' 
     }); 
    } 
});