ahoy_matey 0.1.1 → 0.1.2

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: 93699ebff0f9bfc35b50d48e7ff477963114b1b2
4
- data.tar.gz: 848e8110b3cedef57143e54d8415e23a5e650c66
3
+ metadata.gz: e8ac2f7e33c48f8b761a8ffee2ae5cd715e52849
4
+ data.tar.gz: 7d069547085fb036b792492826c7a1fb81363367
5
5
  SHA512:
6
- metadata.gz: fbd26a7a790231a5b8e8b3dfa2d9b7b99b9e87cd862cffbd15d53ae4a003d1e18afea1f4f46c34576c3a5d6a5f25f4f9f39cfdbb94ab9e58a24488df85c18119
7
- data.tar.gz: b4046b11ece28d61d46f852bf3b0a699f52d24d34faffad687dce093260fcc564d8a5aee29e3583ec3f354fa3fb17d1e68721e7c2419551ab7e0f0e006e46ee3
6
+ metadata.gz: 301bf689ed83f0f44a5c13cc4c1a53707e7ee5fbf7fe53936d560224a647c6d379be3c67834f15d5ec855d0f80081bd37dd4c6db4b9ab573c5ce3661902fb91c
7
+ data.tar.gz: 3a3016d19a6f00750362bcd9a36992cb04b673bc77832c752cd4ea1fdc065e4faff8f06c38dbb628a9c078c291a0989cc15140966465a453708a572b42d4a31f
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## 0.1.2
2
+
3
+ - Attach user on Devise sign up
4
+ - Ability to specify visit model
5
+
6
+ ## 0.1.1
7
+
8
+ - Made most database columns optional
9
+ - Performance hack for referer-parser
10
+
11
+ ## 0.1.0
12
+
13
+ - First major release
data/README.md CHANGED
@@ -6,10 +6,10 @@ Visits are stored in **your database** so you can easily combine them with other
6
6
 
7
7
  You get:
8
8
 
9
- - traffic source - referrer, referring domain, landing page, search keyword
10
- - location - country, region, and city
11
- - technology - browser, OS, and device type
12
- - utm parameters - source, medium, term, content, campaign
9
+ - **traffic source** - referrer, referring domain, landing page, search keyword
10
+ - **location** - country, region, and city
11
+ - **technology** - browser, OS, and device type
12
+ - **utm parameters** - source, medium, term, content, campaign
13
13
 
14
14
  See which campaigns generate the most revenue effortlessly.
15
15
 
@@ -17,30 +17,6 @@ See which campaigns generate the most revenue effortlessly.
17
17
  Order.joins(:visit).group("utm_campaign").sum(:revenue)
18
18
  ```
19
19
 
20
- Goes great with services like [Google Analytics](http://www.google.com/analytics/)
21
-
22
- ## Ready, Set, Go
23
-
24
- Add this line to your application’s Gemfile:
25
-
26
- ```ruby
27
- gem 'ahoy_matey'
28
- ```
29
-
30
- And run the generator. This creates a model to store visits.
31
-
32
- ```sh
33
- rails generate ahoy:install
34
- rake db:migrate
35
- ```
36
-
37
- Lastly, include the javascript file in `app/assets/javascripts/application.js` after jQuery.
38
-
39
- ```javascript
40
- //= require jquery
41
- //= require ahoy
42
- ```
43
-
44
20
  ## How It Works
45
21
 
46
22
  When someone visits your website, Ahoy creates a visit with lots of useful information.
@@ -61,7 +37,7 @@ Visit.group(:referring_domain).count
61
37
  <%= line_chart Visit.group_by_day(:created_at).count %>
62
38
  ```
63
39
 
64
- ## The Power
40
+ ### The Power
65
41
 
66
42
  This information is great on its own, but super powerful when combined with other models.
67
43
 
@@ -77,7 +53,7 @@ When a visitor places an order, the `visit_id` column is automatically set.
77
53
 
78
54
  :tada: Magic!
79
55
 
80
- To see where your orders are coming from, use:
56
+ See where orders are coming from with simple joins:
81
57
 
82
58
  ```ruby
83
59
  Order.joins(:visit).group("referring_domain").count
@@ -85,12 +61,21 @@ Order.joins(:visit).group("city").count
85
61
  Order.joins(:visit).group("device_type").count
86
62
  ```
87
63
 
88
- ## Users
64
+ ### Users
89
65
 
90
66
  Ahoy automatically attaches the `current_user` to the `current_visit`.
91
67
 
92
68
  With [Devise](https://github.com/plataformatec/devise), it will attach the user even if he / she signs in after the visit starts.
93
69
 
70
+ With other authentication frameworks, add this to the end of your sign in method:
71
+
72
+ ```ruby
73
+ if current_visit
74
+ current_visit.user ||= current_user
75
+ current_visit.save!
76
+ end
77
+ ```
78
+
94
79
  To see the visits for a given user, create an association:
95
80
 
96
81
  ```ruby
@@ -106,13 +91,9 @@ user = User.first
106
91
  user.visits
107
92
  ```
108
93
 
109
- ## Location
110
-
111
- Ahoy uses [Geocoder](https://github.com/alexreisner/geocoder) for IP-based geocoding.
112
-
113
- ## UTM Parameters
94
+ ### UTM Parameters
114
95
 
115
- Use UTM Parameters to track campaigns. [This is great for emails and social media](http://www.thunderseo.com/blog/utm-parameters/). Just add them to your links and Ahoy will pick them up.
96
+ Use UTM parameters to track campaigns. [This is great for emails and social media](http://www.thunderseo.com/blog/utm-parameters/). Just add them to your links and Ahoy will pick them up.
116
97
 
117
98
  ```
118
99
  http://datakick.org/?utm_medium=email&utm_campaign=newsletter&utm_source=newsletter-2014-03
@@ -124,10 +105,57 @@ or
124
105
  http://datakick.org/?utm_medium=twitter&utm_campaign=social&utm_source=tweet123
125
106
  ```
126
107
 
127
- ## More Features
108
+ ### Location
109
+
110
+ Ahoy uses [Geocoder](https://github.com/alexreisner/geocoder) for IP-based geocoding.
111
+
112
+ ### Multiple Subdomains [master]
113
+
114
+ To track visits across multiple subdomains, add this to your layout **before** the javascript files.
115
+
116
+ ```html
117
+ <script>
118
+ var Ahoy = {"domain": "yourdomain.com"};
119
+ </script>
120
+ ```
121
+
122
+ ### More
128
123
 
129
124
  - Excludes bots
130
125
  - Degrades gracefully when cookies are disabled
126
+ - Don’t need a field? Just remove it from the migration
127
+
128
+ ## Installation
129
+
130
+ Add this line to your application’s Gemfile:
131
+
132
+ ```ruby
133
+ gem 'ahoy_matey'
134
+ ```
135
+
136
+ And run the generator. This creates a model to store visits.
137
+
138
+ ```sh
139
+ rails generate ahoy:install
140
+ rake db:migrate
141
+ ```
142
+
143
+ Lastly, include the javascript file in `app/assets/javascripts/application.js` after jQuery.
144
+
145
+ ```javascript
146
+ //= require jquery
147
+ //= require ahoy
148
+ ```
149
+
150
+ We recommend using traditional analytics services like [Google Analytics](http://www.google.com/analytics/) as well.
151
+
152
+ ## Reference
153
+
154
+ Use a different model
155
+
156
+ ```ruby
157
+ Ahoy.visit_model = UserVisit
158
+ ```
131
159
 
132
160
  ## TODO
133
161
 
@@ -135,6 +163,10 @@ http://datakick.org/?utm_medium=twitter&utm_campaign=social&utm_source=tweet123
135
163
  - hook to store additional fields
136
164
  - turn off modules
137
165
 
166
+ ## History
167
+
168
+ View the [changelog](https://github.com/ankane/ahoy/blob/master/CHANGELOG.md)
169
+
138
170
  ## Contributing
139
171
 
140
172
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
data/lib/ahoy/model.rb CHANGED
@@ -75,7 +75,14 @@ module Ahoy
75
75
 
76
76
  def set_location
77
77
  if respond_to?(:ip) and [:country=, :region=, :city=].any?{|method| respond_to?(method) }
78
- location = Geocoder.search(ip).first rescue nil
78
+ location =
79
+ begin
80
+ Geocoder.search(ip).first
81
+ rescue => e
82
+ $stderr.puts e.message
83
+ nil
84
+ end
85
+
79
86
  if location
80
87
  self.country = location.country.presence if respond_to?(:country=)
81
88
  self.region = location.state.presence if respond_to?(:region=)
data/lib/ahoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/ahoy_matey.rb CHANGED
@@ -11,7 +11,11 @@ require "ahoy/engine"
11
11
  module Ahoy
12
12
 
13
13
  def self.visit_model
14
- ::Visit
14
+ @visit_model || ::Visit
15
+ end
16
+
17
+ def self.visit_model=(visit_model)
18
+ @visit_model = visit_model
15
19
  end
16
20
 
17
21
  # TODO private
@@ -26,7 +30,7 @@ ActionController::Base.send :include, Ahoy::Controller
26
30
  ActiveRecord::Base.send(:extend, Ahoy::Model) if defined?(ActiveRecord)
27
31
 
28
32
  if defined?(Warden)
29
- Warden::Manager.after_authentication do |user, auth, opts|
33
+ Warden::Manager.after_set_user except: :fetch do |user, auth, opts|
30
34
  request = Rack::Request.new(auth.env)
31
35
  if request.cookies["ahoy_visit"]
32
36
  visit = Ahoy.visit_model.where(visit_token: request.cookies["ahoy_visit"]).first
@@ -1,7 +1,7 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :visits do |t|
4
- # cookies *required*
4
+ # cookies
5
5
  t.string :visit_token
6
6
  t.string :visitor_token
7
7
 
@@ -4,9 +4,10 @@
4
4
  "use strict";
5
5
 
6
6
  var debugMode = false;
7
- var visitTtl, visitorTtl;
7
+ var options = window.Ahoy || {};
8
8
  var $ = window.jQuery || window.Zepto || window.$;
9
9
  var visitToken, visitorToken;
10
+ var visitTtl, visitorTtl;
10
11
 
11
12
  if (debugMode) {
12
13
  visitTtl = 0.2;
@@ -19,14 +20,18 @@
19
20
  // cookies
20
21
 
21
22
  // http://www.quirksmode.org/js/cookies.html
22
- function setCookie(name, value, ttl) {
23
+ function setCookie(name, value, ttl, domain) {
23
24
  var expires = "";
25
+ var cookieDomain = "";
24
26
  if (ttl) {
25
27
  var date = new Date();
26
28
  date.setTime(date.getTime() + (ttl * 60 * 1000));
27
29
  expires = "; expires=" + date.toGMTString();
28
30
  }
29
- document.cookie = name + "=" + value + expires + "; path=/";
31
+ if (domain) {
32
+ cookieDomain = "; domain=" + domain;
33
+ }
34
+ document.cookie = name + "=" + value + expires + cookieDomain + "; path=/";
30
35
  }
31
36
 
32
37
  function getCookie(name) {
@@ -79,12 +84,12 @@
79
84
  } else {
80
85
  if (!visitorToken) {
81
86
  visitorToken = generateToken();
82
- setCookie("ahoy_visitor", visitorToken, visitorTtl);
87
+ setCookie("ahoy_visitor", visitorToken, visitorTtl, options.domain);
83
88
  }
84
89
 
85
90
  // always generate a new visit id here
86
91
  visitToken = generateToken();
87
- setCookie("ahoy_visit", visitToken, visitTtl);
92
+ setCookie("ahoy_visit", visitToken, visitTtl, options.domain);
88
93
 
89
94
  // make sure cookies are enabled
90
95
  if (getCookie("ahoy_visit")) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_matey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - CHANGELOG.md
119
120
  - Gemfile
120
121
  - LICENSE.txt
121
122
  - README.md