@guardian/ophan-tracker-js 2.2.0 → 2.2.2
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.
- package/NPM-dist/attention.js +1 -1
- package/NPM-dist/campaign.js +1 -1
- package/NPM-dist/click-path-capture.js +5 -1
- package/NPM-dist/contribution.js +1 -1
- package/NPM-dist/core.js +1 -1
- package/NPM-dist/embed.js +1 -1
- package/NPM-dist/fb-instant.js +1 -1
- package/NPM-dist/holidays.js +1 -1
- package/NPM-dist/interactive.js +1 -1
- package/NPM-dist/jobs-courses.js +1 -1
- package/NPM-dist/jobs.js +1 -1
- package/NPM-dist/manage-my-account.js +1 -1
- package/NPM-dist/membership.js +1 -1
- package/NPM-dist/ng.js +1 -1
- package/NPM-dist/privatebrowsing.js +1 -1
- package/NPM-dist/r2.js +1 -1
- package/NPM-dist/smart-news.js +1 -1
- package/NPM-dist/support.js +1 -1
- package/NPM-dist/tests/click-path-capture.test.js +30 -3
- package/NPM-dist/witness.js +1 -1
- package/package.json +2 -1
package/NPM-dist/attention.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
|
-
import transmit from './transmit';
|
|
2
|
+
import transmit from './transmit.js';
|
|
3
3
|
import components from './components.js';
|
|
4
4
|
// The upworthy definition of attention minutes, from
|
|
5
5
|
// http://upworthy.github.io/2014/06/implementing-attention-minutes-part-1/ :
|
package/NPM-dist/campaign.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ophan from './core.js';
|
|
2
|
-
import transmit from './transmit';
|
|
2
|
+
import transmit from './transmit.js';
|
|
3
3
|
/**
|
|
4
4
|
* Finds the closest ancestor anchor (`<a>`) element of the given element.
|
|
5
5
|
*
|
|
@@ -43,6 +43,10 @@ if (typeof document.addEventListener === 'function') {
|
|
|
43
43
|
document.addEventListener('click', function (e) {
|
|
44
44
|
let anchorTarget, info;
|
|
45
45
|
anchorTarget = validAncestorAnchorElement(e.target);
|
|
46
|
+
if (!anchorTarget) {
|
|
47
|
+
// If no anchor element was clicked, exit early.
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
46
50
|
info = {
|
|
47
51
|
from: [location.protocol, '//', location.host, location.pathname].join(''),
|
|
48
52
|
to: anchorTarget ? anchorTarget.href : void 0,
|
package/NPM-dist/contribution.js
CHANGED
package/NPM-dist/core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let init, sendInitialEvent, storeDataToSendOnNextEvent, hasProp = {}.hasOwnProperty;
|
|
2
|
-
import transmit from './transmit';
|
|
2
|
+
import transmit from './transmit.js';
|
|
3
3
|
import visibility from './visibility.js';
|
|
4
4
|
import adblockDetection from './adblock-detection.js';
|
|
5
5
|
const VERSION = 17;
|
package/NPM-dist/embed.js
CHANGED
package/NPM-dist/fb-instant.js
CHANGED
package/NPM-dist/holidays.js
CHANGED
package/NPM-dist/interactive.js
CHANGED
package/NPM-dist/jobs-courses.js
CHANGED
package/NPM-dist/jobs.js
CHANGED
package/NPM-dist/membership.js
CHANGED
package/NPM-dist/ng.js
CHANGED
package/NPM-dist/r2.js
CHANGED
package/NPM-dist/smart-news.js
CHANGED
package/NPM-dist/support.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import clickPathCapture, { validAncestorAnchorElement, getContainingComponent } from '../click-path-capture.js';
|
|
2
|
+
import transmit from '../transmit.js';
|
|
3
|
+
import ophan from '../core.js';
|
|
2
4
|
const { getDataLinkNames } = clickPathCapture;
|
|
3
5
|
describe('click-path-capture.js', () => {
|
|
4
6
|
beforeAll(() => {
|
|
5
7
|
document.body.innerHTML = `
|
|
6
8
|
<div data-component="component1">
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
9
|
+
<div id="testElement4">
|
|
10
|
+
<a href="#" data-link-name="link1" id="link1">
|
|
11
|
+
<span id="testElement1"></span>
|
|
12
|
+
</a>
|
|
13
|
+
<span id="nonLinkElement">Non-link element</span>
|
|
14
|
+
</div>
|
|
10
15
|
</div>
|
|
11
16
|
<div id="testElement2" data-component="component2"></div>
|
|
12
17
|
`;
|
|
@@ -41,4 +46,26 @@ describe('click-path-capture.js', () => {
|
|
|
41
46
|
expect(getDataLinkNames(element)).toEqual([]);
|
|
42
47
|
});
|
|
43
48
|
});
|
|
49
|
+
describe('click event handling', () => {
|
|
50
|
+
let transmitSendMoreSpy, ophanStoreDataToSendOnNextEventSpy;
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
transmitSendMoreSpy = jest.spyOn(transmit, 'sendMore').mockImplementation(() => { });
|
|
53
|
+
ophanStoreDataToSendOnNextEventSpy = jest.spyOn(ophan, 'storeDataToSendOnNextEvent').mockImplementation(() => { });
|
|
54
|
+
});
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
jest.clearAllMocks();
|
|
57
|
+
});
|
|
58
|
+
test('should send request and store data when a link is clicked', () => {
|
|
59
|
+
const element = document.getElementById('testElement1');
|
|
60
|
+
element.click();
|
|
61
|
+
expect(transmitSendMoreSpy).toHaveBeenCalled();
|
|
62
|
+
expect(ophanStoreDataToSendOnNextEventSpy).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
test('should not send request when a non-link element within a container is clicked', () => {
|
|
65
|
+
const element = document.getElementById('testElement4');
|
|
66
|
+
element.click();
|
|
67
|
+
expect(transmitSendMoreSpy).not.toHaveBeenCalled();
|
|
68
|
+
expect(ophanStoreDataToSendOnNextEventSpy).not.toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
44
71
|
});
|
package/NPM-dist/witness.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/ophan-tracker-js",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build-for-cdn": "NODE_ENV=production npx rollup -c",
|
|
33
33
|
"build-for-npm": "tsc",
|
|
34
|
+
"pretest": "tsc",
|
|
34
35
|
"test": "jest",
|
|
35
36
|
"format": "npx prettier --write ."
|
|
36
37
|
},
|