Search analytics made easy
- view searches in real-time
- track conversions week over week
- monitor the performance of top searches
Works with Rails 3.1/Rails 4 and any search engine, including Elasticsearch, Sphinx, and Solr
An amazing companion to Searchkick
Add this line to your application’s Gemfile:
gem "mongoid-searchjoy"Next, add the dashboard to your config/routes.rb.
mount Mongoid::Searchjoy::Engine, at: 'admin/searchjoy'Be sure to protect the endpoint in production - see the Authentication section for ways to do this.
Track searches by creating a record in the database.
Mongoid::Searchjoy::Search.create(
search_type: 'Item', # typically the model name
query: 'apple',
results_count: 12
)With Searchkick, you can use the track option to do this automatically.
Item.search 'apple', track: trueIf you want to track more attributes, add them to the searchjoy_searches table. Then, pass the values to the track option.
Item.search 'apple', track: {user_id: 1, source: 'web'}It’s that easy.
First, choose a conversion metric. E.g. an item added to the cart from the search results page counts as a conversion.
Next, when a user searches, keep track of the search id. With Searchkick, you can get the id with @results.search.id.
When a user converts, find the record and call convert.
search = Mongoid::Searchjoy::Search.find params[:id]
search.convertBetter yet, record the model that converted.
item = Item.find params[:item_id]
search.convert(item)Don’t forget to protect the dashboard in production.
Set the following variables in your environment or an initializer.
ENV["SEARCHJOY_USERNAME"] = "andrew"
ENV["SEARCHJOY_PASSWORD"] = "secret"authenticate :user, lambda{|user| user.admin? } do
mount Mongoid::Searchjoy::Engine, at: "admin/searchjoy"
endTo change the time zone, create an initializer config/initializers/mongoid_searchjoy.rb with:
Mongoid::Searchjoy.time_zone = 'Europe/Berlin' # defaults to Time.zoneChange the number of top searches shown with:
Mongoid::Searchjoy.top_searches = 500 # defaults to 100Show the conversion name in the live stream.
Mongoid::Searchjoy.conversion_name = proc { |model| model.name }- customize views
- analytics for individual queries
- group similar queries
- track pagination, facets, sorting, etc
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new feature