Skip to content

Commit 9d1bd0a

Browse files
committed
Upgrade ophan tracker canary
1 parent 77ef83d commit 9d1bd0a

5 files changed

Lines changed: 78 additions & 44 deletions

File tree

dotcom-rendering/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
"@guardian/bridget": "8.13.1",
3333
"@guardian/browserslist-config": "6.1.0",
3434
"@guardian/cdk": "catalog:",
35-
"@guardian/consent-manager": "1.0.0",
3635
"@guardian/commercial-core": "34.0.0",
36+
"@guardian/consent-manager": "1.0.0",
3737
"@guardian/core-web-vitals": "7.0.0",
3838
"@guardian/eslint-config": "catalog:",
3939
"@guardian/identity-auth": "6.0.1",
4040
"@guardian/identity-auth-frontend": "8.1.0",
4141
"@guardian/libs": "32.0.0",
42-
"@guardian/ophan-tracker-js": "4.0.2",
42+
"@guardian/ophan-tracker-js": "0.0.0-canary-20260622142809",
4343
"@guardian/react-crossword": "17.1.0",
4444
"@guardian/shimport": "1.0.2",
4545
"@guardian/source": "12.2.1",

dotcom-rendering/src/client/ophan/ophan.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const getOphan = async (
2222

2323
if (renderingTarget === 'Apps') {
2424
cachedOphan = {
25+
init: () => undefined,
26+
sendInitialEvent: () => undefined,
2527
setEventEmitter: () => undefined, // We don't currently have a custom eventEmitter on DCR - like 'mediator' in Frontend.
2628
trackComponentAttention: () => undefined,
2729
record: (e) => {
@@ -40,6 +42,9 @@ export const getOphan = async (
4042
);
4143
}
4244
},
45+
bumpViewId: () => undefined,
46+
getViewId: () => 'Apps',
47+
getPageViewId: () => 'Apps',
4348
viewId: 'Apps',
4449
pageViewId: 'Apps',
4550
};
@@ -52,6 +57,8 @@ export const getOphan = async (
5257
/* webpackMode: "eager" */ '@guardian/ophan-tracker-js'
5358
);
5459

60+
ophan.init('ng');
61+
5562
const record: (typeof ophan)['record'] = (event, callback) => {
5663
ophan.record(event, callback);
5764
log('dotcom', '🧿 Ophan event recorded:', event);

dotcom-rendering/src/components/YoutubeAtom/eventEmitters.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ const getAppsMediaEvent = async (
5050

5151
export type OphanVideoStyle = 'youtube' | 'loop' | 'cinemagraph' | 'default';
5252

53+
const dispatchOphanAttentionEvent = (
54+
eventType: 'videoPlaying' | 'videoPause' | 'videoEnded',
55+
) => {
56+
const event = new Event(eventType, { bubbles: true });
57+
document.dispatchEvent(event);
58+
};
59+
5360
const ophanTrackerWeb = (id: string, videoStyle: OphanVideoStyle) => {
5461
return (trackingEvent: VideoEventKey): void => {
5562
void getOphan('Web').then((ophan) => {
@@ -69,6 +76,22 @@ const ophanTrackerWeb = (id: string, videoStyle: OphanVideoStyle) => {
6976
};
7077
};
7178

79+
const ophanAttention = () => {
80+
return (trackingEvent: VideoEventKey): void => {
81+
if (trackingEvent === 'play' || trackingEvent === 'resume') {
82+
dispatchOphanAttentionEvent('videoPlaying');
83+
}
84+
85+
if (trackingEvent === 'pause') {
86+
dispatchOphanAttentionEvent('videoPause');
87+
}
88+
89+
if (trackingEvent === 'end') {
90+
dispatchOphanAttentionEvent('videoEnded');
91+
}
92+
};
93+
};
94+
7295
const ophanTrackerApps = (id: string, videoStyle: OphanVideoStyle) => {
7396
return (trackingEvent: VideoEventKey): void => {
7497
void getAppsMediaEvent(trackingEvent).then((appsMediaEvent) => {
@@ -88,4 +111,4 @@ const ophanTrackerApps = (id: string, videoStyle: OphanVideoStyle) => {
88111
};
89112
};
90113

91-
export { ophanTrackerApps, ophanTrackerWeb };
114+
export { ophanAttention, ophanTrackerApps, ophanTrackerWeb };

dotcom-rendering/src/components/YoutubeBlockComponent.island.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import type { ArticleMedia } from '../types/mainMedia';
99
import { Caption } from './Caption';
1010
import type { ResponsiveFontSize } from './CardHeadline';
1111
import { useConfig } from './ConfigContext';
12-
import { ophanTrackerApps, ophanTrackerWeb } from './YoutubeAtom/eventEmitters';
12+
import {
13+
ophanAttention,
14+
ophanTrackerApps,
15+
ophanTrackerWeb,
16+
} from './YoutubeAtom/eventEmitters';
1317
import { YoutubeAtom } from './YoutubeAtom/YoutubeAtom';
1418
import { YoutubeAtomExpiredOverlay } from './YoutubeAtom/YoutubeAtomExpiredOverlay';
1519

@@ -195,7 +199,7 @@ export const YoutubeBlockComponent = ({
195199
duration={duration}
196200
eventEmitters={
197201
renderingTarget === 'Web'
198-
? [ophanTrackerWeb(id, 'youtube')]
202+
? [ophanTrackerWeb(id, 'youtube'), ophanAttention()]
199203
: [ophanTrackerApps(id, 'youtube')]
200204
}
201205
format={format}

0 commit comments

Comments
 (0)