ahoy_matey 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0885adb69bce04e71f7fd609edc8c780355faf3d
4
- data.tar.gz: 0f28e71f18107dfd51a323a451e1c688dc14434c
3
+ metadata.gz: 2e6b98a3bbcd3ab67886e562a6a285344a1d0b53
4
+ data.tar.gz: 97975b14612ca24bf380584f1020c39407a88894
5
5
  SHA512:
6
- metadata.gz: ee3c5d227ab4ee129e986bc315acac53569664f99c99e5a131b286c6a1f6822ac148891e7c44e60e0edb5fc76e5d494e5a665f89fdba03a190c442db134aecac
7
- data.tar.gz: 1ecec9955ebed58e57ea78e22fafaaae7a8fc8c24a4f3debc928a5da109fc8be4db9174c257c5c32b1dde228d13aa53745d4b4c3c57d99625a702be6a3c673cd
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 models.
11
+ It’s all stored in **your database** so you can easily combine it with other data.
12
12
 
13
- ## Ready, Set, Go!
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
- - traffic source (referrer, referring domain, campaign, landing page)
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
- This information is great on it’s own, but super powerful when combined with other models.
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.create!(
49
- ahoy_visit_id: ahoy_visit.id,
50
- # ... more attributes ...
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(:ahoy_visits).group("referring_domain").count
58
- Order.joins(:ahoy_visits).group("city").count
59
- Order.joins(:ahoy_visits).group("device_type").count
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 ahoy_visit_id automatically on `visitable` models
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 ahoy_visit
5
- @ahoy_visit ||= Ahoy::Visit.where(visit_token: cookies[:ahoy_visit]).first if cookies[:ahoy_visit]
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
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_matey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane