Currently, I use Google Analytics for www.example.com. example.com is also added to GA and shows "Tracking not installed".

Recently I added rewrite rule (301 redirect) to redirect all requests from www.example.com to example.com.

How should I move/update GA code to properly track visits to example.com?

3 Answers 3


Check out the Google Articles on how to do it.

One thing Google doesn't mention for Asynchronous tracking. If you have DomainNames set within your GA account you will need to have the middle line from below

var _gaq = _gaq || [];
           _gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
           _gaq.push(['_setDomainName', 'www.example.com']);

Adding that line will make sure you are tracking against the correct domain.


If I understood this correctly, you want to have all visits to the site redirected to the domain (not the www subdomain), but you have the GA code set up to track the www subdomain. I think the best way to do it is edit the settings in GA to point to example.com. When you go to GA, you should have two links in the right of the account name, edit and delete. Clicking edit will allow you to change the website URL so you're good to go and still get to keep the old data in as well.


If the code is included in the pages it's already working. You're able to break out reporting in Analytics to give you different reports based on the sub-domain the code is sitting on. If you want to create different accounts for each you can, which requires a different UA ID to be specified in the code. However if you're fine with doing it on the reporting side you're already done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.