ahoy_matey 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e7ae0f31293a7769778587395e0bd568e61f6f7
4
- data.tar.gz: 8b941ee921205a3fd192b520934f7e57fb3ead7c
3
+ metadata.gz: 3ef1f6ecc94ec7e579782279c9187ec29be12393
4
+ data.tar.gz: 0515d97b0c1916bd94e057de85fb1a1ccb11f8d2
5
5
  SHA512:
6
- metadata.gz: e6d0bae8709e973024253730e1a95479e6effefca95356b89d88e0019f69eefa2b7eeb8a3ea194e9ef75f80e3011dd64e021f4b82fbba0bc7adea1738e81a212
7
- data.tar.gz: 04abbb97db3428069c283284b07168188e69e98babd8e95eb93245a49da42ea753b46b91aa32d1d5a0f0867dcc5438f4fc93b22681d927326a7b38a1c53c329e
6
+ metadata.gz: 7fb051cdca6fa1fe250094b03acf393e28c93c93df0a4ca9379fd6aa468478668be22f4cce72316ea5d9db20824d7ea700e627c5f2787f0b9ce24878d2736346
7
+ data.tar.gz: 00435c1bb0c2f83fec2eef2bf73d45c908269d793a5c18ebc3de39dd3286c13f33e390a8c83e3d3c05581602836c905be0740a21d381ec695a3bcc968dc584dd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.4
2
+
3
+ - Added `ahoy.ready()` and `ahoy.log()` for events
4
+
1
5
  ## 0.1.3
2
6
 
3
7
  - Supports `current_user` from `ApplicationController`
data/README.md CHANGED
@@ -17,6 +17,8 @@ See which campaigns generate the most revenue effortlessly.
17
17
  Order.joins(:visit).group("utm_campaign").sum(:revenue)
18
18
  ```
19
19
 
20
+ :seedling: To track events like page views, check out [Ahoy Events](https://github.com/ankane/ahoy_events).
21
+
20
22
  ## Installation
21
23
 
22
24
  Add this line to your application’s Gemfile:
@@ -210,6 +212,7 @@ var ahoy = {"platform": "Mobile Web"}
210
212
 
211
213
  ## TODO
212
214
 
215
+ - track emails
213
216
  - simple dashboard
214
217
  - hook to store additional fields
215
218
  - turn off modules
@@ -0,0 +1,21 @@
1
+ module Ahoy
2
+ class BaseController < ApplicationController
3
+ # skip all filters
4
+ skip_filter *_process_action_callbacks.map(&:filter)
5
+
6
+ before_filter :halt_bots
7
+
8
+ protected
9
+
10
+ def browser
11
+ @browser ||= Browser.new(ua: request.user_agent)
12
+ end
13
+
14
+ def halt_bots
15
+ if browser.bot?
16
+ render json: {}
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -1,9 +1,5 @@
1
1
  module Ahoy
2
- class VisitsController < ApplicationController
3
- # skip all filters
4
- skip_filter *_process_action_callbacks.map(&:filter)
5
-
6
- before_filter :halt_bots
2
+ class VisitsController < BaseController
7
3
 
8
4
  def create
9
5
  visit_token = generate_token
@@ -33,15 +29,5 @@ module Ahoy
33
29
  SecureRandom.urlsafe_base64(32).gsub(/[\-_]/, "").first(32)
34
30
  end
35
31
 
36
- def browser
37
- @browser ||= Browser.new(ua: request.user_agent)
38
- end
39
-
40
- def halt_bots
41
- if browser.bot?
42
- render json: {}
43
- end
44
- end
45
-
46
32
  end
47
33
  end
data/config/routes.rb CHANGED
@@ -3,5 +3,7 @@ Rails.application.routes.draw do
3
3
  end
4
4
 
5
5
  Ahoy::Engine.routes.draw do
6
- resources :visits, only: [:create]
6
+ scope module: "ahoy" do
7
+ resources :visits, only: [:create]
8
+ end
7
9
  end
@@ -8,8 +8,6 @@ module Ahoy
8
8
  end
9
9
  end
10
10
 
11
- protected
12
-
13
11
  def current_visit
14
12
  visit_token = cookies[:ahoy_visit] || request.headers["Ahoy-Visit"]
15
13
  if visit_token
data/lib/ahoy/engine.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Ahoy
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace Ahoy
4
3
  end
5
4
  end
data/lib/ahoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -8,6 +8,8 @@
8
8
  var visitToken, visitorToken;
9
9
  var visitTtl = 4 * 60; // 4 hours
10
10
  var visitorTtl = 2 * 365 * 24 * 60; // 2 years
11
+ var isReady = false;
12
+ var queue = [];
11
13
 
12
14
  // cookies
13
15
 
@@ -52,6 +54,14 @@
52
54
  }
53
55
  }
54
56
 
57
+ function setReady() {
58
+ var callback;
59
+ while (callback = queue.shift()) {
60
+ callback();
61
+ }
62
+ isReady = true;
63
+ }
64
+
55
65
  // main
56
66
 
57
67
  visitToken = getCookie("ahoy_visit");
@@ -60,6 +70,7 @@
60
70
  if (visitToken && visitorToken && visitToken != "test") {
61
71
  // TODO keep visit alive?
62
72
  log("Active visit");
73
+ setReady();
63
74
  } else {
64
75
  setCookie("ahoy_visit", "test", 1);
65
76
 
@@ -86,9 +97,11 @@
86
97
  $.post("/ahoy/visits", data, function(response) {
87
98
  setCookie("ahoy_visit", response.visit_token, visitTtl);
88
99
  setCookie("ahoy_visitor", response.visitor_token, visitorTtl);
100
+ setReady();
89
101
  }, "json");
90
102
  } else {
91
103
  log("Cookies disabled");
104
+ setReady();
92
105
  }
93
106
  }
94
107
 
@@ -107,5 +120,15 @@
107
120
  return true;
108
121
  };
109
122
 
123
+ ahoy.log = log;
124
+
125
+ ahoy.ready = function (callback) {
126
+ if (isReady) {
127
+ callback();
128
+ } else {
129
+ queue.push(callback);
130
+ }
131
+ };
132
+
110
133
  window.ahoy = ahoy;
111
134
  }(window));
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.3
4
+ version: 0.1.4
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-25 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -122,6 +122,7 @@ files:
122
122
  - README.md
123
123
  - Rakefile
124
124
  - ahoy_matey.gemspec
125
+ - app/controllers/ahoy/base_controller.rb
125
126
  - app/controllers/ahoy/visits_controller.rb
126
127
  - config/routes.rb
127
128
  - lib/ahoy/controller.rb