2012-06-14 24 views
3

有一個網站使用頁面按鈕和他們的URL中的#標籤來操縱其內容(鏈接)的排序方式。他們鏈接到我的網站,我想知道人們在最終找到我的網站並點擊之前點擊了哪些按鈕。如何從引用網址獲取location.hashtag - Google Analytics

例如,參照網址看起來像這樣 - http://www.example.com/page1?content=1234#button1

有沒有一種方法來提取包括hashtag(#),所以我可以告訴人們如何排序找到我的網站後的價值?我想過使用document.referrer.location.hashtag,但我不認爲這有效......

我最終想要將這些數據導入Google Analytics(我可以使用自定義變量),但如何做到這一點在GA的任何其他技巧值得讚賞。

我感謝任何幫助!

回答

1
<script type="text/javascript"> 
    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-XXXXX-X']); 

    /* 
    * Function: Hash Custom Variable 
    * Pass everything after # in document.referrer to GA custom variable 
    */ 
    (function() { 

    // Parse out the hash part of the referrer 
    var referrerHash = document.referrer.split("#")[1]; 

    // If the hash exists, pass it back to GA 
    if(typeof referrerHash !== "undefined") { 
     _gaq.push(['_setCustomVar', 1, 'Sort', referrerHash, 3]); 
    } 

    })(); // IIFE to not leak global vars 

    // Have to _trackPageview after custom variable is pushed  
    _gaq.push(['_trackPageview']); 

    (function() { 
    var ga = document.createElement('script'); 
    ga.type = 'text/javascript'; 
    ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(ga, s); 
    })(); 
</script> 

有用來源:

相關問題