在Rails中捕捉UTM参数 [英] Catching UTM Params in Rails

查看:123
本文介绍了在Rails中捕捉UTM参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图捕捉URL中的UTM参数,将Source,Campaign等添加到用户帐户中。

可悲的是,我似乎无法弄清楚如何捕捉这些参数。据我所知,我遵循博客文章 http:/ /www.matthuggins.com/articles/tracking-new-user-registrations-by-source-search-terms



因此,在我的应用程序控制器I有以下几种:

pre $ Application $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b def capture_referrer
session [:referrer] = request.env ['HTTP_REFERER'] if!session [:referrer]
end
end

在用户控制器中创建Action

  @ user.referrer = session [:referrer] 

以及USer模型本身:

  def set_traffic_source 
如果self.referrer
url = URI.parse(self.referrer)
self.source || = uri.host.downcase.gsub(/ ^ www\。/,'')
self.traffic _keywords || = search_termins(uri)
end
end

很好,用于捕获引用者 - 但我实际上想读出由URI传入的UTM。

使用 params 来访问它们:

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


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?

解决方案

Use params to access them:

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

这篇关于在Rails中捕捉UTM参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆