title: How to create redirect url for tracking?
body: <p>I saw multiple websites have this functionality but Google can't find a clear way to do this.</p>
  
  <p>In many sites, all their external / internal links first start with their domain name followed with parameters or a hash string, for example -- <code>http://sitename.com/?hashurl1</code>. When user clicks that link, user will be redirected to the other site. With this mechanism, they can track user activities, like Slickdeals.</p>
  
  <p>Is there an library or tool we can use to archive this functionality? </p>
  
  <p>I was thinking about using a database to store all the links and write a program to do the redirect and logging. However, I don't want to start from scratch if there is already an open-source project I can use directly.   </p>
  
  <p>I found some commercial service and plugin that has this functionality, but I want to understand the underlying detail of it. </p>
  
  <p>Add: 
  What I need are two things. 
  1. When a user post an arbitrary URL, system will shorten it, just like what Twitter do when a user tweet a url.
  2. Track anyone click that URL.</p>
  
  <p>Now I think about combining goo.gl with Google analytics, use AJAX or do it in server site to shorten url when user post a content. But Goo.gl only provide statistic for a single url. How to connect it with  Google analytics to get whole site activities?    </p>