@glomex/integration-analytics 1.1480.0

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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 glomex GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @glomex/integration-analytics
2
+
3
+ A unified analytics integration package for the [turbo player](https://www.npmjs.com/package/@glomex/integration-web-component). This package provides adapters for various analytics providers including NPAW/Youbora, with planned support for Nielsen, Comscore, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @glomex/integration-analytics
9
+ ```
10
+
11
+ ## Available Adapters
12
+
13
+ ### NPAW/Youbora
14
+
15
+ [NPAW analytics](https://npaw.com/) integration for video analytics and quality of experience monitoring.
16
+
17
+ ```typescript
18
+ import { connectToNpaw } from '@glomex/integration-analytics/npaw';
19
+
20
+ // Get your integration element
21
+ const integration = document.querySelector('glomex-integration');
22
+
23
+ // Simple setup for NPAW analytics (that also handles consent)
24
+ const { npawPlugin, destroy } = connectToNpaw(integration, 'your-npaw-account-code');
25
+ ```
26
+
27
+ #### Advanced NPAW Configuration
28
+
29
+ ```typescript
30
+ import { connectToNpaw } from '@glomex/integration-analytics/npaw';
31
+
32
+ const { npawPlugin, destroy } = connectToNpaw(integration, 'your-npaw-account-code', {
33
+ appName: 'my-app',
34
+ appVersion: '1.0.0'
35
+ });
36
+
37
+ npawPlugin.setAnalyticsOptions({
38
+ userId: 'my-user-id',
39
+ 'content.customDimensions': {
40
+ tenant: 'my-tenant'
41
+ }
42
+ });
43
+
44
+ // Clean up when done
45
+ destroy();
46
+ ```
47
+
48
+ #### Direct NPAW Integration
49
+
50
+ ```typescript
51
+ import { NpawTurboPlayerAdapter } from '@glomex/integration-analytics/npaw';
52
+ import NpawPlugin from 'npaw-plugin';
53
+
54
+ const npawPlugin = new NpawPlugin('your-npaw-account-code');
55
+ npawPlugin.registerAdapterFromClass(integration, NpawTurboPlayerAdapter);
56
+ ```
57
+
58
+ ## Planned Adapters
59
+
60
+ The following adapters are planned for future releases:
61
+
62
+ - [Nielsen](https://www.nielsen.com/solutions/audience-measurement/streaming-measurement/) - `@glomex/integration-analytics/nielsen`
63
+ - [Comscore](https://www.comscore.com/) - `@glomex/integration-analytics/comscore`
64
+ - [GfK Sensic](https://sensic.net/) - `@glomex/integration-analytics/sensic`
65
+ - [Datazoom](https://www.datazoom.io/) - `@glomex/integration-analytics/datazoom`
66
+
67
+ ## Features
68
+
69
+ - 🎯 **Easy Integration**: Simple setup with turbo player
70
+ - 📊 **Multiple Providers**: Support for various analytics providers
71
+ - 🔧 **Smart Metadata Mapping**: Automatically maps player content metadata to each analytics provider's format, with full support for custom overrides
72
+ - 📱 **Cross-Platform**: Works with web, mobile web, and embedded players
73
+ - 🔒 **Consent Handling**: Built-in consent management support
74
+
75
+ ## License
76
+
77
+ MIT
78
+
79
+ ## Support
80
+
81
+ For issues and questions, please visit the [glomex documentation](https://docs.glomex.com) or contact support.
@@ -0,0 +1,315 @@
1
+ import { IntegrationElement, IntegrationElementEventMap } from '@glomex/integration-web-component';
2
+ import NpawPlugin from 'npaw-plugin';
3
+
4
+ /**
5
+ * Interfaces gathered from the npm module npaw-plugin by generating source from the contained sourcemap.
6
+ *
7
+ * @see https://www.npmjs.com/package/npaw-plugin
8
+ */
9
+ interface Adapter {
10
+ flags: AdapterFlags;
11
+ monitor: PlayheadMonitor | null;
12
+ player: unknown;
13
+ plugin: {
14
+ getAdsAdapter(): AdapterAd;
15
+ setAdsAdapter(adapterClass: unknown, videoKey: string): void;
16
+ removeAdsAdapter(videoKey?: string): void;
17
+ };
18
+ getVideo(): {
19
+ getVideoKey(): string;
20
+ removeAdsAdapter(videoKey?: string): void;
21
+ options: Record<string, unknown>;
22
+ };
23
+ getNpawUtils(): {
24
+ calculateAdViewability(player: HTMLElement): boolean;
25
+ buildRenditionString(width: number, height: number, bitrate: number): string;
26
+ };
27
+ getNpawReference(): {
28
+ Constants: {
29
+ AdPosition: {
30
+ Preroll: string;
31
+ Midroll: string;
32
+ Postroll: string;
33
+ };
34
+ };
35
+ };
36
+ setPlayer(player: unknown): void;
37
+ registerListeners(): void;
38
+ unregisterListeners(): void;
39
+ monitorPlayhead(monitorBuffers: boolean, monitorSeeks: boolean, interval?: number): void;
40
+ stopMonitor(): void;
41
+ monitorReadyState(intervalMilliseconds?: number): void;
42
+ startReadyStateMonitor(): void;
43
+ stopReadyStateMonitor(): void;
44
+ checkReadyState(readyState: number | null | undefined, triggeredEvent?: string): void;
45
+ getPlugin(): unknown;
46
+ getLog(): unknown;
47
+ isStarted(): boolean;
48
+ getAdapterClass(className: string): unknown;
49
+ getAdapterName(adapterObject?: unknown): string;
50
+ getAdapterNameFromClass(adapterClass?: unknown): string;
51
+ getAdapterClasses(): Record<string, unknown>;
52
+ getPlayhead(): number | null;
53
+ getDuration(): number | null;
54
+ getBitrate(): number | null;
55
+ getTotalBytes(): number | null;
56
+ getTitle(): string | null;
57
+ getResource(): string | null;
58
+ getPlayerVersion(): string | null;
59
+ getPlayerName(): string | null;
60
+ getVersion(): string;
61
+ getVideoObject(): unknown | null;
62
+ getLastUsedCdn(): string | undefined;
63
+ checkExistsPlayer(): boolean;
64
+ checkExistsObjectOnPage(object: unknown): boolean;
65
+ fireInit(params?: Record<string, unknown>, triggeredEvent?: string): void;
66
+ fireStart(params?: Record<string, unknown>, triggeredEvent?: string): void;
67
+ fireJoin(params?: Record<string, unknown>, triggeredEvent?: string): void;
68
+ firePause(params?: Record<string, unknown>, triggeredEvent?: string): void;
69
+ fireResume(params?: Record<string, unknown>, triggeredEvent?: string): void;
70
+ fireBufferBegin(params?: Record<string, unknown>, convertFromSeek?: boolean, triggeredEvent?: string, triggeredByStateProperty?: boolean): void;
71
+ fireBufferEnd(params?: Record<string, unknown>, triggeredEvent?: string): void;
72
+ cancelBuffer(params?: Record<string, unknown>): void;
73
+ fireStop(params?: Record<string, unknown>, triggeredEvent?: string): void;
74
+ firePlayerLog(playerEvent: string, playerData: unknown): void;
75
+ setIsAds(value: boolean): void;
76
+ fireCasted(params?: Record<string, unknown>, triggeredEvent?: string): void;
77
+ fireError(code?: string | number | Record<string, unknown>, msg?: string, metadata?: Record<string, unknown>, level?: string, triggeredEvent?: string, fatalError?: boolean, duration?: number): void;
78
+ fireFatalError(code?: string | number | Record<string, unknown>, msg?: string, metadata?: Record<string, unknown>, level?: string, triggeredEvent?: string, duration?: number): void;
79
+ isLegacyBufferBehaviourEnabled(): boolean;
80
+ }
81
+ interface AdapterContent extends Adapter {
82
+ getPlayrate(): number;
83
+ getFramesPerSecond(): number | undefined;
84
+ getDroppedFrames(): number | undefined;
85
+ getThroughput(): number | undefined;
86
+ getRendition(): unknown | undefined;
87
+ getTitle2(): string | undefined;
88
+ getIsLive(): boolean | undefined;
89
+ getCdnTraffic(): number | undefined;
90
+ getP2PTraffic(): number | undefined;
91
+ getUploadTraffic(): number | undefined;
92
+ getIsP2PEnabled(): boolean | undefined;
93
+ getSegmentDuration(): number | undefined;
94
+ getHouseholdId(): string | undefined;
95
+ getLatency(): number | undefined;
96
+ getPacketLoss(): number | undefined;
97
+ getPacketSent(): number | undefined;
98
+ getMetrics(): Record<string, unknown> | undefined;
99
+ getAudioCodec(): string | undefined;
100
+ getVideoCodec(): string | undefined;
101
+ setUrlToParse(url: string): void;
102
+ getURLToParse(): string | undefined;
103
+ fireSeekBegin(params?: Record<string, unknown>, convertFromBuffer?: boolean, triggeredEvent?: string): void;
104
+ fireSeekEnd(params?: Record<string, unknown>, triggeredEvent?: string): void;
105
+ cancelSeek(params?: Record<string, unknown>): void;
106
+ fireEvent(eventName: string, dimensions?: Record<string, unknown>, values?: Record<string, unknown>, topLevelDimensions?: Record<string, unknown>, hasEndDatetime?: boolean): void;
107
+ fireEventEnd(eventName: string): void;
108
+ storeNewRendition(rendition: unknown): void;
109
+ }
110
+ type AdPosition = string | number | null;
111
+ interface AdBreaksCount {
112
+ pre?: number;
113
+ mid?: number;
114
+ post?: number;
115
+ }
116
+ /**
117
+ * Structure of ads requested. This is intentionally generic because the source
118
+ * only states "structure of ads requested" without a concrete schema.
119
+ */
120
+ type AdPattern = unknown;
121
+ type AdInsertionType = string | null;
122
+ interface AdapterAd extends AdapterContent {
123
+ /** Current ad position */
124
+ getPosition(): AdPosition;
125
+ /** Given ad structure (number of pre/mid/post breaks) */
126
+ getGivenBreaks(): AdBreaksCount | null;
127
+ /** Expected ad structure (number of pre/mid/post breaks) */
128
+ getExpectedBreaks(): AdBreaksCount | null;
129
+ /** Structure of ads requested */
130
+ getExpectedPattern(): AdPattern | null;
131
+ /** Playheads (in seconds or ms, depending on implementation) of ad break start times */
132
+ getBreaksTime(): number[] | null;
133
+ /** Number of ads given for the current break */
134
+ getGivenAds(): number | null;
135
+ /** Number of ads requested for the current break */
136
+ getExpectedAds(): number | null;
137
+ /**
138
+ * Whether the ad is visible on screen (standard: >50% pixels visible)
139
+ * Defaults to true in the base mixin.
140
+ */
141
+ getIsVisible(): boolean;
142
+ /** Whether audio is enabled when the ad begins */
143
+ getAudioEnabled(): boolean | null;
144
+ /** Whether the ad is skippable */
145
+ getIsSkippable(): boolean | null;
146
+ /** Whether the player is fullscreen when the ad begins */
147
+ getIsFullscreen(): boolean | null;
148
+ /** Ad campaign identifier/name */
149
+ getCampaign(): string | null;
150
+ /** Ad creative ID */
151
+ getCreativeId(): string | null;
152
+ /** Ad provider name */
153
+ getProvider(): string | null;
154
+ /** Ad insertion type (client-side/server-side) */
155
+ getAdInsertionType(): AdInsertionType;
156
+ /**
157
+ * Fire a click event.
158
+ * If a string is passed, it is treated as the URL: params = { url: string }.
159
+ */
160
+ fireClick(params?: Record<string, unknown> | string): void;
161
+ /**
162
+ * Fire a quartile event (0..3). Increments `lastQuartileSent` internally.
163
+ */
164
+ fireQuartile(quartile: number): void;
165
+ /** Start visibility/view tracking chrono for ads */
166
+ startChronoView(): void;
167
+ /** Stop visibility/view tracking chrono for ads */
168
+ stopChronoView(): void;
169
+ /**
170
+ * Fire a manifest-related event. If first arg is string, it is treated as errorType
171
+ * and `message` is used as errorMessage.
172
+ */
173
+ fireManifest(params?: Record<string, unknown> | string, message?: string): void;
174
+ /**
175
+ * Mark ad as skipped and fire stop with params.skipped = true
176
+ */
177
+ fireSkip(params?: Record<string, unknown>): void;
178
+ /** Alias to fireAdBreakStart */
179
+ fireBreakStart(params?: Record<string, unknown>): void;
180
+ /** Alias to fireAdBreakStop */
181
+ fireBreakStop(params?: Record<string, unknown>): void;
182
+ /** Fire Ad Break (Pod) start */
183
+ fireAdBreakStart(params?: Record<string, unknown>): void;
184
+ /** Fire Ad Break (Pod) stop */
185
+ fireAdBreakStop(params?: Record<string, unknown>): void;
186
+ }
187
+ interface PlayheadMonitor {
188
+ stop(): void;
189
+ skipNextTick(): void;
190
+ progress(): void;
191
+ }
192
+ interface AdapterFlags {
193
+ initCalled: boolean;
194
+ isStarted: boolean;
195
+ isStopped: boolean;
196
+ isJoined: boolean;
197
+ isBuffering: boolean;
198
+ isSeeking: boolean;
199
+ isPaused: boolean;
200
+ isAdPaused: boolean;
201
+ isEnded: boolean;
202
+ isVideoStateBuffering: boolean;
203
+ lastQuartileSent: number;
204
+ }
205
+
206
+ declare module './npaw-turbo-player-ad-adapter' {
207
+ interface NpawTurboPlayerAdAdapter extends AdapterAd {
208
+ player: IntegrationElement;
209
+ }
210
+ }
211
+ type AdapterEventListeners$1 = {
212
+ [K in keyof IntegrationElementEventMap]?: (event: IntegrationElementEventMap[K]) => void;
213
+ };
214
+ declare class NpawTurboPlayerAdAdapter {
215
+ _refs?: AdapterEventListeners$1;
216
+ getVersion(): string;
217
+ getPlayerVersion(): string;
218
+ getPlayhead(): number;
219
+ getTitle(): string;
220
+ getTitle2(): string | undefined;
221
+ getCreativeId(): string | null;
222
+ getProvider(): string | null;
223
+ getAdInsertionType(): string;
224
+ getDuration(): number | null;
225
+ getBreaksTime(): null;
226
+ getResource(): string;
227
+ getGivenAds(): number | null;
228
+ getAudioEnabled(): boolean;
229
+ getIsSkippable(): boolean;
230
+ getIsFullscreen(): boolean;
231
+ getIsVisible(): boolean;
232
+ getPosition(): string | null;
233
+ registerListeners(): void;
234
+ unregisterListeners(): void;
235
+ _isSupportedAd(): boolean | undefined;
236
+ impressionListener(): void;
237
+ pausedListener(): void;
238
+ resumedListener(): void;
239
+ bufferingStartListener(): void;
240
+ bufferingEndListener(): void;
241
+ completeListener(): void;
242
+ clickListener(): void;
243
+ skippedListener(): void;
244
+ errorListener(event: IntegrationElementEventMap['aderror']): void;
245
+ }
246
+
247
+ declare module './npaw-turbo-player-adapter' {
248
+ interface NpawTurboPlayerAdapter extends AdapterContent {
249
+ player: IntegrationElement;
250
+ }
251
+ }
252
+ type AdapterEventListeners = {
253
+ [K in keyof IntegrationElementEventMap]?: (event: IntegrationElementEventMap[K]) => void;
254
+ };
255
+ declare class NpawTurboPlayerAdapter {
256
+ _refs?: AdapterEventListeners;
257
+ adsAdapters: {
258
+ npawTurboPlayerAdAdapter: typeof NpawTurboPlayerAdAdapter;
259
+ };
260
+ getPlayerName(): string;
261
+ getVersion(): string;
262
+ getPlayerVersion(): string;
263
+ getResource(): string | null;
264
+ getTitle(): string | null;
265
+ getDuration(): number;
266
+ getPlayhead(): number;
267
+ getPlayrate(): number;
268
+ getIsLive(): boolean;
269
+ getBitrate(): number | null;
270
+ getLatency(): number | undefined;
271
+ getRendition(): string;
272
+ getThroughput(): number | undefined;
273
+ getDroppedFrames(): number | undefined;
274
+ getTotalBytes(): number | null;
275
+ registerListeners(): void;
276
+ unregisterListeners(): void;
277
+ contentStart(): void;
278
+ contentImpression(): void;
279
+ playListener(): void;
280
+ pauseListener(): void;
281
+ seekingListener(): void;
282
+ seekedListener(): void;
283
+ contentBufferStart(): void;
284
+ contentBufferEnd(): void;
285
+ contentStop(): void;
286
+ contentSelect(): void;
287
+ contentError(event: IntegrationElementEventMap['contenterror']): void;
288
+ }
289
+
290
+ interface NpawIntegrationOptions {
291
+ /**
292
+ * Application name for analytics, defaults to `integration.extraContext.appName`
293
+ * @example 'my-app'
294
+ */
295
+ appName?: string;
296
+ /**
297
+ * Application release version, defaults to `integration.extraContext.appVersion`
298
+ * @example '1.0.0'
299
+ */
300
+ appVersion?: string;
301
+ }
302
+ /**
303
+ * Connects NPAW analytics integration to a turbo player integration
304
+ *
305
+ * @param integration - The integration element
306
+ * @param accountCode - NPAW account code
307
+ * @param options - NPAW configuration options
308
+ * @returns The NPAW plugin instance and a destroy function
309
+ */
310
+ declare function connectToNpaw(integration: IntegrationElement, accountCode: string, options?: NpawIntegrationOptions): {
311
+ npawPlugin: NpawPlugin;
312
+ destroy(): void;
313
+ };
314
+
315
+ export { type NpawIntegrationOptions, NpawTurboPlayerAdapter, connectToNpaw };
@@ -0,0 +1,317 @@
1
+ import { PlaybackMode, IntegrationEvent, Mimetype, EXTERNAL_PLAYER_NAME } from '@glomex/integration-web-component';
2
+ import NpawPlugin from 'npaw-plugin';
3
+
4
+ // src/npaw/index.ts
5
+
6
+ // package.json
7
+ var package_default = {
8
+ version: "1.1480.0"};
9
+
10
+ // src/npaw/package-info.ts
11
+ var { version } = package_default;
12
+
13
+ // src/npaw/npaw-turbo-player-ad-adapter.ts
14
+ var NpawTurboPlayerAdAdapter = class {
15
+ _refs;
16
+ getVersion() {
17
+ return `turbo-ad-v${version}`;
18
+ }
19
+ getPlayerVersion() {
20
+ return this.player.version;
21
+ }
22
+ getPlayhead() {
23
+ return this.player.adCurrentTime;
24
+ }
25
+ getTitle() {
26
+ return this.player.currentAd?.title || "";
27
+ }
28
+ getTitle2() {
29
+ return this.player.currentAd?.advertiserName || void 0;
30
+ }
31
+ getCreativeId() {
32
+ return this.player.currentAd?.creativeId || null;
33
+ }
34
+ getProvider() {
35
+ return this.player.currentAd?.adSystem || null;
36
+ }
37
+ getAdInsertionType() {
38
+ return "client-side";
39
+ }
40
+ getDuration() {
41
+ return this.player.currentAd?.duration || this.player.adDuration || null;
42
+ }
43
+ getBreaksTime() {
44
+ return null;
45
+ }
46
+ getResource() {
47
+ return this.player.currentAd?.adUrl || "unknown";
48
+ }
49
+ getGivenAds() {
50
+ return this.player.currentAd?.totalAds || null;
51
+ }
52
+ getAudioEnabled() {
53
+ return Boolean(!this.player.adMuted);
54
+ }
55
+ getIsSkippable() {
56
+ return this.player.currentAd?.skippable || false;
57
+ }
58
+ getIsFullscreen() {
59
+ return this.player.presentationMode === "fullscreen";
60
+ }
61
+ getIsVisible() {
62
+ return this.getNpawUtils().calculateAdViewability(this.player);
63
+ }
64
+ getPosition() {
65
+ if (this.player.currentAd?.breakName === "preroll") {
66
+ return this.getNpawReference().Constants.AdPosition.Preroll;
67
+ }
68
+ if (this.player.currentAd?.breakName === "midroll") {
69
+ return this.getNpawReference().Constants.AdPosition.Midroll;
70
+ }
71
+ if (this.player.currentAd?.breakName === "postroll") {
72
+ return this.getNpawReference().Constants.AdPosition.Postroll;
73
+ }
74
+ return null;
75
+ }
76
+ registerListeners() {
77
+ this._refs = {
78
+ [IntegrationEvent.AD_IMPRESSION]: this.impressionListener.bind(this),
79
+ [IntegrationEvent.AD_RESUMED]: this.resumedListener.bind(this),
80
+ [IntegrationEvent.AD_PAUSED]: this.pausedListener.bind(this),
81
+ [IntegrationEvent.AD_BUFFERING_START]: this.bufferingStartListener.bind(this),
82
+ [IntegrationEvent.AD_BUFFERING_END]: this.bufferingEndListener.bind(this),
83
+ [IntegrationEvent.AD_CLICK]: this.clickListener.bind(this),
84
+ [IntegrationEvent.AD_SKIPPED]: this.skippedListener.bind(this),
85
+ [IntegrationEvent.AD_COMPLETE]: this.completeListener.bind(this),
86
+ [IntegrationEvent.AD_ERROR]: this.errorListener.bind(this)
87
+ };
88
+ for (const type of Object.keys(this._refs)) {
89
+ const handler = this._refs?.[type];
90
+ this.player.addEventListener(
91
+ type,
92
+ handler
93
+ );
94
+ }
95
+ }
96
+ unregisterListeners() {
97
+ for (const type of Object.keys(this._refs || {})) {
98
+ const handler = this._refs?.[type];
99
+ this.player.removeEventListener(
100
+ type,
101
+ handler
102
+ );
103
+ }
104
+ this._refs = void 0;
105
+ }
106
+ _isSupportedAd() {
107
+ return this.player.currentAd?.isLinear;
108
+ }
109
+ impressionListener() {
110
+ if (!this._isSupportedAd()) return;
111
+ this.fireStart({}, "impressionListener");
112
+ this.fireJoin({}, "impressionListener");
113
+ }
114
+ pausedListener() {
115
+ if (!this._isSupportedAd()) return;
116
+ this.firePause({}, IntegrationEvent.AD_PAUSED);
117
+ }
118
+ resumedListener() {
119
+ if (!this._isSupportedAd()) return;
120
+ this.fireResume({}, IntegrationEvent.AD_RESUMED);
121
+ }
122
+ bufferingStartListener() {
123
+ if (!this._isSupportedAd()) return;
124
+ this.fireBufferBegin({}, true, IntegrationEvent.AD_BUFFERING_START);
125
+ }
126
+ bufferingEndListener() {
127
+ if (!this._isSupportedAd()) return;
128
+ this.fireBufferEnd({}, IntegrationEvent.AD_BUFFERING_END);
129
+ }
130
+ completeListener() {
131
+ if (!this._isSupportedAd()) return;
132
+ this.fireStop({}, IntegrationEvent.AD_COMPLETE);
133
+ }
134
+ clickListener() {
135
+ if (!this._isSupportedAd()) return;
136
+ this.fireClick(this.player.currentAd?.clickThroughUrl || "");
137
+ }
138
+ skippedListener() {
139
+ if (!this._isSupportedAd()) return;
140
+ this.fireSkip();
141
+ }
142
+ errorListener(event) {
143
+ if (!this._isSupportedAd()) return;
144
+ this.fireError(event.detail.error.code, event.detail.error.message);
145
+ }
146
+ };
147
+
148
+ // src/npaw/npaw-turbo-player-adapter.ts
149
+ var NpawTurboPlayerAdapter = class {
150
+ _refs;
151
+ adsAdapters = {
152
+ npawTurboPlayerAdAdapter: NpawTurboPlayerAdAdapter
153
+ };
154
+ getPlayerName() {
155
+ return "turbo-player";
156
+ }
157
+ getVersion() {
158
+ return `turbo-v${version}`;
159
+ }
160
+ getPlayerVersion() {
161
+ return this.player.version;
162
+ }
163
+ getResource() {
164
+ return this.player.source?.src || null;
165
+ }
166
+ getTitle() {
167
+ return this.player.content?.title || null;
168
+ }
169
+ getDuration() {
170
+ return this.player.duration;
171
+ }
172
+ getPlayhead() {
173
+ return this.getIsLive() ? this.player.wallClockTime : this.player.currentTime;
174
+ }
175
+ getPlayrate() {
176
+ return 1;
177
+ }
178
+ getIsLive() {
179
+ return this.player.content?.sources[0]?.playbackMode === PlaybackMode.LIVE;
180
+ }
181
+ getBitrate() {
182
+ return this.player.getVideoPlaybackQuality()?.bitrate || null;
183
+ }
184
+ getLatency() {
185
+ return this.player.getVideoPlaybackQuality()?.liveLatency;
186
+ }
187
+ getRendition() {
188
+ const { width, height, bandwidth } = this.player.getVideoPlaybackQuality() || {};
189
+ if (width && height && bandwidth) {
190
+ return this.getNpawUtils().buildRenditionString(width, height, bandwidth);
191
+ }
192
+ return "unknown";
193
+ }
194
+ getThroughput() {
195
+ return this.player.getVideoPlaybackQuality()?.throughput;
196
+ }
197
+ getDroppedFrames() {
198
+ return this.player.getVideoPlaybackQuality()?.droppedVideoFrames;
199
+ }
200
+ getTotalBytes() {
201
+ return this.player.getVideoPlaybackQuality()?.bytes || null;
202
+ }
203
+ registerListeners() {
204
+ this._refs = {
205
+ [IntegrationEvent.CONTENT_PLAY]: this.playListener.bind(this),
206
+ [IntegrationEvent.CONTENT_PAUSE]: this.pauseListener.bind(this),
207
+ [IntegrationEvent.CONTENT_SEEKING]: this.seekingListener.bind(this),
208
+ [IntegrationEvent.CONTENT_SEEKED]: this.seekedListener.bind(this),
209
+ [IntegrationEvent.CONTENT_BUFFERING_START]: this.contentBufferStart.bind(this),
210
+ [IntegrationEvent.CONTENT_BUFFERING_END]: this.contentBufferEnd.bind(this),
211
+ [IntegrationEvent.CONTENT_START]: this.contentStart.bind(this),
212
+ [IntegrationEvent.CONTENT_IMPRESSION]: this.contentImpression.bind(this),
213
+ [IntegrationEvent.CONTENT_STOP]: this.contentStop.bind(this),
214
+ [IntegrationEvent.CONTENT_SELECT]: this.contentSelect.bind(this),
215
+ [IntegrationEvent.CONTENT_ERROR]: this.contentError.bind(this)
216
+ };
217
+ for (const type of Object.keys(this._refs)) {
218
+ const handler = this._refs?.[type];
219
+ this.player.addEventListener(
220
+ type,
221
+ handler
222
+ );
223
+ }
224
+ this.plugin.setAdsAdapter(
225
+ this.getAdapterClass("npawTurboPlayerAdAdapter"),
226
+ this.getVideo().getVideoKey()
227
+ );
228
+ }
229
+ unregisterListeners() {
230
+ for (const type of Object.keys(this._refs || {})) {
231
+ const handler = this._refs?.[type];
232
+ this.player.removeEventListener(
233
+ type,
234
+ handler
235
+ );
236
+ }
237
+ this._refs = void 0;
238
+ this.plugin.removeAdsAdapter(this.getVideo().getVideoKey());
239
+ }
240
+ contentStart() {
241
+ const { options } = this.getVideo();
242
+ const streamingProtocol = this.player.source?.mimetype === Mimetype.DASH ? "DASH" : this.player.source?.mimetype === Mimetype.HLS ? "HLS" : void 0;
243
+ options["content.id"] = this.player.source?.id || this.player.content?.id;
244
+ options["content.streamingProtocol"] = streamingProtocol;
245
+ options["content.playbackType"] = this.player.source?.playbackMode;
246
+ options["content.tvShow"] = this.player.content?.show?.name;
247
+ options["content.season"] = this.player.content?.show?.seasonNumber;
248
+ options["content.language"] = this.player.content?.language;
249
+ this.fireStart({}, IntegrationEvent.CONTENT_START);
250
+ }
251
+ contentImpression() {
252
+ this.fireJoin({}, IntegrationEvent.CONTENT_IMPRESSION);
253
+ }
254
+ playListener() {
255
+ this.fireResume({}, IntegrationEvent.CONTENT_PLAY);
256
+ this.plugin.getAdsAdapter().fireAdBreakStop({});
257
+ }
258
+ pauseListener() {
259
+ this.firePause({}, "pauseListener");
260
+ }
261
+ seekingListener() {
262
+ this.fireSeekBegin({}, true, IntegrationEvent.CONTENT_SEEKING);
263
+ }
264
+ seekedListener() {
265
+ this.fireSeekEnd({}, IntegrationEvent.CONTENT_SEEKED);
266
+ }
267
+ contentBufferStart() {
268
+ this.fireBufferBegin({}, true, IntegrationEvent.CONTENT_BUFFERING_START);
269
+ }
270
+ contentBufferEnd() {
271
+ this.fireBufferEnd({}, IntegrationEvent.CONTENT_BUFFERING_END);
272
+ }
273
+ contentStop() {
274
+ this.fireStop({}, IntegrationEvent.CONTENT_STOP);
275
+ }
276
+ contentSelect() {
277
+ this.fireStop({}, IntegrationEvent.CONTENT_SELECT);
278
+ }
279
+ contentError(event) {
280
+ this.fireFatalError(
281
+ event.detail.error.code,
282
+ event.detail.error.message,
283
+ void 0,
284
+ "fatal",
285
+ IntegrationEvent.CONTENT_ERROR
286
+ );
287
+ }
288
+ };
289
+
290
+ // src/npaw/index.ts
291
+ function connectToNpaw(integration, accountCode, options) {
292
+ const { appName = EXTERNAL_PLAYER_NAME, appVersion } = options || {};
293
+ const npawPlugin = new NpawPlugin(accountCode);
294
+ npawPlugin.setAnalyticsOptions({
295
+ "app.name": appName || integration.extraContext?.appName,
296
+ "app.releaseVersion": appVersion || integration.extraContext?.appVersion
297
+ });
298
+ const onUserUpdateConsent = () => {
299
+ const hasPurpose1Consent = Boolean(integration.consent?.purposeConsents?.["1"]);
300
+ npawPlugin.setAnalyticsOptions({
301
+ "user.obfuscateIp": !hasPurpose1Consent,
302
+ disableStorage: !hasPurpose1Consent,
303
+ ...hasPurpose1Consent ? {} : { userId: void 0 }
304
+ });
305
+ };
306
+ npawPlugin.registerAdapterFromClass(integration, NpawTurboPlayerAdapter);
307
+ integration.addEventListener(IntegrationEvent.USER_UPDATE_CONSENT, onUserUpdateConsent);
308
+ return {
309
+ npawPlugin,
310
+ destroy() {
311
+ integration.removeEventListener(IntegrationEvent.USER_UPDATE_CONSENT, onUserUpdateConsent);
312
+ npawPlugin?.destroy();
313
+ }
314
+ };
315
+ }
316
+
317
+ export { NpawTurboPlayerAdapter, connectToNpaw };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@glomex/integration-analytics",
3
+ "version": "1.1480.0",
4
+ "description": "Analytics integrations for the turbo player",
5
+ "documentation": "https://docs.glomex.com",
6
+ "homepage": "https://glomex.com",
7
+ "keywords": [
8
+ "glomex",
9
+ "video",
10
+ "player",
11
+ "streaming",
12
+ "media-player",
13
+ "web-player",
14
+ "analytics",
15
+ "npaw",
16
+ "youbora",
17
+ "nielsen",
18
+ "comscore",
19
+ "datazoom",
20
+ "sensic"
21
+ ],
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "exports": {
25
+ "./npaw": {
26
+ "types": "./dist/npaw/index.d.ts",
27
+ "import": "./dist/npaw/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "LICENSE.md",
32
+ "dist/**/*.js",
33
+ "dist/**/*.d.ts"
34
+ ],
35
+ "scripts": {
36
+ "prepack": "npm run build",
37
+ "build": "rm -rf dist && npm run build:ts --force && npm run build:tsup",
38
+ "build:ts": "tsc --build",
39
+ "build:tsup": "tsup",
40
+ "lint": "tsc --noEmit && biome ci",
41
+ "watch": "npm run build:ts --force && tsup --watch"
42
+ },
43
+ "dependencies": {
44
+ "@glomex/integration-web-component": "workspace:*",
45
+ "npaw-plugin": "^7.3.18"
46
+ },
47
+ "devDependencies": {
48
+ "@biomejs/biome": "catalog:",
49
+ "tsup": "catalog:",
50
+ "typescript": "catalog:"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "license": "MIT"
56
+ }