Tracking Subdomains With Google Analytics
If you use subdomains religiously (like I do), then you’ll want to add the subdomain code to your Google Analytics code. See, Analytics refuses to ackowledge any page hits coming from sites other than the one you are officially tracking, so you need to add a line of code to your Analytics code.
Add the bold line, exactly where you see it:
< script src="http://www.google-analytics.com/urchin.js" type="text/javascript" >
< /script >
< script type="text/javascript" >
_uacct = “UA-xxxx-x”;
_udn=”blognewschannel.com”;
urchinTracker();
< /script >
But wait, we’re not done. First, replace the xxxx-x with your account code, then replace blognewschannel.com with your primary domain.
Now, we’re still not done. See, your reporting pages won’t know the subdomain exists and list its pages properly. A page called google.blognewschannel.com/example.php would be recorded only as /example.php, making tracking similar pages on different subdomains impossible. Here’s what you do:
- In Analytics Settings, click “Filter Manager”
- Click “Add Filter”
- Enter a filter name (like “subdomains”)
- Under “Filter Type” select “Custom Filter”, then click the radio button for “Advanced”
- In Field A, select “Hostname” and type in the box “
(.*)“ - In Field B, select “Request Stem” and type in the box “
(.*)“ - In “Output To”, select “Request Stem” and type in the box “
$A1$B1“ - Add any and all website profiles you want subdomain tracking on, and click “Finish”
Now, you should start seeing subdomain reporting data shortly, tracked on every subdomain that has proper Analytics code.
It should go without saying that you do not type in the quotation marks at any point. I just wrote those to help you out.
The page this information came from is incorrect, since it refers to interface elements that no longer exist. Still, this solution should work. If it doesn’t, let me know if you have any problems.
If you don’t want to track these in the same profile, but to give each subdomain a different profile, then you need to create multiple profiles for the same domain, put the code for the specific subdomain profiles only on those subdomains, and create an Include filter so that profile knows it is to only track that one subdomain.
Use the filter type “Include only traffic to a subdirectory”, and submit the subdirectory as “^sub\.example\.com“, with “sub” being the name of the subdomain. This even includes the “www” subdomain (as “^www\.example\.com“). This method is explained here.
If you want to track a portion of your site hosted on a third party site, such as a shopping cart or del.icio.us links, change your outgoing link to read:
< a href=
"javascript:__utmLinker('https://www.securecart.com/?store=parameters');" >
Purchase Now< /a >
Just put your link where that link is (oh, and change the link text). Setting your del.icio.us links to automatically include this code is something I wouldn’t know how to do, but its not the worst idea.



I am amazed at google counter just installed it at www.offshelf.net and it does not slow down performance and download time as many have reported earlier, maybe google fixed it maybe I did everything right and stats is gives me is trully amazing
Comment by albuk | May 4, 2006
Hi Nathan Weinberg,
That was a great information i came across…
I have an issue of the similar kind, can you please help me out ?
I have a following marketing & storefront module.
Marketing website http://www.xyz.com that has a Button called “BUY NOW” which takes to my storefront/buy site http://buy.xyz.com
Both the above websites have GA tracking code and am able to track the hits perfectly.
Now of recent we started promoting our website by putting PAID UP Adbanners on other websites…say www.worldads.com.
The way this works is, first the vistors clicks on ads and land on http://www.xyz.com, Select the product and then click the buy button (lands in http://buy.xyz.com)and start purchasing the product.
Under Ecommerce Analysis Reports i should be able to check how many customers are getting referred thru this advertising website.
In simple terms, i want to calculate the ROI on marketing advertisment expenditure.
Thanks in advance for your help !!!
Ameet
Comment by ameet | May 17, 2006
Ameet, I don’t have enough experience with Google Analytics to answer your question. However, based on what I think you’re asking, it should be relatively easy to implement. I’ve found that the people who work on Analytics are pretty good at answering your questions if you contact them via the Help section on the Analytics site, so try that. Wish I could be of more help.
Comment by Nathan Weinberg | May 17, 2006
[…] » Tracking Subdomains With Google Analytics » InsideGoogle » part of the Blog News Channel […]
Pingback by no idea | September 6, 2006
google analytics is trully amazing the graphics is merely outstanding, the functionality is superb, and it doesnt slow the download of the page as many people has reported it. I personaly recomend it to every one.
Comment by hypothyroid | September 23, 2006
[…] Xwindow 的美化字型設定 改天來試試看 Trac 介紹 & 0.8.4 中文版 原來版本控制系統可以這樣用 favicon 大觀 唔~ 好多喔 改天來把橘底白B給換掉 新縮寫 這是繼 i18n. l10n之後的新東西嗎? Tracking Subdomains With Google Analytics Google Analytics 不吃建在子網域下的東西? 沒注意到說, 這是讓 Google Analytics 照單收的方法… Blocking Google Analytics Tracking 不想讓 Google Analytics 收集個人資料的話, 看這裡 為民喉舌 ── 談輸入法 中文能力下降跟這個果然有關係 CSSVista 即時顯示一份 CSS 在 Fx 及 IE 下的效果, 免費軟體, 目前只有 win 版 Google搜索技巧2005版 筆記筆記 活動 布拉西梅利亞的: 唸過的課文串聯台灣篇。 umm… 我的國小國中課本咧? 高中的好像還留著 Orz 希爾@月の繭的: 唸過的課文串聯香港篇。 這邊是港版的唷 […]
Pingback by 遺忘の空島 v2 » Blog Archive » [網摘]這是不定時偏食網摘 | October 30, 2006