ahoy_matey 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +23 -2
- data/ahoy_matey.gemspec +1 -1
- data/app/jobs/ahoy/geocode_v2_job.rb +3 -4
- data/docs/Ahoy-2-Upgrade.md +1 -1
- data/lib/ahoy.rb +4 -0
- data/lib/ahoy/database_store.rb +10 -5
- data/lib/ahoy/tracker.rb +6 -2
- data/lib/ahoy/version.rb +1 -1
- data/vendor/assets/javascripts/ahoy.js +7 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c48c8c5793b7e8f7c53ee1fcfed647340749cee
|
4
|
+
data.tar.gz: ad2e9686bebde7233be8804ac899a1672f352240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b3a16dd65efc501a56fa2a6e2574dc228dbc236d97d352153bd6012b85243450753a62f4155737a2d43610ac619f225004492ed8bcfc8a5e088ef93b67fb56a
|
7
|
+
data.tar.gz: 23e2ee9cc5ec7d772cce7a4af348b95b93090c5d3a7113fd1d47fcd9fe3bbca4cbbb145cbc21d3826ca159d984566e3e1c8f3b45d89d9a7319bba2ae2d8026eb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 2.0.2
|
2
|
+
|
3
|
+
- Fixed error on duplicate records
|
4
|
+
- Fixed message when visit not found for geocoding
|
5
|
+
- Better compatibility with GeoLite2
|
6
|
+
- Better browser compatibility for Ahoy.js
|
7
|
+
|
1
8
|
## 2.0.1
|
2
9
|
|
3
10
|
- Added `Ahoy.server_side_visits = :when_needed` to automatically create visits server-side when needed for events and `visitable`
|
data/README.md
CHANGED
@@ -79,7 +79,7 @@ skip_before_action :track_ahoy_visit
|
|
79
79
|
|
80
80
|
This is typically useful for APIs.
|
81
81
|
|
82
|
-
You can also defer visit tracking to JavaScript. This is useful for preventing bots (that aren’t detected by their user agent) and users with cookies disabled from creating a new visit on each request. `:when_needed` will create visits server-side when needed by events, and `false` will
|
82
|
+
You can also defer visit tracking to JavaScript. This is useful for preventing bots (that aren’t detected by their user agent) and users with cookies disabled from creating a new visit on each request. `:when_needed` will create visits server-side only when needed by events, and `false` will disable server-side creation completely, discarding events without a visit.
|
83
83
|
|
84
84
|
```ruby
|
85
85
|
Ahoy.server_side_visits = :when_needed
|
@@ -120,7 +120,7 @@ class ApplicationController < ActionController::Base
|
|
120
120
|
protected
|
121
121
|
|
122
122
|
def track_action
|
123
|
-
ahoy.track "
|
123
|
+
ahoy.track "Ran action", request.path_parameters
|
124
124
|
end
|
125
125
|
end
|
126
126
|
```
|
@@ -263,6 +263,27 @@ Change the job queue with:
|
|
263
263
|
Ahoy.job_queue = :low_priority
|
264
264
|
```
|
265
265
|
|
266
|
+
#### Geocoding Performance
|
267
|
+
|
268
|
+
To avoid calls to a remote API, download the [GeoLite2 City database](https://dev.maxmind.com/geoip/geoip2/geolite2/) and configure Geocoder to use it.
|
269
|
+
|
270
|
+
Add this line to your application’s Gemfile:
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
gem 'maxminddb'
|
274
|
+
```
|
275
|
+
|
276
|
+
And create an initializer at `config/initializers/geocoder.rb` with:
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
Geocoder.configure(
|
280
|
+
ip_lookup: :geoip2,
|
281
|
+
geoip2: {
|
282
|
+
file: Rails.root.join("lib", "GeoLite2-City.mmdb")
|
283
|
+
}
|
284
|
+
)
|
285
|
+
```
|
286
|
+
|
266
287
|
### Token Generation
|
267
288
|
|
268
289
|
Ahoy uses random UUIDs for visit and visitor tokens by default, but you can use your own generator like [Druuid](https://github.com/recurly/druuid).
|
data/ahoy_matey.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency "railties", ">= 4.2"
|
21
21
|
spec.add_dependency "addressable"
|
22
|
-
spec.add_dependency "geocoder"
|
22
|
+
spec.add_dependency "geocoder", ">= 1.4.5"
|
23
23
|
spec.add_dependency "browser", "~> 2.0"
|
24
24
|
spec.add_dependency "referer-parser", ">= 0.3"
|
25
25
|
spec.add_dependency "user_agent_parser"
|
@@ -7,14 +7,13 @@ module Ahoy
|
|
7
7
|
begin
|
8
8
|
Geocoder.search(ip).first
|
9
9
|
rescue => e
|
10
|
-
|
10
|
+
Ahoy.log "Geocode error: #{e.class.name}: #{e.message}"
|
11
11
|
nil
|
12
12
|
end
|
13
13
|
|
14
|
-
if location
|
14
|
+
if location && location.country.present?
|
15
15
|
data = {
|
16
|
-
|
17
|
-
country: location.try(:country).presence,
|
16
|
+
country: location.country,
|
18
17
|
region: location.try(:state).presence,
|
19
18
|
city: location.try(:city).presence,
|
20
19
|
postal_code: location.try(:postal_code).presence,
|
data/docs/Ahoy-2-Upgrade.md
CHANGED
data/lib/ahoy.rb
CHANGED
data/lib/ahoy/database_store.rb
CHANGED
@@ -4,7 +4,11 @@ module Ahoy
|
|
4
4
|
@visit = visit_model.create!(slice_data(visit_model, data))
|
5
5
|
rescue => e
|
6
6
|
raise e unless unique_exception?(e)
|
7
|
-
|
7
|
+
|
8
|
+
# so next call to visit will try to fetch from DB
|
9
|
+
if defined?(@visit)
|
10
|
+
remove_instance_variable(:@visit)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def track_event(data)
|
@@ -18,19 +22,20 @@ module Ahoy
|
|
18
22
|
raise e unless unique_exception?(e)
|
19
23
|
end
|
20
24
|
else
|
21
|
-
|
25
|
+
Ahoy.log "Event excluded since visit not created: #{data[:visit_token]}"
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
def geocode(data)
|
26
|
-
|
30
|
+
visit_token = data.delete(:visit_token)
|
31
|
+
data = slice_data(visit_model, data)
|
27
32
|
if defined?(Mongoid::Document) && visit_model < Mongoid::Document
|
28
33
|
# upsert since visit might not be found due to eventual consistency
|
29
|
-
visit_model.where(visit_token:
|
34
|
+
visit_model.where(visit_token: visit_token).find_one_and_update({"$set": data}, {upsert: true})
|
30
35
|
elsif visit
|
31
36
|
visit.update_attributes(data)
|
32
37
|
else
|
33
|
-
|
38
|
+
Ahoy.log "Visit for geocode not found: #{visit_token}"
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
data/lib/ahoy/tracker.rb
CHANGED
@@ -65,7 +65,11 @@ module Ahoy
|
|
65
65
|
if exclude?
|
66
66
|
debug "Geocode excluded"
|
67
67
|
else
|
68
|
-
|
68
|
+
data = {
|
69
|
+
visit_token: visit_token
|
70
|
+
}.merge(data).select { |_, v| v }
|
71
|
+
|
72
|
+
@store.geocode(data)
|
69
73
|
true
|
70
74
|
end
|
71
75
|
rescue => e
|
@@ -256,7 +260,7 @@ module Ahoy
|
|
256
260
|
end
|
257
261
|
|
258
262
|
def debug(message)
|
259
|
-
|
263
|
+
Ahoy.log message
|
260
264
|
end
|
261
265
|
end
|
262
266
|
end
|
data/lib/ahoy/version.rb
CHANGED
@@ -98,7 +98,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
98
98
|
* Ahoy.js
|
99
99
|
* Simple, powerful JavaScript analytics
|
100
100
|
* https://github.com/ankane/ahoy.js
|
101
|
-
* v0.3.
|
101
|
+
* v0.3.1
|
102
102
|
* MIT License
|
103
103
|
*/
|
104
104
|
|
@@ -186,10 +186,13 @@ function ready(callback) {
|
|
186
186
|
}
|
187
187
|
|
188
188
|
function matchesSelector(element, selector) {
|
189
|
-
|
190
|
-
|
189
|
+
var matches = element.matches || element.matchesSelector || element.mozMatchesSelector || element.msMatchesSelector || element.oMatchesSelector || element.webkitMatchesSelector;
|
190
|
+
|
191
|
+
if (matches) {
|
192
|
+
return matches.apply(element, [selector]);
|
191
193
|
} else {
|
192
|
-
|
194
|
+
log("Unable to match");
|
195
|
+
return false;
|
193
196
|
}
|
194
197
|
}
|
195
198
|
|
@@ -216,7 +219,6 @@ function generateId() {
|
|
216
219
|
}
|
217
220
|
|
218
221
|
function saveEventQueue() {
|
219
|
-
// TODO add stringify method for IE 7 and under
|
220
222
|
if (canStringify) {
|
221
223
|
setCookie("ahoy_events", JSON.stringify(eventQueue), 1);
|
222
224
|
}
|
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: 2.0.
|
4
|
+
version: 2.0.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: 2018-
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.4.5
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.4.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: browser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|