Visits are stored in your database so you can easily combine them with other data.
- traffic source - referrer, referring domain, landing page, search keyword
- location - country, region, and city
- technology - browser, OS, and device type
- utm parameters - source, medium, term, content, campaign
See which campaigns generate the most revenue effortlessly.
How It Works
When someone visits your website, Ahoy creates a visit with lots of useful information.
current_visit method to access it.
Explore your visits with queries like:
Visit.group(:search_keyword).count Visit.group(:country).count Visit.group(:referring_domain).count
<%= line_chart Visit.group_by_day(:created_at).count %>
This information is great on its own, but super powerful when combined with other models.
Let’s associate orders with visits.
class Order < ActiveRecord::Base visitable end
When a visitor places an order, the
visit_id column is automatically set.
See where orders are coming from with simple joins:
Order.joins(:visit).group("referring_domain").count Order.joins(:visit).group("city").count Order.joins(:visit).group("device_type").count
Ahoy automatically attaches the
current_user to the
With Devise, it will attach the user even if he / she signs in after the visit starts.
With other authentication frameworks, add this to the end of your sign in method:
if current_visit current_visit.user ||= current_user current_visit.save! end
To see the visits for a given user, create an association:
class User < ActiveRecord::Base has_many :visits end
user = User.first user.visits
Use UTM parameters to track campaigns. This is great for emails and social media. Just add them to your links and Ahoy will pick them up.
Ahoy uses Geocoder for IP-based geocoding.
- Excludes bots
- Degrades gracefully when cookies are disabled
Add this line to your application’s Gemfile:
And run the generator. This creates a model to store visits.
rails generate ahoy:install rake db:migrate
//= require jquery //= require ahoy
We recommend using traditional analytics services like Google Analytics as well.
- simple dashboard
- hook to store additional fields
- turn off modules
Everyone is encouraged to help improve this project. Here are a few ways you can help: