ahoy_matey 3.0.5 → 3.1.0
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 +6 -2
- data/lib/ahoy.rb +8 -0
- data/lib/ahoy/base_store.rb +5 -1
- data/lib/ahoy/controller.rb +3 -3
- data/lib/ahoy/model.rb +1 -1
- data/lib/ahoy/tracker.rb +5 -9
- data/lib/ahoy/version.rb +1 -1
- data/vendor/assets/javascripts/ahoy.js +111 -18
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c98a3beef3f7d137de52572c02e410709d603028021a25b5e325e47fd6b2fe8c
|
4
|
+
data.tar.gz: c9304029a1f3828baac05af4397083243113019e52add5da3439fac9c111f2ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b4d2504fda7d21993196093617a55b31bf38b58b33a744b64db6f187f9e6da5b570858ecb67aeb550b76ce623742adebbb5369b2edd2f501166dd539682b14c
|
7
|
+
data.tar.gz: e8ecbc02ed485f8856f34527351b2c293fe77afb07d4b6011c050e246c50ed92d8262639109696feadd386145633778620d3159b023a0ca27d963a2ffb83aef3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Track visits and events in Ruby, JavaScript, and native apps. Data is stored in
|
|
8
8
|
|
9
9
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
|
10
10
|
|
11
|
-
[![Build Status](https://
|
11
|
+
[![Build Status](https://github.com/ankane/ahoy/workflows/build/badge.svg?branch=master)](https://github.com/ankane/ahoy/actions)
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
@@ -70,6 +70,10 @@ Track an event with:
|
|
70
70
|
ahoy.track("My second event", {language: "JavaScript"});
|
71
71
|
```
|
72
72
|
|
73
|
+
### Native Apps
|
74
|
+
|
75
|
+
Check out [Ahoy iOS](https://github.com/namolnad/ahoy-ios) and [Ahoy Android](https://github.com/instacart/ahoy-android).
|
76
|
+
|
73
77
|
### GDPR Compliance
|
74
78
|
|
75
79
|
Ahoy provides a number of options to help with GDPR compliance. See the [GDPR section](#gdpr-compliance-1) for more info.
|
@@ -145,7 +149,7 @@ See [Ahoy.js](https://github.com/ankane/ahoy.js) for a complete list of features
|
|
145
149
|
|
146
150
|
#### Native Apps
|
147
151
|
|
148
|
-
|
152
|
+
See the docs for [Ahoy iOS](https://github.com/namolnad/ahoy-ios) and [Ahoy Android](https://github.com/instacart/ahoy-android).
|
149
153
|
|
150
154
|
#### AMP
|
151
155
|
|
data/lib/ahoy.rb
CHANGED
@@ -104,6 +104,14 @@ module Ahoy
|
|
104
104
|
addr.mask(48).to_s
|
105
105
|
end
|
106
106
|
end
|
107
|
+
|
108
|
+
def self.instance
|
109
|
+
Thread.current[:ahoy]
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.instance=(value)
|
113
|
+
Thread.current[:ahoy] = value
|
114
|
+
end
|
107
115
|
end
|
108
116
|
|
109
117
|
ActiveSupport.on_load(:action_controller) do
|
data/lib/ahoy/base_store.rb
CHANGED
@@ -24,7 +24,11 @@ module Ahoy
|
|
24
24
|
def user
|
25
25
|
@user ||= begin
|
26
26
|
if Ahoy.user_method.respond_to?(:call)
|
27
|
-
Ahoy.user_method.
|
27
|
+
if Ahoy.user_method.arity == 1
|
28
|
+
Ahoy.user_method.call(controller)
|
29
|
+
else
|
30
|
+
Ahoy.user_method.call(controller, request)
|
31
|
+
end
|
28
32
|
else
|
29
33
|
controller.send(Ahoy.user_method) if controller.respond_to?(Ahoy.user_method, true)
|
30
34
|
end
|
data/lib/ahoy/controller.rb
CHANGED
@@ -39,12 +39,12 @@ module Ahoy
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def set_ahoy_request_store
|
42
|
-
previous_value =
|
42
|
+
previous_value = Ahoy.instance
|
43
43
|
begin
|
44
|
-
|
44
|
+
Ahoy.instance = ahoy
|
45
45
|
yield
|
46
46
|
ensure
|
47
|
-
|
47
|
+
Ahoy.instance = previous_value
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/ahoy/model.rb
CHANGED
data/lib/ahoy/tracker.rb
CHANGED
@@ -67,16 +67,12 @@ module Ahoy
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def geocode(data)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
data = {
|
74
|
-
visit_token: visit_token
|
75
|
-
}.merge(data).select { |_, v| v }
|
70
|
+
data = {
|
71
|
+
visit_token: visit_token
|
72
|
+
}.merge(data).select { |_, v| v }
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
end
|
74
|
+
@store.geocode(data)
|
75
|
+
true
|
80
76
|
rescue => e
|
81
77
|
report_exception(e)
|
82
78
|
end
|
data/lib/ahoy/version.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* Ahoy.js
|
3
3
|
* Simple, powerful JavaScript analytics
|
4
4
|
* https://github.com/ankane/ahoy.js
|
5
|
-
* v0.3.
|
5
|
+
* v0.3.8
|
6
6
|
* MIT License
|
7
7
|
*/
|
8
8
|
|
@@ -12,7 +12,96 @@
|
|
12
12
|
(global = global || self, global.ahoy = factory());
|
13
13
|
}(this, (function () { 'use strict';
|
14
14
|
|
15
|
-
var
|
15
|
+
var isUndefined = function (value) { return value === undefined; };
|
16
|
+
|
17
|
+
var isNull = function (value) { return value === null; };
|
18
|
+
|
19
|
+
var isBoolean = function (value) { return typeof value === 'boolean'; };
|
20
|
+
|
21
|
+
var isObject = function (value) { return value === Object(value); };
|
22
|
+
|
23
|
+
var isArray = function (value) { return Array.isArray(value); };
|
24
|
+
|
25
|
+
var isDate = function (value) { return value instanceof Date; };
|
26
|
+
|
27
|
+
var isBlob = function (value) { return value &&
|
28
|
+
typeof value.size === 'number' &&
|
29
|
+
typeof value.type === 'string' &&
|
30
|
+
typeof value.slice === 'function'; };
|
31
|
+
|
32
|
+
var isFile = function (value) { return isBlob(value) &&
|
33
|
+
typeof value.name === 'string' &&
|
34
|
+
(typeof value.lastModifiedDate === 'object' ||
|
35
|
+
typeof value.lastModified === 'number'); };
|
36
|
+
|
37
|
+
var serialize = function (obj, cfg, fd, pre) {
|
38
|
+
cfg = cfg || {};
|
39
|
+
|
40
|
+
cfg.indices = isUndefined(cfg.indices) ? false : cfg.indices;
|
41
|
+
|
42
|
+
cfg.nullsAsUndefineds = isUndefined(cfg.nullsAsUndefineds)
|
43
|
+
? false
|
44
|
+
: cfg.nullsAsUndefineds;
|
45
|
+
|
46
|
+
cfg.booleansAsIntegers = isUndefined(cfg.booleansAsIntegers)
|
47
|
+
? false
|
48
|
+
: cfg.booleansAsIntegers;
|
49
|
+
|
50
|
+
cfg.allowEmptyArrays = isUndefined(cfg.allowEmptyArrays)
|
51
|
+
? false
|
52
|
+
: cfg.allowEmptyArrays;
|
53
|
+
|
54
|
+
fd = fd || new FormData();
|
55
|
+
|
56
|
+
if (isUndefined(obj)) {
|
57
|
+
return fd;
|
58
|
+
} else if (isNull(obj)) {
|
59
|
+
if (!cfg.nullsAsUndefineds) {
|
60
|
+
fd.append(pre, '');
|
61
|
+
}
|
62
|
+
} else if (isBoolean(obj)) {
|
63
|
+
if (cfg.booleansAsIntegers) {
|
64
|
+
fd.append(pre, obj ? 1 : 0);
|
65
|
+
} else {
|
66
|
+
fd.append(pre, obj);
|
67
|
+
}
|
68
|
+
} else if (isArray(obj)) {
|
69
|
+
if (obj.length) {
|
70
|
+
obj.forEach(function (value, index) {
|
71
|
+
var key = pre + '[' + (cfg.indices ? index : '') + ']';
|
72
|
+
|
73
|
+
serialize(value, cfg, fd, key);
|
74
|
+
});
|
75
|
+
} else if (cfg.allowEmptyArrays) {
|
76
|
+
fd.append(pre + '[]', '');
|
77
|
+
}
|
78
|
+
} else if (isDate(obj)) {
|
79
|
+
fd.append(pre, obj.toISOString());
|
80
|
+
} else if (isObject(obj) && !isFile(obj) && !isBlob(obj)) {
|
81
|
+
Object.keys(obj).forEach(function (prop) {
|
82
|
+
var value = obj[prop];
|
83
|
+
|
84
|
+
if (isArray(value)) {
|
85
|
+
while (prop.length > 2 && prop.lastIndexOf('[]') === prop.length - 2) {
|
86
|
+
prop = prop.substring(0, prop.length - 2);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
var key = pre ? pre + '[' + prop + ']' : prop;
|
91
|
+
|
92
|
+
serialize(value, cfg, fd, key);
|
93
|
+
});
|
94
|
+
} else {
|
95
|
+
fd.append(pre, obj);
|
96
|
+
}
|
97
|
+
|
98
|
+
return fd;
|
99
|
+
};
|
100
|
+
|
101
|
+
var index_module = {
|
102
|
+
serialize: serialize,
|
103
|
+
};
|
104
|
+
var index_module_1 = index_module.serialize;
|
16
105
|
|
17
106
|
// https://www.quirksmode.org/js/cookies.html
|
18
107
|
|
@@ -146,17 +235,23 @@
|
|
146
235
|
element.webkitMatchesSelector;
|
147
236
|
|
148
237
|
if (matches) {
|
149
|
-
|
238
|
+
if (matches.apply(element, [selector])) {
|
239
|
+
return element;
|
240
|
+
} else if (element.parentElement) {
|
241
|
+
return matchesSelector(element.parentElement, selector)
|
242
|
+
}
|
243
|
+
return null;
|
150
244
|
} else {
|
151
245
|
log("Unable to match");
|
152
|
-
return
|
246
|
+
return null;
|
153
247
|
}
|
154
248
|
}
|
155
249
|
|
156
250
|
function onEvent(eventName, selector, callback) {
|
157
251
|
document.addEventListener(eventName, function (e) {
|
158
|
-
|
159
|
-
|
252
|
+
var matchedElement = matchesSelector(e.target, selector);
|
253
|
+
if (matchedElement) {
|
254
|
+
callback.call(matchedElement, e);
|
160
255
|
}
|
161
256
|
});
|
162
257
|
}
|
@@ -275,7 +370,7 @@
|
|
275
370
|
// stringify so we keep the type
|
276
371
|
data.events_json = JSON.stringify(data.events);
|
277
372
|
delete data.events;
|
278
|
-
window.navigator.sendBeacon(eventsUrl(),
|
373
|
+
window.navigator.sendBeacon(eventsUrl(), index_module_1(data));
|
279
374
|
});
|
280
375
|
}
|
281
376
|
|
@@ -299,13 +394,12 @@
|
|
299
394
|
}
|
300
395
|
|
301
396
|
function eventProperties(e) {
|
302
|
-
var target = e.target;
|
303
397
|
return cleanObject({
|
304
|
-
tag:
|
305
|
-
id: presence(
|
306
|
-
"class": presence(
|
398
|
+
tag: this.tagName.toLowerCase(),
|
399
|
+
id: presence(this.id),
|
400
|
+
"class": presence(this.className),
|
307
401
|
page: page(),
|
308
|
-
section: getClosestSection(
|
402
|
+
section: getClosestSection(this)
|
309
403
|
});
|
310
404
|
}
|
311
405
|
|
@@ -465,24 +559,23 @@
|
|
465
559
|
|
466
560
|
ahoy.trackClicks = function () {
|
467
561
|
onEvent("click", "a, button, input[type=submit]", function (e) {
|
468
|
-
var
|
469
|
-
|
470
|
-
properties.
|
471
|
-
properties.href = target.href;
|
562
|
+
var properties = eventProperties.call(this, e);
|
563
|
+
properties.text = properties.tag == "input" ? this.value : (this.textContent || this.innerText || this.innerHTML).replace(/[\s\r\n]+/g, " ").trim();
|
564
|
+
properties.href = this.href;
|
472
565
|
ahoy.track("$click", properties);
|
473
566
|
});
|
474
567
|
};
|
475
568
|
|
476
569
|
ahoy.trackSubmits = function () {
|
477
570
|
onEvent("submit", "form", function (e) {
|
478
|
-
var properties = eventProperties(e);
|
571
|
+
var properties = eventProperties.call(this, e);
|
479
572
|
ahoy.track("$submit", properties);
|
480
573
|
});
|
481
574
|
};
|
482
575
|
|
483
576
|
ahoy.trackChanges = function () {
|
484
577
|
onEvent("change", "input, textarea, select", function (e) {
|
485
|
-
var properties = eventProperties(e);
|
578
|
+
var properties = eventProperties.call(this, e);
|
486
579
|
ahoy.track("$change", properties);
|
487
580
|
});
|
488
581
|
};
|
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: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -220,7 +220,7 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
-
description:
|
223
|
+
description:
|
224
224
|
email: andrew@chartkick.com
|
225
225
|
executables: []
|
226
226
|
extensions: []
|
@@ -266,7 +266,7 @@ homepage: https://github.com/ankane/ahoy
|
|
266
266
|
licenses:
|
267
267
|
- MIT
|
268
268
|
metadata: {}
|
269
|
-
post_install_message:
|
269
|
+
post_install_message:
|
270
270
|
rdoc_options: []
|
271
271
|
require_paths:
|
272
272
|
- lib
|
@@ -281,8 +281,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
- !ruby/object:Gem::Version
|
282
282
|
version: '0'
|
283
283
|
requirements: []
|
284
|
-
rubygems_version: 3.1.
|
285
|
-
signing_key:
|
284
|
+
rubygems_version: 3.1.4
|
285
|
+
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Simple, powerful, first-party analytics for Rails
|
288
288
|
test_files: []
|