Wildcards In Rails Redirects

The captured wildcard in a Rails 3 route can be used in the redirect method:

match 'via/:source' => redirect('/?utm_source=%{source}')

This example is intended to improve metrics for customer acquisition campaigns. utm_source is for Google Analytics, which KISSMetrics logs as Ad Campaign Hits.

The URLs are now friendlier for sharing:


When the user clicks them, they’ll be redirected to:


The URLs are also encapsulated. If the Google Analytics params need to change, the developer can edit config/routes.rb and deploy. All past routes will still work.