|
| 1 | +# Ahoy |
| 2 | + |
| 3 | +Simple, powerful visit tracking for Rails. |
| 4 | + |
| 5 | +## Get Started |
| 6 | + |
| 7 | +Add this line to your application’s Gemfile: |
| 8 | + |
| 9 | +```ruby |
| 10 | +gem "ahoy_matey" |
| 11 | +``` |
| 12 | + |
| 13 | +And run the generator. This creates a migration to store visits. |
| 14 | + |
| 15 | +```sh |
| 16 | +rails generate ahoy:install |
| 17 | +rake db:migrate |
| 18 | +``` |
| 19 | + |
| 20 | +Next, include the javascript file in your `app/assets/javascripts/application.js` after jQuery. |
| 21 | + |
| 22 | +```javascript |
| 23 | +//= require jquery |
| 24 | +//= require ahoy |
| 25 | +``` |
| 26 | + |
| 27 | +That’s it. |
| 28 | + |
| 29 | +## What You Get |
| 30 | + |
| 31 | +When a person visits your website, Ahoy creates a visit with lots of useful information. |
| 32 | + |
| 33 | +- source (referrer, referring domain, campaign, landing page) |
| 34 | +- location (country, region, and city) |
| 35 | +- technology (browser, OS, and device type) |
| 36 | + |
| 37 | +This information is great on it’s own, but super powerful when combined with other models. |
| 38 | + |
| 39 | +You can store the visit id on any model. For instance, when someone places an order: |
| 40 | + |
| 41 | +```ruby |
| 42 | +Order.create!( |
| 43 | + visit_id: ahoy_visit.id, |
| 44 | + # ... more attributes ... |
| 45 | +) |
| 46 | +``` |
| 47 | + |
| 48 | +When you want to explore where most orders are coming from, you can do a number of queries. |
| 49 | + |
| 50 | +```ruby |
| 51 | +Order.joins(:ahoy_visits).group("referring_domain").count |
| 52 | +Order.joins(:ahoy_visits).group("city").count |
| 53 | +Order.joins(:ahoy_visits).group("device_type").count |
| 54 | +``` |
| 55 | + |
| 56 | +## Features |
| 57 | + |
| 58 | +- Excludes search engines |
| 59 | +- Gracefully degrades when cookies are disabled |
| 60 | +- Gets campaign from utm_campaign parameter |
| 61 | + |
| 62 | +# How It Works |
| 63 | + |
| 64 | +When a user visits your website for the first time, the Javascript library generates a unique visit and visitor id. |
| 65 | + |
| 66 | +It sends the event to the server. |
| 67 | + |
| 68 | +A visit cookie is set for 4 hours, and a visitor cookie is set for 2 years. |
| 69 | + |
| 70 | +## Contributing |
| 71 | + |
| 72 | +Everyone is encouraged to help improve this project. Here are a few ways you can help: |
| 73 | + |
| 74 | +- [Report bugs](https://github.com/ankane/ahoy/issues) |
| 75 | +- Fix bugs and [submit pull requests](https://github.com/ankane/ahoy/pulls) |
| 76 | +- Write, clarify, or fix documentation |
| 77 | +- Suggest or add new features |
0 commit comments