2011-05-21 146 views
4

我有像多個門戶一樣行事的門戶。 門戶代碼庫相同,但對於所有網站,但內容基於您遇到的網址或域。 目前我能夠追蹤我的域名使用Google Analytics在同一代碼中跟蹤多個域

example.com

,也像子網域

a.example.com,b.example.com

。但我想還跟蹤

anotherexample.com

這也指向同一個域。我能怎麼做? 有什麼建議嗎?

+0

您看過http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#multipleDomains嗎? – Eduardo 2011-05-23 00:51:10

+0

anotherexample.com迴應同樣的事情?銥只是一個重定向? – Eduardo 2011-05-23 13:02:23

+0

這不是重定向。正如我所說我們的門戶行爲像多個門戶一樣。如果你輸入abc.com,你會看到abc站點。如果你輸入def.com,你會看到def.com。內容不同?講清楚? – gandil 2011-05-23 15:58:48

回答

3

多個url指向相同的代碼庫。不要緊。唯一的問題是上面的網址和網站中的跟蹤代碼是否匹配。所以你必須從地址欄中寫入數據庫的谷歌訪問代碼。

代碼:

<!-- Google Analytics --> 
<script type="text/javascript"> 
    var accountNameFromDB = ...Some Operations... 
    var domainNameFromDB = ...Some Operations... 
    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', accountNameFromDB]); 
    _gaq.push(['_setDomainName', domainNameFromDB]); 
    _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> 

就拿accountNameFromDB和domainNameFromDB變量dynmically。 添加此主頁(或主模板)的代碼頭或添加每一頁。

+0

我目前正在這樣做,這是完全不正確的,與谷歌的文檔相反:https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#multipleDomains – Cerin 2012-10-25 14:32:35

+0

這是用本指南cerin編寫的。區別在於域名和域名唯一ID來自數據庫。 – gandil 2012-10-26 12:58:53

相關問題