2011-07-14 95 views
1

我拼湊了一些我在網上發現的關於在Google Analytics的長文章頁面上跟蹤滾動距離的想法。我感興趣的是當用戶到達文章的中途標記時記錄一個事件,然後再在終點處記錄事件。我的代碼並不完美,因爲它沒有考慮頁面上的時間(如果用戶在頁面加載後立即滾動到底部會怎麼樣?),但是一旦我處理此問題,這是一個容易解決的問題。谷歌分析和_trackEvent:事件不記錄到分析

下面的代碼在兩個console.log()調用正在跟蹤他們應該是什麼時候,所以我的假設是_trackEvent調用也可以,但他們不是。沒有錯誤被拋出。他們從未在Google Analytics中顯示過。

任何人都可以看到任何明顯的錯誤或漏洞?下面是網站,在這裏我使用這段代碼:http://www.adlucent.com/blog/

$(document).ready(function() { 

    if ($(document.body).hasClass('single')) { 
     var doc_height = $(document).height(), 
      article_pos = $('#main > article').offset(), 
      article_height = $('#main > article').height(), 
      article_half = (article_height/2) + article_pos.top, 
      article_bottom = article_height + article_pos.top, 
      scrolled_half = Math.round(100 * article_half/doc_height), 
      scrolled_whole = Math.round(100 * article_bottom/doc_height); 

     $(window).scroll(function(){ 
      var scrollPercent = GetScrollPercent(); 
      if (!isScrolledHalf) { 
       if (scrollPercent > scrolled_half) { 
        isScrolledHalf = true; 
        console.log("Reached halfway mark!"); 
        _gaq.push(['_trackEvent', 'Content Engagement', 'Scroll', 'Half']); 
       } 
      } 
      if (!isScrolledWhole) { 
       if (scrollPercent > scrolled_whole) { 
        isScrolledWhole = true; 
        console.log("Reached the end!"); 
        _gaq.push(['_trackEvent', 'Content Engagement', 'Scroll', 'End']); 
       } 
      } 
     }); 
    } 

}); 
function GetScrollPercent(target){ 
    var bottom = $(window).height() + $(window).scrollTop(), 
     height = $(document).height(); 
    return Math.round(100 * bottom/height); 
} 

回答

0

事實證明它實際上可能是在新的GA的錯誤。當我聽到回來時,我會在這裏回覆評論。

後...

我從未收到過對這個問題的答案,但我的代碼最終開始追蹤。我後來切換到using this來跟蹤滾動深度,它的工作原理絕對完美無瑕。

+1

這個詞什麼意思? –

+0

@Brandon - 對此有何更新?你說你會回來更新你的答案和更多的細節?謝謝! – jmort253

+0

這是固定的.. ?? – shashwat