ahoy_matey 0.1.4 → 0.1.5

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: 3ef1f6ecc94ec7e579782279c9187ec29be12393
4
- data.tar.gz: 0515d97b0c1916bd94e057de85fb1a1ccb11f8d2
3
+ metadata.gz: e01d2ba2f3f5b56e44fa016d8f0eb16e669b499d
4
+ data.tar.gz: 9f243b939b05458432e3651d7f75728bbd592ab8
5
5
  SHA512:
6
- metadata.gz: 7fb051cdca6fa1fe250094b03acf393e28c93c93df0a4ca9379fd6aa468478668be22f4cce72316ea5d9db20824d7ea700e627c5f2787f0b9ce24878d2736346
7
- data.tar.gz: 00435c1bb0c2f83fec2eef2bf73d45c908269d793a5c18ebc3de39dd3286c13f33e390a8c83e3d3c05581602836c905be0740a21d381ec695a3bcc968dc584dd
6
+ metadata.gz: 10c69828ab683a8a0048e22a62f83d1c920d811e7e723658c8e90d954e2f7221b695a91038dae105bfecabb04b5470d45d9a9108b2b784663a377f4eed02a43c
7
+ data.tar.gz: 6200522f9ede3ce32ab07bd02fcfc5e179b874cea692ea6ade74f62cbd7b7642870ad568a7115408b01976a9dc29e04f716048d71f833ade6a0c86434a4602ab
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.5
2
+
3
+ - Added support for Doorkeeper
4
+ - Added options to `visitable`
5
+ - Added `landing_params` method
6
+
1
7
  ## 0.1.4
2
8
 
3
9
  - Added `ahoy.ready()` and `ahoy.log()` for events
data/README.md CHANGED
@@ -19,6 +19,8 @@ Order.joins(:visit).group("utm_campaign").sum(:revenue)
19
19
 
20
20
  :seedling: To track events like page views, check out [Ahoy Events](https://github.com/ankane/ahoy_events).
21
21
 
22
+ :postbox: To track emails, check out [Ahoy Email](https://github.com/ankane/ahoy_email).
23
+
22
24
  ## Installation
23
25
 
24
26
  Add this line to your application’s Gemfile:
@@ -167,7 +169,7 @@ Turn off logging
167
169
  ahoy.debug(false);
168
170
  ```
169
171
 
170
- ### Native Apps [experimental]
172
+ ### Native Apps
171
173
 
172
174
  When a user launches the app, create a visit. Send a `POST` request to `/ahoy/visits` with:
173
175
 
@@ -189,6 +191,22 @@ Send the visit token in the `Ahoy-Visit` header for all requests.
189
191
 
190
192
  After 4 hours, create another visit and use the updated visit token.
191
193
 
194
+ ### Doorkeeper
195
+
196
+ To attach the user with [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper), be sure you have a `current_resource_owner` method in `ApplicationController`.
197
+
198
+ ```ruby
199
+ class ApplicationController < ActionController::Base
200
+
201
+ private
202
+
203
+ def current_resource_owner
204
+ User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
205
+ end
206
+
207
+ end
208
+ ```
209
+
192
210
  ### More
193
211
 
194
212
  - Excludes bots
@@ -210,11 +228,42 @@ Change the platform on the web
210
228
  var ahoy = {"platform": "Mobile Web"}
211
229
  ```
212
230
 
231
+ Track additional values
232
+
233
+ ```ruby
234
+ class Visit < ActiveRecord::Base
235
+ ahoy_visit
236
+
237
+ before_create :set_gclid
238
+
239
+ def set_gclid
240
+ self.gclid = landing_params["gclid"]
241
+ end
242
+
243
+ end
244
+ ```
245
+
246
+ Use a method besides `current_user`
247
+
248
+ ```ruby
249
+ Ahoy.user_method = :true_user
250
+ ```
251
+
252
+ or use a Proc
253
+
254
+ ```ruby
255
+ Ahoy.user_method = proc {|controller| controller.current_user }
256
+ ```
257
+
258
+ Customize visitable
259
+
260
+ ```ruby
261
+ visitable :sign_up_visit, class_name: "Visit"
262
+ ```
263
+
213
264
  ## TODO
214
265
 
215
- - track emails
216
266
  - simple dashboard
217
- - hook to store additional fields
218
267
  - turn off modules
219
268
 
220
269
  ## History
@@ -13,7 +13,7 @@ module Ahoy
13
13
  v.user_agent = request.user_agent if v.respond_to?(:user_agent=)
14
14
  v.referrer = params[:referrer] if v.respond_to?(:referrer=)
15
15
  v.landing_page = params[:landing_page] if v.respond_to?(:landing_page=)
16
- v.user = current_user if respond_to?(:current_user) and v.respond_to?(:user=)
16
+ v.user = Ahoy.fetch_user(self) if v.respond_to?(:user=)
17
17
  v.platform = params[:platform] if v.respond_to?(:platform=)
18
18
  v.app_version = params[:app_version] if v.respond_to?(:app_version=)
19
19
  v.os_version = params[:os_version] if v.respond_to?(:os_version=)
data/lib/ahoy/model.rb CHANGED
@@ -21,12 +21,8 @@ module Ahoy
21
21
  end
22
22
 
23
23
  def set_utm_parameters
24
- landing_uri = Addressable::URI.parse(landing_page) rescue nil
25
- if landing_uri
26
- query_values = landing_uri.query_values || {}
27
- %w[utm_source utm_medium utm_term utm_content utm_campaign].each do |name|
28
- self[name] = query_values[name] if respond_to?(:"#{name}=")
29
- end
24
+ %w[utm_source utm_medium utm_term utm_content utm_campaign].each do |name|
25
+ self[name] = landing_params[name] if respond_to?(:"#{name}=")
30
26
  end
31
27
  true
32
28
  end
@@ -92,23 +88,31 @@ module Ahoy
92
88
  true
93
89
  end
94
90
 
91
+ def landing_params
92
+ @landing_params ||= begin
93
+ landing_uri = Addressable::URI.parse(landing_page) rescue nil
94
+ ActiveSupport::HashWithIndifferentAccess.new((landing_uri && landing_uri.query_values) || {})
95
+ end
96
+ end
97
+
95
98
  end # end class_eval
96
99
  end
97
100
 
98
- def visitable
101
+ def visitable(name = nil, options = {})
102
+ if name.is_a?(Hash)
103
+ name = nil
104
+ options = name
105
+ end
106
+ name ||= :visit
99
107
  class_eval do
100
- belongs_to :visit
101
-
108
+ belongs_to name, options
102
109
  before_create :set_visit
103
-
110
+ end
111
+ class_eval %Q{
104
112
  def set_visit
105
- if !self.class.column_names.include?("visit_id")
106
- raise "Add a visit_id column to this table to use visitable"
107
- else
108
- self.visit ||= RequestStore.store[:ahoy_controller].try(:send, :current_visit)
109
- end
113
+ self.#{name} ||= RequestStore.store[:ahoy_controller].try(:send, :current_visit)
110
114
  end
111
- end
115
+ }
112
116
  end
113
117
 
114
118
  end
data/lib/ahoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/ahoy_matey.rb CHANGED
@@ -24,6 +24,19 @@ module Ahoy
24
24
  @referrer_parser ||= RefererParser::Referer.new("https://github.com/ankane/ahoy")
25
25
  end
26
26
 
27
+ def self.fetch_user(controller)
28
+ if user_method.respond_to?(:call)
29
+ user_method.call(controller)
30
+ else
31
+ controller.send(user_method)
32
+ end
33
+ end
34
+
35
+ mattr_accessor :user_method
36
+ self.user_method = proc do |controller|
37
+ (controller.respond_to?(:current_user) && controller.current_user) || (controller.respond_to?(:current_resource_owner, true) and controller.send(:current_resource_owner))
38
+ end
39
+
27
40
  end
28
41
 
29
42
  ActionController::Base.send :include, Ahoy::Controller
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.4
4
+ version: 0.1.5
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-04-28 00:00:00.000000000 Z
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable