@guardian/ophan-tracker-js 2.0.4 → 2.1.0-next.1

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.
Files changed (54) hide show
  1. package/assets/adblock-detection.js +24 -0
  2. package/assets/attention.js +187 -0
  3. package/assets/campaign.js +40 -0
  4. package/assets/click-path-capture.js +107 -0
  5. package/assets/components.js +209 -0
  6. package/assets/contribution.js +25 -0
  7. package/assets/core.js +282 -0
  8. package/assets/embed.js +11 -0
  9. package/assets/fb-instant.js +10 -0
  10. package/assets/heatmap.js +47 -0
  11. package/assets/holidays.js +11 -0
  12. package/assets/http-status.js +20 -0
  13. package/assets/iframe-tracking.js +82 -0
  14. package/assets/interactive.js +25 -0
  15. package/assets/jobs-courses.js +11 -0
  16. package/assets/jobs.js +11 -0
  17. package/assets/manage-my-account.js +50 -0
  18. package/assets/membership.js +25 -0
  19. package/assets/ng.js +41 -0
  20. package/assets/perf.js +43 -0
  21. package/assets/privatebrowsing.js +79 -0
  22. package/{build → assets}/r2.js +3 -3
  23. package/{build → assets}/smart-news.js +4 -4
  24. package/assets/support.js +44 -0
  25. package/assets/transmit.js +150 -0
  26. package/assets/vendor/adBlockDetectionLib.js +366 -0
  27. package/assets/visibility.js +20 -0
  28. package/{build → assets}/witness.js +3 -3
  29. package/package.json +28 -24
  30. package/build/adblock-detection.js +0 -24
  31. package/build/attention.js +0 -149
  32. package/build/campaign.js +0 -30
  33. package/build/click-path-capture.js +0 -81
  34. package/build/components.js +0 -167
  35. package/build/contribution.js +0 -25
  36. package/build/core.js +0 -234
  37. package/build/embed.js +0 -11
  38. package/build/fb-instant.js +0 -10
  39. package/build/heatmap.js +0 -32
  40. package/build/holidays.js +0 -11
  41. package/build/http-status.js +0 -20
  42. package/build/iframe-tracking.js +0 -68
  43. package/build/interactive.js +0 -25
  44. package/build/jobs-courses.js +0 -11
  45. package/build/jobs.js +0 -11
  46. package/build/manage-my-account.js +0 -47
  47. package/build/membership.js +0 -25
  48. package/build/ng.js +0 -33
  49. package/build/perf.js +0 -39
  50. package/build/privatebrowsing.js +0 -71
  51. package/build/support.js +0 -41
  52. package/build/transmit.js +0 -107
  53. package/build/vendor/adBlockDetectionLib.js +0 -367
  54. package/build/visibility.js +0 -7
@@ -0,0 +1,79 @@
1
+ // Generated by CoffeeScript 2.7.0
2
+ // Check if a visitor is using private browsing mode (true or false)
3
+ // User agent checking and browser mode checking based on: https://gist.github.com/cou929/7973956#gistcomment-1769682
4
+ var privateBrowsingMode;
5
+
6
+ import transmit from './transmit.js';
7
+
8
+ privateBrowsingMode = function (callback) {
9
+ var reportNormalMode, reportPrivateMode, tryIndexedDB, tryLocalStorage;
10
+ reportNormalMode = function () {
11
+ return callback(false);
12
+ };
13
+ reportPrivateMode = function () {
14
+ return callback(true);
15
+ };
16
+ tryLocalStorage = function () {
17
+ var error;
18
+ try {
19
+ if (localStorage.length) {
20
+ return reportNormalMode();
21
+ } else {
22
+ localStorage.x = 1;
23
+ localStorage.removeItem('x');
24
+ return reportNormalMode();
25
+ }
26
+ } catch (error1) {
27
+ error = error1;
28
+ return reportPrivateMode();
29
+ }
30
+ };
31
+ tryIndexedDB = function () {
32
+ var db, error;
33
+ try {
34
+ db = indexedDB.open('test');
35
+ db.onsuccess = reportNormalMode;
36
+ return (db.onerror = reportPrivateMode);
37
+ } catch (error1) {
38
+ error = error1;
39
+ return reportPrivateMode();
40
+ }
41
+ };
42
+
43
+ // Blink
44
+ if (window.webkitRequestFileSystem) {
45
+ return window.webkitRequestFileSystem(
46
+ window.TEMPORARY,
47
+ 1,
48
+ reportNormalMode,
49
+ reportPrivateMode,
50
+ );
51
+ // Firefox
52
+ } else if ('MozAppearance' in document.documentElement.style) {
53
+ return tryIndexedDB();
54
+ // Safari
55
+ } else if (/constructor/i.test(window.HTMLElement)) {
56
+ return tryLocalStorage();
57
+ } else if (
58
+ !window.indexedDB &&
59
+ (window.PointerEvent || window.MSPointerEvent)
60
+ ) {
61
+ return reportPrivateMode();
62
+ } else {
63
+ // Rest
64
+ return reportNormalMode();
65
+ }
66
+ };
67
+
68
+ export default {
69
+ init: function () {
70
+ return privateBrowsingMode(function (value) {
71
+ var report;
72
+ report = {
73
+ inPrivateBrowsingMode: value,
74
+ };
75
+ return transmit.sendMore(report);
76
+ });
77
+ },
78
+ privateBrowsingMode: privateBrowsingMode,
79
+ };
@@ -13,12 +13,12 @@ import './perf.js';
13
13
 
14
14
  import './campaign.js';
15
15
 
16
- core.init("r2");
16
+ core.init('r2');
17
17
 
18
18
  if (window.addEventListener != null) {
19
- attention.init(visibility);
19
+ attention.init(visibility);
20
20
  }
21
21
 
22
22
  export default {
23
- viewId: transmit.viewId
23
+ viewId: transmit.viewId,
24
24
  };
@@ -7,13 +7,13 @@ import attention from './attention.js';
7
7
 
8
8
  import visibility from './visibility.js';
9
9
 
10
- core.init("smart-news");
10
+ core.init('smart-news');
11
11
 
12
12
  if (window.addEventListener != null) {
13
- attention.init(visibility);
13
+ attention.init(visibility);
14
14
  }
15
15
 
16
16
  export default {
17
- record: transmit.sendMore,
18
- viewId: transmit.viewId
17
+ record: transmit.sendMore,
18
+ viewId: transmit.viewId,
19
19
  };
@@ -0,0 +1,44 @@
1
+ // Generated by CoffeeScript 2.7.0
2
+ var init, sendInitialEvent;
3
+
4
+ import core from './core.js';
5
+
6
+ import transmit from './transmit.js';
7
+
8
+ import attention from './attention.js';
9
+
10
+ import visibility from './visibility.js';
11
+
12
+ import './click-path-capture.js';
13
+
14
+ import './perf.js';
15
+
16
+ import './campaign.js';
17
+
18
+ init = function () {
19
+ core.init('support');
20
+ if (window.addEventListener != null) {
21
+ return attention.init(visibility);
22
+ }
23
+ };
24
+
25
+ sendInitialEvent = function (
26
+ url = location.href,
27
+ referrer = window.document.referrer,
28
+ ) {
29
+ var e;
30
+ try {
31
+ transmit.bumpViewId();
32
+ return core.sendInitialEvent(null, url, referrer);
33
+ } catch (error) {
34
+ e = error;
35
+ return console.log(e);
36
+ }
37
+ };
38
+
39
+ export default {
40
+ init: init,
41
+ sendInitialEvent: sendInitialEvent,
42
+ record: transmit.sendMore,
43
+ viewId: transmit.viewId,
44
+ };
@@ -0,0 +1,150 @@
1
+ // Generated by CoffeeScript 2.7.0
2
+ var buildQueryString,
3
+ bumpViewId,
4
+ generatePageViewId,
5
+ isDefined,
6
+ ophanRemoteHost,
7
+ ref,
8
+ ref1,
9
+ ref2,
10
+ send,
11
+ sendInitial,
12
+ sendMore,
13
+ smartEncode,
14
+ viewId,
15
+ hasProp = {}.hasOwnProperty;
16
+
17
+ ophanRemoteHost =
18
+ (typeof window !== 'undefined' && window !== null
19
+ ? window.ophanRemoteHost
20
+ : void 0) || 'https://ophan.theguardian.com';
21
+
22
+ generatePageViewId = function () {
23
+ return (
24
+ new Date().getTime().toString(36) +
25
+ 'xxxxxxxxxxxx'.replace(/x/g, function () {
26
+ return Math.floor(Math.random() * 36).toString(36);
27
+ })
28
+ );
29
+ };
30
+
31
+ // guardian.config.ophan.pageViewId is now pregenerated in
32
+ // the Guardian Frontend Project (https://github.com/guardian/frontend)
33
+ // frontend/common/app/templates/inlineJS/blocking/config.scala.js
34
+ // If you're going to change the generation method, please update that one too
35
+ viewId =
36
+ (ref =
37
+ typeof guardian !== 'undefined' && guardian !== null
38
+ ? (ref1 = guardian.config) != null
39
+ ? (ref2 = ref1.ophan) != null
40
+ ? ref2.pageViewId
41
+ : void 0
42
+ : void 0
43
+ : void 0) != null
44
+ ? ref
45
+ : generatePageViewId();
46
+
47
+ bumpViewId = function () {
48
+ return (viewId = generatePageViewId());
49
+ };
50
+
51
+ // send the initial event associated with this page view
52
+ // store the resulting page view id
53
+ // this must only ever be called *once* subsequent calls will
54
+ // be ignored
55
+ sendInitial = function (obj) {
56
+ return send(ophanRemoteHost + `/img/1?${buildQueryString(obj)}`);
57
+ };
58
+
59
+ // send more data - if initial hasn't been sent, queue up and wait for the
60
+ // initial send to occur
61
+ smartEncode = function (value) {
62
+ if (typeof value === 'string' || typeof value === 'number') {
63
+ return encodeURIComponent(value);
64
+ } else {
65
+ return encodeURIComponent(JSON.stringify(value));
66
+ }
67
+ };
68
+
69
+ sendMore = function (obj, f) {
70
+ var prop, url, value, values;
71
+ if (!JSON) {
72
+ return;
73
+ }
74
+ values = (function () {
75
+ var results;
76
+ results = [];
77
+ for (prop in obj) {
78
+ if (!hasProp.call(obj, prop)) continue;
79
+ value = obj[prop];
80
+ if (isDefined(value)) {
81
+ results.push(`${encodeURIComponent(prop)}=${smartEncode(value)}`);
82
+ }
83
+ }
84
+ return results;
85
+ })();
86
+ if (!values.length) {
87
+ return;
88
+ }
89
+ url = `${ophanRemoteHost}/img/2?viewId=${viewId}&${values.join('&')}`;
90
+ return send(url, f);
91
+ };
92
+
93
+ isDefined = function (v) {
94
+ if (Array.isArray(v)) {
95
+ return v.length;
96
+ } else {
97
+ return v != null;
98
+ }
99
+ };
100
+
101
+ buildQueryString = function (obj) {
102
+ var prop, value, values;
103
+ obj.viewId = viewId;
104
+ values = (function () {
105
+ var results;
106
+ results = [];
107
+ for (prop in obj) {
108
+ if (!hasProp.call(obj, prop)) continue;
109
+ value = obj[prop];
110
+ if (value != null) {
111
+ results.push(
112
+ `${encodeURIComponent(prop)}=${encodeURIComponent(value)}`,
113
+ );
114
+ }
115
+ }
116
+ return results;
117
+ })();
118
+ return values.join('&');
119
+ };
120
+
121
+ send = function (url, f) {
122
+ var checker, fetchOptions, image;
123
+ if (typeof fetch === 'function') {
124
+ fetchOptions = {
125
+ method: 'GET',
126
+ keepalive: true,
127
+ };
128
+ return fetch(url, fetchOptions).then(function () {
129
+ return typeof f === 'function' ? f() : void 0;
130
+ });
131
+ } else {
132
+ image = new Image();
133
+ checker = setInterval(function () {
134
+ if (image.complete) {
135
+ if (typeof f === 'function') {
136
+ f();
137
+ }
138
+ return clearInterval(checker);
139
+ }
140
+ }, 10);
141
+ return (image.src = url);
142
+ }
143
+ };
144
+
145
+ export default {
146
+ sendInitial: sendInitial,
147
+ sendMore: sendMore,
148
+ viewId: viewId,
149
+ bumpViewId: bumpViewId,
150
+ };
@@ -0,0 +1,366 @@
1
+ // Generated by CoffeeScript 2.7.0
2
+ // TLDR; This is stripped down from the IAB ad block detection library.
3
+ // https://github.com/InteractiveAdvertisingBureau/AdBlockDetection
4
+ // The aforementioned library is not well maintained
5
+ // and had work in progress network adblocking detection
6
+
7
+ var init = function () {
8
+ var ofs = 'offset',
9
+ cl = 'client';
10
+ var noop = function () {};
11
+
12
+ var testedOnce = false;
13
+ var testExecuting = false;
14
+
15
+ var isOldIEevents = window.addEventListener === undefined;
16
+
17
+ /**
18
+ * Options set with default options initialized
19
+ *
20
+ */
21
+ var _options = {
22
+ loopDelay: 50,
23
+ maxLoop: 5,
24
+ debug: false,
25
+ found: noop,
26
+ notfound: noop,
27
+ complete: noop,
28
+ };
29
+
30
+ var listeners = []; // event response listeners
31
+ var baitNode = null;
32
+ var quickBait = {
33
+ cssClass:
34
+ 'ad-slot pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links',
35
+ };
36
+ var baitTriggers = {
37
+ nullProps: [ofs + 'Parent'],
38
+ zeroProps: [],
39
+ };
40
+
41
+ baitTriggers.zeroProps = [
42
+ ofs + 'Height',
43
+ ofs + 'Left',
44
+ ofs + 'Top',
45
+ ofs + 'Width',
46
+ ofs + 'Height',
47
+ cl + 'Height',
48
+ cl + 'Width',
49
+ ];
50
+
51
+ // result object
52
+ var exeResult = {
53
+ quick: null,
54
+ remote: null,
55
+ };
56
+
57
+ var findResult = null; // result of test for ad blocker
58
+
59
+ var timerIds = {
60
+ test: 0,
61
+ download: 0,
62
+ };
63
+
64
+ function isFunc(fn) {
65
+ return typeof fn == 'function';
66
+ }
67
+
68
+ /**
69
+ * Make a DOM element
70
+ */
71
+ function makeEl(tag, attributes) {
72
+ var k,
73
+ v,
74
+ el,
75
+ attr = attributes;
76
+ var d = document;
77
+
78
+ el = d.createElement(tag);
79
+
80
+ if (attr) {
81
+ for (k in attr) {
82
+ if (attr.hasOwnProperty(k)) {
83
+ el.setAttribute(k, attr[k]);
84
+ }
85
+ }
86
+ }
87
+
88
+ return el;
89
+ }
90
+
91
+ function attachEventListener(dom, eventName, handler) {
92
+ if (isOldIEevents) {
93
+ dom.attachEvent('on' + eventName, handler);
94
+ } else {
95
+ dom.addEventListener(eventName, handler, false);
96
+ }
97
+ }
98
+
99
+ function log(message, isError) {
100
+ if (!_options.debug && !isError) {
101
+ return;
102
+ }
103
+ if (window.console && window.console.log) {
104
+ if (isError) {
105
+ console.error('[ABD] ' + message);
106
+ } else {
107
+ console.log('[ABD] ' + message);
108
+ }
109
+ }
110
+ }
111
+
112
+ function beginTest(bait) {
113
+ log('start beginTest');
114
+ if (findResult == true) {
115
+ return;
116
+ }
117
+ testExecuting = true;
118
+ castBait(bait);
119
+
120
+ exeResult.quick = 'testing';
121
+
122
+ timerIds.test = setTimeout(function () {
123
+ reelIn(bait, 1);
124
+ }, 5);
125
+ }
126
+
127
+ /**
128
+ * Create the bait node to see how the browser page reacts
129
+ */
130
+ function castBait(bait) {
131
+ var i,
132
+ d = document,
133
+ b = d.body;
134
+ var t;
135
+ var baitStyle =
136
+ 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;';
137
+
138
+ if (bait == null || typeof bait == 'string') {
139
+ log('invalid bait being cast');
140
+ return;
141
+ }
142
+
143
+ if (bait.style != null) {
144
+ baitStyle += bait.style;
145
+ }
146
+
147
+ baitNode = makeEl('div', {
148
+ class: bait.cssClass,
149
+ style: baitStyle,
150
+ });
151
+
152
+ log('adding bait node to DOM');
153
+
154
+ b.appendChild(baitNode);
155
+
156
+ // touch these properties
157
+ for (i = 0; i < baitTriggers.nullProps.length; i++) {
158
+ t = baitNode[baitTriggers.nullProps[i]];
159
+ }
160
+ for (i = 0; i < baitTriggers.zeroProps.length; i++) {
161
+ t = baitNode[baitTriggers.zeroProps[i]];
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Run tests to see if browser has taken the bait and blocked the bait element
167
+ */
168
+ function reelIn(bait, attemptNum) {
169
+ var i, k, v;
170
+ var body = document.body;
171
+ var found = false;
172
+
173
+ if (baitNode == null) {
174
+ log('recast bait');
175
+ castBait(bait || quickBait);
176
+ }
177
+
178
+ if (typeof bait == 'string') {
179
+ log('invalid bait used', true);
180
+ if (clearBaitNode()) {
181
+ setTimeout(function () {
182
+ testExecuting = false;
183
+ }, 5);
184
+ }
185
+
186
+ return;
187
+ }
188
+
189
+ if (timerIds.test > 0) {
190
+ clearTimeout(timerIds.test);
191
+ timerIds.test = 0;
192
+ }
193
+
194
+ // test for issues
195
+
196
+ if (body.getAttribute('abp') !== null) {
197
+ log('found adblock body attribute');
198
+ found = true;
199
+ }
200
+
201
+ for (i = 0; i < baitTriggers.nullProps.length; i++) {
202
+ if (baitNode[baitTriggers.nullProps[i]] == null) {
203
+ if (attemptNum > 4) found = true;
204
+ log('found adblock null attr: ' + baitTriggers.nullProps[i]);
205
+ break;
206
+ }
207
+ if (found == true) {
208
+ break;
209
+ }
210
+ }
211
+
212
+ for (i = 0; i < baitTriggers.zeroProps.length; i++) {
213
+ if (found == true) {
214
+ break;
215
+ }
216
+ if (baitNode[baitTriggers.zeroProps[i]] == 0) {
217
+ if (attemptNum > 4) found = true;
218
+ log('found adblock zero attr: ' + baitTriggers.zeroProps[i]);
219
+ }
220
+ }
221
+
222
+ if (window.getComputedStyle !== undefined) {
223
+ var baitTemp = window.getComputedStyle(baitNode, null);
224
+ if (
225
+ baitTemp.getPropertyValue('display') == 'none' ||
226
+ baitTemp.getPropertyValue('visibility') == 'hidden'
227
+ ) {
228
+ if (attemptNum > 4) found = true;
229
+ log('found adblock computedStyle indicator');
230
+ }
231
+ }
232
+
233
+ testedOnce = true;
234
+
235
+ if (found || attemptNum++ >= _options.maxLoop) {
236
+ findResult = found;
237
+ log('exiting test loop - value: ' + findResult);
238
+ notifyListeners();
239
+ if (clearBaitNode()) {
240
+ setTimeout(function () {
241
+ testExecuting = false;
242
+ }, 5);
243
+ }
244
+ } else {
245
+ timerIds.test = setTimeout(function () {
246
+ reelIn(bait, attemptNum);
247
+ }, _options.loopDelay);
248
+ }
249
+ }
250
+
251
+ function clearBaitNode() {
252
+ if (baitNode === null) {
253
+ return true;
254
+ }
255
+
256
+ try {
257
+ if (isFunc(baitNode.remove)) {
258
+ baitNode.remove();
259
+ }
260
+ document.body.removeChild(baitNode);
261
+ } catch (ex) {}
262
+ baitNode = null;
263
+
264
+ return true;
265
+ }
266
+
267
+ /**
268
+ * Halt the test and any pending timeouts
269
+ */
270
+ function stopFishing() {
271
+ if (timerIds.test > 0) {
272
+ clearTimeout(timerIds.test);
273
+ }
274
+ if (timerIds.download > 0) {
275
+ clearTimeout(timerIds.download);
276
+ }
277
+
278
+ clearBaitNode();
279
+ }
280
+
281
+ /**
282
+ * Fire all registered listeners
283
+ */
284
+ function notifyListeners() {
285
+ var i, funcs;
286
+ if (findResult === null) {
287
+ return;
288
+ }
289
+ for (i = 0; i < listeners.length; i++) {
290
+ funcs = listeners[i];
291
+ try {
292
+ if (funcs != null) {
293
+ if (isFunc(funcs['complete'])) {
294
+ funcs['complete'](findResult);
295
+ }
296
+
297
+ if (findResult && isFunc(funcs['found'])) {
298
+ funcs['found']();
299
+ } else if (findResult === false && isFunc(funcs['notfound'])) {
300
+ funcs['notfound']();
301
+ }
302
+ }
303
+ } catch (ex) {
304
+ log('Failure in notify listeners ' + ex.Message, true);
305
+ }
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Attaches event listener or fires if events have already passed.
311
+ */
312
+ function attachOrFire() {
313
+ var fireNow = false;
314
+ var fn;
315
+
316
+ if (document.readyState) {
317
+ if (document.readyState == 'complete') {
318
+ fireNow = true;
319
+ }
320
+ }
321
+
322
+ fn = function () {
323
+ beginTest(quickBait, false);
324
+ };
325
+
326
+ if (fireNow) {
327
+ fn();
328
+ } else {
329
+ attachEventListener(window, 'load', fn);
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Public interface of adblock detector
335
+ */
336
+ return function (options) {
337
+ var k, v, funcs;
338
+
339
+ if (!options) {
340
+ return;
341
+ }
342
+
343
+ funcs = {
344
+ complete: noop,
345
+ found: noop,
346
+ notfound: noop,
347
+ };
348
+
349
+ for (k in options) {
350
+ if (options.hasOwnProperty(k)) {
351
+ if (k == 'complete' || k == 'found' || k == 'notFound') {
352
+ funcs[k.toLowerCase()] = options[k];
353
+ } else {
354
+ _options[k] = options[k];
355
+ }
356
+ }
357
+ }
358
+
359
+ listeners.push(funcs);
360
+
361
+ attachOrFire();
362
+ };
363
+ };
364
+ export default {
365
+ init: init(),
366
+ };
@@ -0,0 +1,20 @@
1
+ // Generated by CoffeeScript 2.7.0
2
+ export default {
3
+ state: function () {
4
+ return (
5
+ document.visibilityState ||
6
+ document.webkitVisibilityState ||
7
+ document.mozVisibilityState ||
8
+ document.msVisibilityState
9
+ );
10
+ },
11
+ changeEvent: document.visibilityState
12
+ ? 'visibilitychange'
13
+ : document.webkitVisibilityState
14
+ ? 'webkitvisibilitychange'
15
+ : document.mozVisibilityState
16
+ ? 'mozvisibilitychange'
17
+ : document.msVisibilityState
18
+ ? 'msvisibilitychange'
19
+ : void 0,
20
+ };
@@ -3,9 +3,9 @@ import core from './core.js';
3
3
 
4
4
  import transmit from './transmit.js';
5
5
 
6
- core.init("witness");
6
+ core.init('witness');
7
7
 
8
8
  export default {
9
- record: transmit.sendMore,
10
- viewId: transmit.viewId
9
+ record: transmit.sendMore,
10
+ viewId: transmit.viewId,
11
11
  };