Question

I'm trying to create a simple URL redirection page, and would like to track the analytics of my page using Google analytics.

The steps would be:

  1. User receives a pamphlet in the mail for mywebsite.com
  2. User types mywebsite.com into their browser
  3. Mywebsite.com is a 301 redirect to another website (ex. kiva.org/campaign1234/long-ugly-url)
  4. How do I track details of step 2?

Basically, mywebsite.com is taking the place of a URL shortener service like bit.ly. However, due to the 301 redirect I'm unsure how I would track analytics of mywebsite.com. Can you help me figure out what I need to do to track google analytics for mywebsite.com? If not google analytics, anything else with date, number of clicks, browser, and city information would work fine too.

Was it helpful?

Solution

Rather than using Javascript (which does not really allow for a 301 redirects, whith the possible exception of serverside javascript like node.js apps) you should use Googles measurement protocol, which allows you to create serverside implementations of GA indepentently from the programming language (as long as the analytics property you track to is set up for UNiversal Analytics).

Of course you do not need GA, you could also catch the request from the browser and store it to a database (but you tagged your question Google Analytics so I assume you want to use GA).

OTHER TIPS

You could write the redirection in JavaScript, and therefore also have the analytics code in it. See this question for how to do redirects in JavaScript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top