2012-10-20 30 views
3

我正在開發一個js單頁網站使用JavaScript客戶端MVC(angular.js在這種情況下)手柄網址哈希#與谷歌分析

我加入谷歌分析該網站的應用程序,但是從我能看到至今(至少實時)谷歌並沒有考慮到URI的一部分散列後

是我有一個url像mydomain.com.ar/#/ideas/1但對於谷歌分析它看起來就像mydomain.com.ar/

有什麼想法?

+0

可能的重複。請參閱[是否有可能跟蹤谷歌鏈接像谷歌分析頁面?](http://stackoverflow.com/questions/4811172/is-it-possible-to-track-hash-links-like-pages-with-google - 分析) –

回答

3

您需要在#之後解析參數,並使用_trackPageview發送數據以便在您的頁面報表上看到它們。

,這裏是如何做到這一點,

var params = {}, 
    queryString = location.hash.substring(1), 
    regex = /([^&=]+)=([^&]*)/g, 
    m; 
while (m = regex.exec(queryString)) { 
    params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]); 
} 
_gaq.push(['_trackPageview', queryString]); 
+1

這裏是如何做到這一點; first'var params = {},queryString = location.hash.substring(1), regex = /([^&=] +)=([^&] *)/ g,m; (m = regex.exec(queryString)){ params [decodeURIComponent(m [1])] = decodeURIComponent(m [2]); }' 然後'_gaq.push(['_ trackPageview',queryString]);'' –

0

使用$窗口的依賴和路徑變化調用。

同時使用GA'set'來確保Google實時分析的路線。

$scope.$on('$routeChangeSuccess', function() { 
    $window.ga('set', 'page', $location.url()); 
    $window.ga('send', 'pageview'); 
});