简体   繁体   English

如何知道游客来自哪里?

[英]How to know from where visitors are coming?

I have a website with google Analytics, which provides information about from where visitors are coming. 我有一个带有google Analytics(分析)的网站,该网站提供有关访问者来自何处的信息。

My website has a registration form, and I would like to know from where the new register is coming (but without asking him). 我的网站上有一份注册表,我想知道新的注册表来自何处(但不问他)。

For example, suppose a user were searching "cars" in google.com, clicked my link (not adwords), and were registering in my website. 例如,假设某个用户正在google.com中搜索"cars" ,点击了我的链接(而非adwords),并正在我的网站中注册。 How and from where can I read and save that this user was looking for "cars" in google.com and clicked in my link? 如何以及从哪里可以读取并保存该用户在google.com中寻找"cars"并点击了我的链接? Are there any cookies generated by google? 谷歌有没有生成cookies?

You can store the referrer where the user came from in its session: 您可以在用户的​​会话中存储引用者:

# in application_controller.rb
before_filter :store_referrer

private
def store_referrer
  referer = request.referer.presence
  if referer && !referer.start_with?('http://your.domain')
    session[:referer] ||= referer 
  end
end

When the user signs up, you just pass that value to the user: 用户注册后,只需将该值传递给用户:

User.new(params[:user].merge(:referer => session[:referer]))

You User should have a referer= method that handles that url. 您的User应该有一个referer=方法来处理该网址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM