ahoy_matey 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -23
- data/app/controllers/ahoy/visits_controller.rb +13 -1
- data/lib/ahoy/controller_extensions.rb +17 -2
- data/lib/ahoy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e6b98a3bbcd3ab67886e562a6a285344a1d0b53
|
4
|
+
data.tar.gz: 97975b14612ca24bf380584f1020c39407a88894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3808dc8508cdbf29d1b018224179141d2588be09b76752035ddbb9f697ec22df873a0272de63e536575a6d887fcfee3997e9a9d3eddd7cfee02eafdbc68e8e9a
|
7
|
+
data.tar.gz: d8c2b3764a85b9f66d0b06da755260e501c089fe3cab7d8a584cf4e167803714b103f1cf6b692eea242e3571ceabda097acb8285da9f88cb79f3213a4b8a3e79
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ahoy
|
2
2
|
|
3
|
-
:fire: Simple, powerful visit tracking for Rails
|
3
|
+
:fire: Simple, powerful visit tracking for Rails
|
4
4
|
|
5
5
|
In under a minute, start learning more about your visitors.
|
6
6
|
|
@@ -8,9 +8,15 @@ In under a minute, start learning more about your visitors.
|
|
8
8
|
- location - country, region, and city
|
9
9
|
- technology - browser, OS, and device type
|
10
10
|
|
11
|
-
It’s all stored in **your database** so you can easily combine it with other
|
11
|
+
It’s all stored in **your database** so you can easily combine it with other data.
|
12
12
|
|
13
|
-
|
13
|
+
See which campaigns generate the most revenue effortlessly.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Order.joins(:visit).group("campaign").sum(:revenue)
|
17
|
+
```
|
18
|
+
|
19
|
+
## Ready, Set, Go
|
14
20
|
|
15
21
|
Add this line to your application’s Gemfile:
|
16
22
|
|
@@ -36,27 +42,26 @@ Lastly, include the javascript file in `app/assets/javascripts/application.js` a
|
|
36
42
|
|
37
43
|
When a person visits your website, Ahoy creates a visit with lots of useful information.
|
38
44
|
|
39
|
-
|
40
|
-
- location (country, region, and city)
|
41
|
-
- technology (browser, OS, and device type)
|
45
|
+
Use the `current_visit` method to access it.
|
42
46
|
|
43
|
-
|
47
|
+
The information is great on it’s own, but super powerful when combined with other models.
|
44
48
|
|
45
49
|
You can store the visit id on any model. For instance, when someone places an order:
|
46
50
|
|
47
51
|
```ruby
|
48
|
-
Order
|
49
|
-
|
50
|
-
|
51
|
-
)
|
52
|
+
class Order < ActiveRecord::Base
|
53
|
+
visitable # needs better name
|
54
|
+
end
|
52
55
|
```
|
53
56
|
|
57
|
+
The visit_id column will be automatically set. Magic!
|
58
|
+
|
54
59
|
When you want to explore where most orders are coming from, you can do a number of queries.
|
55
60
|
|
56
61
|
```ruby
|
57
|
-
Order.joins(:
|
58
|
-
Order.joins(:
|
59
|
-
Order.joins(:
|
62
|
+
Order.joins(:visit).group("referring_domain").count
|
63
|
+
Order.joins(:visit).group("device_type").count
|
64
|
+
Order.joins(:visit).group("city").count
|
60
65
|
```
|
61
66
|
|
62
67
|
## Features
|
@@ -65,21 +70,13 @@ Order.joins(:ahoy_visits).group("device_type").count
|
|
65
70
|
- Gracefully degrades when cookies are disabled
|
66
71
|
- Gets campaign from utm_campaign parameter
|
67
72
|
|
68
|
-
# How It Works
|
69
|
-
|
70
|
-
When a user visits your website for the first time, the Javascript library generates a unique visit and visitor id.
|
71
|
-
|
72
|
-
It sends the event to the server.
|
73
|
-
|
74
|
-
A visit cookie is set for 4 hours, and a visitor cookie is set for 2 years.
|
75
|
-
|
76
73
|
## TODO
|
77
74
|
|
78
75
|
- better readme
|
79
76
|
- model integration
|
80
77
|
- update visit when user logs in
|
81
78
|
- better browser / OS detection
|
82
|
-
- set
|
79
|
+
- set visit_id automatically on `visitable` models
|
83
80
|
|
84
81
|
## Contributing
|
85
82
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Ahoy
|
2
2
|
class VisitsController < ActionController::Base
|
3
|
+
before_filter :halt_bots
|
3
4
|
|
4
5
|
def create
|
5
6
|
visit =
|
@@ -23,7 +24,6 @@ module Ahoy
|
|
23
24
|
visit.campaign = (landing_uri.query_values || {})["utm_campaign"]
|
24
25
|
end
|
25
26
|
|
26
|
-
browser = Browser.new(ua: request.user_agent)
|
27
27
|
visit.browser = browser.name
|
28
28
|
|
29
29
|
# TODO add more
|
@@ -71,5 +71,17 @@ module Ahoy
|
|
71
71
|
render json: {id: visit.id}
|
72
72
|
end
|
73
73
|
|
74
|
+
protected
|
75
|
+
|
76
|
+
def browser
|
77
|
+
@browser ||= Browser.new(ua: request.user_agent)
|
78
|
+
end
|
79
|
+
|
80
|
+
def halt_bots
|
81
|
+
if browser.bot?
|
82
|
+
render json: {}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
74
86
|
end
|
75
87
|
end
|
@@ -1,8 +1,23 @@
|
|
1
1
|
module Ahoy
|
2
2
|
module ControllerExtensions
|
3
3
|
|
4
|
-
def
|
5
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.helper_method :current_visit
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def current_visit
|
11
|
+
if cookies[:ahoy_visit]
|
12
|
+
@current_visit ||= Ahoy::Visit.where(visit_token: cookies[:ahoy_visit]).first
|
13
|
+
if @current_visit
|
14
|
+
@current_visit
|
15
|
+
else
|
16
|
+
# clear cookie if visits are destroyed
|
17
|
+
cookies.delete(:ahoy_visit)
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
6
21
|
end
|
7
22
|
|
8
23
|
end
|
data/lib/ahoy/version.rb
CHANGED