@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.
@@ -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/ :
@@ -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 perf from './perf.js';
4
4
  const start = perf?.timing?.domComplete ?? performance.now();
5
5
  // DFP ads
@@ -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,
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  import attention from './attention.js';
5
5
  import visibility from './visibility.js';
6
6
  import './click-path-capture.js';
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
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  core.init('embed');
5
5
  export default {
6
6
  record: transmit.sendMore,
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  core.init('facebook-instant-article');
5
5
  export default {
6
6
  viewId: transmit.viewId,
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  core.init('holidays');
5
5
  export default {
6
6
  record: transmit.sendMore,
@@ -1,5 +1,5 @@
1
1
  import core from './core.js';
2
- import transmit from './transmit';
2
+ import transmit from './transmit.js';
3
3
  import attention from './attention.js';
4
4
  import './click-path-capture.js';
5
5
  if (window.guardian?.ophan) {
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  core.init('jobs-courses');
5
5
  export default {
6
6
  record: transmit.sendMore,
package/NPM-dist/jobs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  core.init('jobs');
5
5
  export default {
6
6
  record: transmit.sendMore,
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  import attention from './attention.js';
5
5
  import visibility from './visibility.js';
6
6
  import './click-path-capture.js';
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  import attention from './attention.js';
5
5
  import visibility from './visibility.js';
6
6
  import './click-path-capture.js';
package/NPM-dist/ng.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import core from './core.js';
2
- import transmit from './transmit';
2
+ import transmit from './transmit.js';
3
3
  import attention from './attention.js';
4
4
  import visibility from './visibility.js';
5
5
  import privatebrowsing from './privatebrowsing.js';
@@ -1,4 +1,4 @@
1
- import transmit from './transmit';
1
+ import transmit from './transmit.js';
2
2
  /*
3
3
  TO-DO:
4
4
  This function could probably be simplified with an async function.
package/NPM-dist/r2.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  import attention from './attention.js';
5
5
  import visibility from './visibility.js';
6
6
  import './click-path-capture.js';
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  import attention from './attention.js';
5
5
  import visibility from './visibility.js';
6
6
  core.init('smart-news');
@@ -1,5 +1,5 @@
1
1
  import core from './core.js';
2
- import transmit from './transmit';
2
+ import transmit from './transmit.js';
3
3
  import attention from './attention.js';
4
4
  import visibility from './visibility.js';
5
5
  import './click-path-capture.js';
@@ -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
- <a href="#" data-link-name="link1">
8
- <span id="testElement1"></span>
9
- </a>
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
  });
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  import core from './core.js';
3
- import transmit from './transmit';
3
+ import transmit from './transmit.js';
4
4
  core.init('witness');
5
5
  export default {
6
6
  record: transmit.sendMore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/ophan-tracker-js",
3
- "version": "2.2.0",
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
  },