Tracking 301 Redirects with Google Analytics

LaneMisc29 Comments


Please note this post was moved to this site from a previous site I maintained. I moved it simply to maintain the integrity of the posts and any related comments while not maintaining multiple sites for the same purpose. I point this out for the sole reason of highlighting the old post dates which should be taken in to consideration when considering any advise in this article.

If you are anything like me you have several domains that are related pointing, or redirecting, to your primary domain name. The extra domain names can be helpful in protecting your personal or business brand. Of course you are careful to have 301 redirects in place pointing to your main site in an effort to keep Google and the other search engines happy. However, how do you know how many visitors to your site are there because of your related domain names? My intention this morning was to find out.

For the sake of this example we will use my primary domain name of and a secondary domain of

Initially I started crafting a solution that was composed of funneling all traffic for to a simple PHP script that would load Google Analytics javascript to the browser before doing a meta refresh to another PHP script that would have the 301 redirect to I quickly realized that this would give me data in Google Analytics but would negatively effect any possible benefits of the secondary domains in SEO. Rather than page rank flowing down to the primary domain, it would be stopping at the tracker PHP script. This just won’t do so it was time to start thinking creatively.

After a few minutes it came to me. Why can’t I treat each secondary domain like a campaign and add the URL tracking data to the redirects? At first I was not sure it would work but a quick test proved it is quite effective at doing the 301 redirect and showing the redirect in Google Analytics under the Campaigns section. Now I can see how frequently my other domains send me traffic and understand how visitors to that domain differ from visitors to my primary domain.

This solution is amazingly quick to set up! First, go to the Google Campaign URL Builder tool page. You can get as complicated as you’d like with this but I stuck to just the required fields:

Click to embiggen.

First, you want to enter your primary domain name in Step 1. Next, set the campaign attributes you want to track in a way that will be meaningful to you. I am simply calling my source “redirects” so I can lump all the redirects in to a single reporting location. I am differentiating the sources with the secondary domain name as the medium. Since it is a required field I labeled the campaign name as 301_Redirects. Notice I included an underscore (_) rather than using a space to avoid any issues with URL string character encoding. Use values that make sense to you. Once you have filled in the form click the “Generate URL” button and lastly copy the URL from the box in step 4.

The hard part is now done! To implement this, simply open your .htaccess file for this secondary domain name and pasted this URL in with just a bit more code. Obviously you want to replace my campaign URL with your own:

[text light=”true”] RewriteEngine On
RewriteRule ^$ [R=301,L] [/text]

If you have only a single .htaccess file with all your domains pointing to the same site then you would add a condition to the redirect to only do so if the secondary domain name is used:

[text light=”true”] RewriteEngine On
RewriteCond %{HTTP_HOST} lanevance\.me
RewriteRule ^$ [R=301,L] [/text]

Once you have some traffic to your domain and data collecting in Google Analytics you can find your reports at:

You will now see your new campaign showing up in the Google Analytics campaigns list:

Click to embiggen.

And to see the details on which of your secondary domains brought the traffic to your site click in to the “301_Redirects” campaign:

Click to embiggen.

There you have it, a simple way to implement and track traffic from your secondary domain names. Have you found another way to track your domains? Let me know in the comments section below!

Photo Credit: Bull3t

29 Comments on “Tracking 301 Redirects with Google Analytics”

  1. Is there a way to not have it show the full url 9 in the browser address bar?

      1. is there any way to do this, if the redirected url is on the same domain as the destiation?

        like goes to

        its the same domain so I can’t really edit the htaccess, or can I?

        1. @aab071baf3a19f4704d3c0dbd0f92c1f:disqus Do you just want to redirect page.html to page2.html? Do you care about tracking this in a campaign in Google Analytics?

          Depending on your web host and the platform your site runs on, you should have the ability to modify the .htaccess file for your site. It is a very common feature for servers running Linux/FreeBSD and Apache.

    1. Thanks for the suggestion MattheGriz!

      By doing this you will be removing the Google variables (utm_*) from the query string. The unintended side effect will be when your web page loads the Google Analytics javascript will not have access to those variables and thus the action will not be recorded in your GA. You have to let the query string stay to be able to track the action.

      I suppose you could add some additional javascript to your target site after the GA code loads to redirect the page back to just the base domain. However, you will see 2 issues with this. First, that visitor will be counted as 2 visits rather than one, throwing off your stats. Secondly, your visitor may have already started reading or navigating your site when you force the refresh which may lead to a poor user experience. To me, the user experience is less impacted by just leaving the query string in place.

  2. I followed all the steps however my campaign is not showing up at all in my Google Analytics account. What did I do wrong?

    1. @Domenic1, can you give us the domains you are trying this on? Sometimes it may take a day for the info to start showing up in Google Analytics.

  3. This worked, I just have a bunch of sub-domain landing pages… ie.,, etc. So the only difference was that I created the campaign and just stuck that directly into my SUB-DOMAIN record. I’m not interested in the SEO traffic. It worked perfectly, now I can see all my referring 301 sub-domains.

    1. Thanks for the additional suggestion on how to implement this! Glad this helped solve your problem!

  4. Hi,

    I am new at this so please bear with me.

    Do you have to add url generated by the Google URL Builder to the htaccess file or can it be used as the redirect itself? We have purchased a number of URLs to track direct mail campaigns from Go Daddy, and they offer a redirect screen instead of having to host each of these URLs separately. You are supposed to use their form to enter the URL you want to be redirected to, and then they automatically take care of updating DNS settings. So would it work to simply put the entire URL generated by the URL Builder here, or would this not work?


  5. Hey Lane, just to double check. This will allow you to know who got to your website via a certain domain… but you won’t know how they got to the domain right?

  6. Pingback: How to use Google Analytics to Track Printed Media Marketing Campaigns. | Showcase creativeShowcase creative

  7. Nice post – thanks – quick question:

    Scenario: User goes to google and performs a search – one of my old pages shows in the results (a page I have just created a 301 quick redirect for using an app within wordpress) – They click on my result – are redirected to the new page.

    Question: Will this user show-up in Google analytics as a direct visitor? If not, how would they show as far as their traffic source?

  8. Hey Lane, just found your post here. I was using a javascript to redirect after page load. That way the GA code ran and then the redirect. First issue, the problem of non-JS users not getting the redirect. So I added a regular “click here” link on the page. Second, I did not know if there were any SEO penalties for this method. Have you learned of any other techniques recently?

  9. Perfect solution for a need I had. I’ve been using Google Campaigns a lot of late, for various purposes.

    Recently, I set up some 301 redirects in a site’s .htaccess file to accommodate my client’s direct mail campaigns. In those campaigns, they printed short “alias URLs” to redirect to pages whose actual URLs are too long (and too easy to either misspell
    or give up on).

    For example:
    redirects to

    But when I checked Google Analytics, I realized (duhhh) that the 301 redirects cannot be detected.

    I just implemented your solution, and voila!

    Thanks much.

  10. Hi,

    I have created as per your process but me it’s not working here is the code
    RewriteEngine On
    RewriteCond %{HTTP_HOST}
    RewriteCond %{HTTP_HOST}
    RewriteRule ^$
    RewriteRule ^$

    The resulted URL home pare URL is comming like this(Search bar)

    If i entered my home page URL

    In this case also the URL is comming like this

    If you don’t mine please let me know any syntex changes for this code

    Thanks & Regards


  11. Followed this and can’t get it to work. The campaign shows up in GA but no info associated with it (not set).

    RewriteCond %{HTTP_HOST} ^$ [OR]
    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^/?$ “” [R=301,L]

  12. Thanks! It worked like a charm. Not sure what the .htaccess is but I used the URL maker, went to my domain manager in GoDaddy and replaced my simple URL with the new URL in the redirect 301 section. Now I can see it in my campaign section in analytics.

  13. Hello, i have a 2nd url that is shorter than my main url and i use the 2nd the all the time on social media. When you visit the shorter one, it forwards you on to the main site, which is linked to Google Analytics. I followed your steps above and generate my code, but my question is, do i just follow the first “Re-Write Engine” box you listed or do i do both? I just want to be able to track when ppl use my links and track which one is being used more. Thank you for your time & any help you can offer.

    1. This is what my current .htaccess editor looks like:

      # BEGIN WordPress

      RewriteEngine On
      RewriteBase /
      RewriteRule ^index.php$ – [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]

      # END WordPress

      This is what Google code generated following your steps:

      Please advise what i should put in the htaccess editor?

Leave a Reply

Your email address will not be published. Required fields are marked *