@guardian/ophan-tracker-js 2.6.0 → 2.6.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/core.js CHANGED
@@ -9,12 +9,6 @@ let platform = null;
9
9
  const MaximumComponentNameLength = 50;
10
10
  init = function (servingPlatform, httpStatus) {
11
11
  platform = servingPlatform;
12
- window.addEventListener('pageshow', function (event) {
13
- if (event.persisted) {
14
- transmit.bumpViewId();
15
- sendInitialEvent(httpStatus, location.href, window.document.referrer, 'bfcache');
16
- }
17
- }, false);
18
12
  if (visibility.state() !== 'prerender') {
19
13
  return sendInitialEvent(httpStatus);
20
14
  }
@@ -93,7 +87,7 @@ sendInitialEvent = function (httpStatus, url = location.href, referrer = window.
93
87
  if (loadType !== 'normal') {
94
88
  event.loadType = loadType;
95
89
  }
96
- appendContentType(event);
90
+ appendContentType(event, platform, window.guardian);
97
91
  appendDataFromLocalStorageToEvent(event);
98
92
  transmit.sendInitial(event);
99
93
  return adblockDetection.run().then(function (adBlockerEnabled) {
@@ -204,13 +198,13 @@ storeDataToSendOnNextEvent = function (newData) {
204
198
  /**
205
199
  * Determines the 'content type' based on the platform and guardian object.
206
200
  * @param {Record<string, unknown>} event - The event object that will be updated with contentType.
207
- * @param {string} platform - The current platform ('next-gen', 'embed' or other).
208
- * @param {Record<string, unknown>} guardian - The guardian object.
201
+ * @param {string} localPlatform - The current platform ('next-gen', 'embed' or other).
202
+ * @param {Record<string, unknown>} localGuardian - The guardian object.
209
203
  */
210
- const appendContentType = (event, platform, guardian) => {
211
- const contentType = platform === 'next-gen' || platform === 'embed'
212
- ? guardian?.config?.page?.contentType
213
- : guardian?.page?.contentTypes;
204
+ const appendContentType = (event, localPlatform, localGuardian) => {
205
+ const contentType = localPlatform === 'next-gen' || localPlatform === 'embed'
206
+ ? localGuardian?.config?.page?.contentType
207
+ : localGuardian?.page?.contentTypes;
214
208
  if (contentType) {
215
209
  event.contentType = contentType.toLowerCase();
216
210
  }
@@ -163,57 +163,3 @@ describe('appendContentType', () => {
163
163
  expect(event.contentType).toBeUndefined();
164
164
  });
165
165
  });
166
- describe('loadType pageshow handling', () => {
167
- let mockAddEventListener;
168
- let pageShowHandler;
169
- let originalSendInitial;
170
- beforeEach(() => {
171
- jest.clearAllMocks();
172
- mockAddEventListener = jest.fn();
173
- window.addEventListener = mockAddEventListener;
174
- originalSendInitial = transmit.sendInitial;
175
- transmit.sendInitial = jest.fn();
176
- const core = require('../core.js').default;
177
- core.init('next-gen', 200);
178
- const pageShowCall = mockAddEventListener.mock.calls.find(call => call[0] === 'pageshow');
179
- pageShowHandler = pageShowCall ? pageShowCall[1] : null;
180
- });
181
- afterEach(() => {
182
- transmit.sendInitial = originalSendInitial;
183
- });
184
- it('should register pageshow event listener during init', () => {
185
- expect(mockAddEventListener).toHaveBeenCalledWith('pageshow', expect.any(Function), false);
186
- });
187
- it('should call sendInitialEvent with loadType=bfcache when pageshow event has persisted=true', () => {
188
- expect(pageShowHandler).toBeTruthy();
189
- transmit.sendInitial.mockClear();
190
- // Simulate a bfcache restore event
191
- const mockEvent = { persisted: true };
192
- pageShowHandler(mockEvent);
193
- expect(transmit.sendInitial).toHaveBeenCalledWith(expect.objectContaining({
194
- loadType: 'bfcache'
195
- }));
196
- });
197
- it('should call bumpViewId when pageshow event has persisted=true', () => {
198
- expect(pageShowHandler).toBeTruthy();
199
- transmit.bumpViewId.mockClear();
200
- // Simulate a bfcache restore event
201
- const mockEvent = { persisted: true };
202
- pageShowHandler(mockEvent);
203
- expect(transmit.bumpViewId).toHaveBeenCalledTimes(1);
204
- });
205
- it('should not call sendInitialEvent when pageshow event has persisted=false', () => {
206
- expect(pageShowHandler).toBeTruthy();
207
- transmit.sendInitial.mockClear();
208
- const mockEvent = { persisted: false };
209
- pageShowHandler(mockEvent);
210
- expect(transmit.sendInitial).not.toHaveBeenCalled();
211
- });
212
- it('should handle pageshow event without persisted property', () => {
213
- expect(pageShowHandler).toBeTruthy();
214
- transmit.sendInitial.mockClear();
215
- const mockEvent = {};
216
- pageShowHandler(mockEvent);
217
- expect(transmit.sendInitial).not.toHaveBeenCalled();
218
- });
219
- });
@@ -58,7 +58,7 @@ declare function processCaptures(): void;
58
58
  /**
59
59
  * Determines the 'content type' based on the platform and guardian object.
60
60
  * @param {Record<string, unknown>} event - The event object that will be updated with contentType.
61
- * @param {string} platform - The current platform ('next-gen', 'embed' or other).
62
- * @param {Record<string, unknown>} guardian - The guardian object.
61
+ * @param {string} localPlatform - The current platform ('next-gen', 'embed' or other).
62
+ * @param {Record<string, unknown>} localGuardian - The guardian object.
63
63
  */
64
- declare function appendContentType(event: Record<string, unknown>, platform: string, guardian: Record<string, unknown>): void;
64
+ declare function appendContentType(event: Record<string, unknown>, localPlatform: string, localGuardian: Record<string, unknown>): void;
@@ -1 +1 @@
1
- export type TComponentType = 'READERS_QUESTIONS_ATOM' | 'QANDA_ATOM' | 'PROFILE_ATOM' | 'GUIDE_ATOM' | 'TIMELINE_ATOM' | 'NEWSLETTER_SUBSCRIPTION' | 'SURVEYS_QUESTIONS' | 'ACQUISITIONS_EPIC' | 'ACQUISITIONS_ENGAGEMENT_BANNER' | 'ACQUISITIONS_THANK_YOU_EPIC' | 'ACQUISITIONS_HEADER' | 'ACQUISITIONS_FOOTER' | 'ACQUISITIONS_INTERACTIVE_SLICE' | 'ACQUISITIONS_NUGGET' | 'ACQUISITIONS_STANDFIRST' | 'ACQUISITIONS_THRASHER' | 'ACQUISITIONS_EDITORIAL_LINK' | 'ACQUISITIONS_MANAGE_MY_ACCOUNT' | 'ACQUISITIONS_BUTTON' | 'ACQUISITIONS_OTHER' | 'APP_ADVERT' | 'APP_AUDIO' | 'APP_BUTTON' | 'APP_CARD' | 'APP_CROSSWORDS' | 'APP_ENGAGEMENT_BANNER' | 'APP_EPIC' | 'APP_GALLERY' | 'APP_LINK' | 'APP_NAVIGATION_ITEM' | 'APP_SCREEN' | 'APP_THRASHER' | 'APP_VIDEO' | 'AUDIO_ATOM' | 'CHART_ATOM' | 'ACQUISITIONS_MERCHANDISING' | 'ACQUISITIONS_HOUSE_ADS' | 'SIGN_IN_GATE' | 'ACQUISITIONS_SUBSCRIPTIONS_BANNER' | 'MOBILE_STICKY_AD' | 'IDENTITY_AUTHENTICATION' | 'RETENTION_ENGAGEMENT_BANNER' | 'ACQUISITION_SUPPORT_SITE' | 'RETENTION_EPIC' | 'CONSENT' | 'LIVE_BLOG_PINNED_POST' | 'STICKY_VIDEO' | 'KEY_EVENT_CARD' | 'RETENTION_HEADER' | 'SLIDESHOW' | 'APP_FEATURE' | 'CARD' | 'CAROUSEL' | 'CONTAINER' | 'MENU' | 'ACQUISITIONS_GUTTER' | 'INTERACTIVE_ATOM' | 'LOOP_VIDEO' | 'AD_BLOCK_RECOVERY' | 'SIGN_IN_GOOGLE_ONE_TAP';
1
+ export type TComponentType = 'READERS_QUESTIONS_ATOM' | 'QANDA_ATOM' | 'PROFILE_ATOM' | 'GUIDE_ATOM' | 'TIMELINE_ATOM' | 'NEWSLETTER_SUBSCRIPTION' | 'SURVEYS_QUESTIONS' | 'ACQUISITIONS_EPIC' | 'ACQUISITIONS_ENGAGEMENT_BANNER' | 'ACQUISITIONS_THANK_YOU_EPIC' | 'ACQUISITIONS_HEADER' | 'ACQUISITIONS_FOOTER' | 'ACQUISITIONS_INTERACTIVE_SLICE' | 'ACQUISITIONS_NUGGET' | 'ACQUISITIONS_STANDFIRST' | 'ACQUISITIONS_THRASHER' | 'ACQUISITIONS_EDITORIAL_LINK' | 'ACQUISITIONS_MANAGE_MY_ACCOUNT' | 'ACQUISITIONS_BUTTON' | 'ACQUISITIONS_OTHER' | 'APP_ADVERT' | 'APP_AUDIO' | 'APP_BUTTON' | 'APP_CARD' | 'APP_CROSSWORDS' | 'APP_ENGAGEMENT_BANNER' | 'APP_EPIC' | 'APP_GALLERY' | 'APP_LINK' | 'APP_NAVIGATION_ITEM' | 'APP_SCREEN' | 'APP_THRASHER' | 'APP_VIDEO' | 'AUDIO_ATOM' | 'CHART_ATOM' | 'ACQUISITIONS_MERCHANDISING' | 'ACQUISITIONS_HOUSE_ADS' | 'SIGN_IN_GATE' | 'ACQUISITIONS_SUBSCRIPTIONS_BANNER' | 'MOBILE_STICKY_AD' | 'IDENTITY_AUTHENTICATION' | 'RETENTION_ENGAGEMENT_BANNER' | 'ACQUISITION_SUPPORT_SITE' | 'RETENTION_EPIC' | 'CONSENT' | 'LIVE_BLOG_PINNED_POST' | 'STICKY_VIDEO' | 'KEY_EVENT_CARD' | 'RETENTION_HEADER' | 'SLIDESHOW' | 'APP_FEATURE' | 'CARD' | 'CAROUSEL' | 'CONTAINER' | 'MENU' | 'ACQUISITIONS_GUTTER' | 'INTERACTIVE_ATOM' | 'LOOP_VIDEO' | 'AD_BLOCK_RECOVERY' | 'SIGN_IN_GOOGLE_ONE_TAP' | 'BF_CACHE';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/ophan-tracker-js",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=16"