Track Vanity URLs Using Redirects

This post shows how to set up 301 redirects to track vanity URLs in analytics tools like Google Analytics and IBM Digital Analytics (Coremetrics). This will ensure marketing query strings are appended to the destination page, so that marketing sources can be correctly tracked.

Vanity URLs for Marketing

Adding tracking parameters to URLs is an essential part of a marketing campaign strategy, as these tracking parameters enable you to see how your marketing efforts are performing. However, sometimes it's not optimal to hand out a long link filled with tracking parameters, for example on TV or through direct mail. One solution is to shorten your URL using a service like bit.ly, but that may seem unprofessional, harder to remember, or just not as nice as using your own domain name. So, in those cases, the best solution is to hand out a "vanity" URL that is easy to remember and share.

An example of a short and memorable vanity URL would be www.site.com/promo.

Vanity URL Redirects

Campaign tracking involves adding query strings (aka marketing tags) to the end of marketing links. Vanity URLs don't contain any query strings, so instead they need to redirect to a full URL containing tracking parameters. Example:

Vanity URL:
www.site.com/promo

Redirected URL
www.site.com/apparel/sweater?utm_medium=redirect&utm_source=promo

The example above contains tracking parameters for Google Analytics, but you could just as easily apply cm_mmc parameters for Coremetrics, or your custom tracking parameters for Omniture.

Redirect Technical Implementation

Vanity URL redirects should be implemented as a 301 redirect. There are many methods for implementing redirects, and it will depend on your setup. However if you're doing this yourself using a CMS like WordPress, these are the steps to set up a redirect for vanity URLs:

  1. Open and edit your .htaccess file (you can just create a new text file named .htaccess if there isn't one there already).
    ❓ The .htaccess file is a text file you can most easily access by a plugin  (e.g. Yoast's popular WordPress SEO plugin).  Alternately you can access it via FTP or through the File Manager in cPanel. It's usually located in the root directory and hidden by default, so you might need to edit the Settings and check a box called Show Hidden Files. show hidden files
  2. Create a backup copy of the existing .htaccess file. Don't skip this part - it's very easy to break your site if you make a mistake in your .htaccess file.
  3. Add the following text anywhere in the .htaccess file:
    [GA example]

     Redirect 301 /promo http://www.site.com/?utm_source=promo&utm_medium=redirect&utm_campaign=Feb_promo

    ===============OR====================

    [IBM Analytics example]

    Redirect 301 /promo http://www.site.com/?cm_mmc=promo-_-redirect-_-Feb_promo-_-XYZ

    Substitute in your page names and desired tracking parameters. Note that you don't include the hostname on the first part, but you do on the second.

  4. In the above example, /promo refers to the vanity page path you're redirecting from, and http://www.site.com/ refers to the page you’re redirecting to. You can redirect to any page on your site; if you wanted to redirect to a page other than a homepage, for example to '/newpage',  you’d implement the redirect as follows:
    Redirect 301 /promo http://www.site.com/newpage?utm_source=promo&utm_medium=redirect&utm_campaign=Feb_promo

Conclusion

Following the above steps will let you distribute a simple vanity URL that redirects to a fully tagged destination URL for analytics tracking.

23 thoughts on “Track Vanity URLs Using Redirects”

  1. Hi Ana,
    I have a question here. Currently we have used links like http://www.mysite.com/name-of-campaign (such as email, kiosk, directmail) that all go to the same destination page. We can already get the destination, but how can we track which URL the users came through? Also, what are the mistakes to avoid (what is bad practice/to definitely avoid)?

      • Hi Jonathan! Unfortunately I don’t exactly understand the question. Do you mean you have links like mysite.com/email, mysite.com/kiosk, etc, that all redirect to the same URL (say, mysite.com) so you want to be able to distinguish them? If so I’d suggest adding GA UTM parameters to the redirect, basically as described in this post and the one you linked to. So for example they would redirect to mysite.com?utm_medium=redirect&utm_source=email. Is there a reason you don’t want to use this method? If I better understand what you’re trying to do perhaps I can think of another solution for you.

  2. Thanks Ana,
    I had a couple of issues with using the URL builder. GA seemed to strip URL parameters off the pages in the dashboard. I was also concerned about duplicate content. Is that an issue? Also, I saw in another post that you could use # instead of ?. Is this true?
    I think there was one other question about using URL parameters, but cannot remember it.

    • In general, GA doesn't strip URL parameters out of the page reports, but its own UTM parameters are a special case since they show up automatically anyway in the marketing reports. So to see your data you'd go to Traffic Sources > Sources > All Traffic. Alternately, if you wanted to see it tied to landing page, you could go to Content > Site Content > Landing Pages and choose Secondary Dimension = Medium.
      There's no issue with duplicate content, again GA will just process the UTM parameters and leave everything else the same.
      As for using #, by default you have to use the ? mark, but if you really wanted to use # you could by setting a special option in the main tracking block. Not sure why you'd do this though since if you turned on that option it would just interpret the # exactly the same as the ? and essentially make no difference at all.

  3. Ana, I created the URL, entered a new 301 (in Drupal) and directed it to that URL, then I followed it and looked in GA. Not there. Am I doing something wrong? Has to be something basic.

  4. I will, but yesterday same result. I do want to ask, when you look for the link in GA, it will be /mylink?param1=foo&param2=bar
    Correct? I am only noticing hits on /mylink. Is that how it is supposed to be or will GA show the parameters?

    • GA will show the parameters except in the following cases:
      1) you're using GA's own "utm" parameters. These do get stripped off and interpreted as marketing tags.
      2) you have a profile filter in place that strips them out (check in Admin settings).

      In general GA will report exactly what shows up in the URL bar. After the redirect, are you seeing the full URL + parameters in the URL bar?

  5. Well I put in my own parameters after the utm parameters and the links showed in GA! But I tried one with only my own param and that showed up as well. So what are the utm params for? Are they used for classification/grouping under campaigns?

      • Hi Ana! I had another question: is there any way to track exit clicks? Not the final destination, but for ex., tracking URL redirects from our site (on Drupal) that go offsite? I hope this is not too obvious.

      • Thanks Ana, what about a link like mysite.com/mycampaign that is a 301 to another site? There would be no loading of GA as the redirect is immediate. Possible?

      • Do you mean an outbound link from your site to another site or a link to your site? In the first case you can track it as described, just fire an event when the user clicks. If you mean a link to your site that doesn't actually go to your site (because it redirects) then you can't track it because, as you note, the GA code doesn't load.

  6. Thanks Ana. I mean the latter, e.g. I am using a link in an email like http://www.mysite.com/campaign1 that goes to another site. What I was doing was making a page that had some Javascript on it that forwarded the user after the page loads. That way the GA script loaded before it sent the user to the other site. I know there must be some security and other concerns with this. But thank you once more!

    • Ana, sorry to post again, but my last was intended to be a question: what are the risks of using JS like I had been doing?

      • Hey Jonathan, there are issues related to latency and not passing on cookie or tag values from prior pages. Also search engines don't like it very much (though that's improved in recent years) so your SEO may suffer. I'm not too familiar with the details as I've always just avoided them - I'm sure you can find more comprehensive info out there if you need it.

  7. can anybody help me out?
    I have to track traffic from third party link for my website.
    How would it be the code for the same. I have used 301 redirect but not working

    • Hey Pravin, sorry, I would need more information. What happens when you click on the link, do you see the "utm" parameters in the URL on the destination page?

  8. I'm a student working on a class project with several competing groups within the class. Can I use this to create a central class hub web page where each group has their own personal redirect link? Ideally, every link would go to the same hub page while allowing the group that sent the reference to get credit for it. Thank you!

Comments are closed.