Catching UTM Params in Rails

折月煮酒 提交于 2019-12-06 08:37:17

问题


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?


回答1:


Use params to access them:

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


来源:https://stackoverflow.com/questions/12847889/catching-utm-params-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!