Search code examples
ruby-on-railsgoogle-analyticsanalytics

Catching UTM Params in Rails


I am trying to catch the UTM Params in the URL to add Source, Campaign etc to a User Account.
Sadly, I can't seem to figure out how to catch those params. As of know I following the Blog Article http://www.matthuggins.com/articles/tracking-new-user-registrations-by-source-search-terms

So, in my Application Controller I have following:

ApplicationController.class_eval do
  before_filter :capture_referrer

  protected
    def capture_referrer
      session[:referrer] = request.env['HTTP_REFERER'] if !session[:referrer]
    end
end

In the create Action in the user controller

@user.referrer = session[:referrer]

and in the USer Model itself:

 def set_traffic_source
  if self.referrer
    url = URI.parse(self.referrer)
    self.source ||= uri.host.downcase.gsub(/^www\./, '')
    self.traffic_keywords ||= search_termins(uri)
  end
end

This all works fine, for catching the referer - But I actualy want to read out the UTMs passed into by the URI. How would I go about this?


Solution

  • Use params to access them:

    params[:utm_source]
    params[:utm_campaign]
    params[:utm_medium]