2014-06-11 1 views
0

Google 애널리틱스 이벤트가 아웃 바운드 링크를 추적하도록 설정되었습니다. 나는 the tutorial on Google's site을 따라 갔다.Google 애널리틱스 아웃 바운드 링크 추적에서 '라벨 없음'

내가 겪고있는 문제는 Google 애널리틱스에서 'url'매개 변수 (이벤트 라벨)가 추적되지 않는다는 것입니다. '아웃 바운드'및 '클릭'은 모두 ga() 호출에서 올바르게 작동합니다. ga() 호출 전에 줄의 'url'변수를 alert()하면 화면에 성공적으로 경고합니다.

카테고리 (아웃 바운드) 및 액션 (클릭)이 정상적으로 작동하는 이유는 무엇입니까? 그러나 라벨 (var url)이 Google 웹 로그 분석에 표시되지 않습니까?

jQuery(document).ready(function() { 
    initExternalLinkLogging(); 
}); 

function initExternalLinkLogging() { 
    // ':external' is from here and works great: http://stackoverflow.com/questions/1227631/using-jquery-to-check-if-a-link-is-internal-or-external 
    externalLinks = jQuery("a:external"); 
    jQuery(externalLinks).click(function() { 
     trackOutboundLink(this); 
    }); 
} 

function trackOutboundLink(url) { 
    // This is the triggered on each outbound link click successfully 
    // 'url' has the correct value, but is not showing up in Google Analytics 
    try { 
     ga('send', 'event', 'outbound', 'click', url, { 
      'hitCallback': function() { 
       document.location = url; 
      } 
     }); 
    } catch (err) { 
     // Do nothing for now 
    } 
} 

답변

0

이 문제를 해결했습니다. 이 문맥에서, 'url'변수는 화면에 경고가 URL 문자열로 표시 되더라도 객체였습니다. 이 함수 호출을 변경하면 문제가 해결됩니다.

//This doesn't work 
trackOutboundLink(this); 

//This fixes it. See ".href" 
trackOutboundLink(this.href); 

그래서 작업 상태에서 참조에 대한 전체 코드는 다음과 같습니다

jQuery(document).ready(function() { 
    initExternalLinkLogging(); 
}); 

function initExternalLinkLogging() { 
    // ':external' is from here and works great: http://stackoverflow.com/questions/1227631/using-jquery-to-check-if-a-link-is-internal-or-external 
    externalLinks = jQuery("a:external"); 
    jQuery(externalLinks).click(function() { 
     trackOutboundLink(this); 
    }); 
} 

function trackOutboundLink(url) { 
    // This is the triggered on each outbound link click successfully 
    // 'url' has the correct value, but is not showing up in Google Analytics 
    try { 
     ga('send', 'event', 'outbound', 'click', url, {'hitCallback': 
       function() { 
        document.location = url; 
       } 
     }); 
    } catch (err) { 
    } 
}