No commit activity in last 3 years
No release in over 3 years
Help to parse referer url for get user search query and page of search engine results. Work with Google and Yandex for now.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

#SearchEngineReferer Get meta information from search engine`s referer for

  • google.com
  • bing.com
  • yandex.ru
  • go.mail.ru
  • nova.rambler.ru

##Instalation Add the folowing line to Gemfile and then run bundle command.

gem 'search_engine_referer'

##Usage In your code use:

referer = SearchEngineReferer.parse('http://google.com?q=ruby&start=20')
referef.search_engine # => :google
referer.page # => 3
referer.query # => 'ruby'

non_search_enfine_referer = SearchEngineReferer.parse('http://example.com?q=ruby')
non_search_enfine_referef # => nil

##Middleware Tiny middleware provided. It adds search_engine_referer key to env with found referer. Examples:

  • Uses HTTP_REFERER from env

    use SearchEngineReferer::Middleware
  • Uses CUSTOM_ENV_KEY for referer lookup

    use SearchEngineReferer::Middleware, 'CUSTOM_ENV_KEY'
  • Uses provided proc for referer lookup

    use SearchEngineReferer::Middleware do |env|
      env['action_pack.cookies']['referer']
    end

##Controller Helpers Its add helpers for controllers and views: search_engine_referer and search_engine_query. search_engine_referer_source method for referer source manipulations. By default it returns request.referer. It can be overwritten in controller, for example:

def search_engine_referer_source
  cookies[:search_engine_referer] || super
end

Note that helpers will use env['search_engine_referer'] if it provided by middleware

##Development Fully tested pull requests are welcome.