@24i/bigscreen-sdk 1.0.23-alpha.2405 → 1.0.23-alpha.2409

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.
Files changed (26) hide show
  1. package/package.json +3 -2
  2. package/packages/analytics/src/clients/GoogleAnalytics/generateSessionId.ts +2 -2
  3. package/packages/analytics/src/clients/TwentyFourIQ/TwentyFourIQClient.ts +116 -0
  4. package/packages/analytics/src/clients/TwentyFourIQ/constants.ts +99 -0
  5. package/packages/analytics/src/clients/TwentyFourIQ/generateSessionId.ts +8 -0
  6. package/packages/analytics/src/clients/TwentyFourIQ/helper.ts +34 -0
  7. package/packages/analytics/src/clients/TwentyFourIQ/index.ts +2 -0
  8. package/packages/analytics/src/clients/TwentyFourIQ/interface.ts +31 -0
  9. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapAdLoaded.ts +13 -0
  10. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapAdSkipped.ts +16 -0
  11. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapBase.ts +21 -0
  12. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapBuffering.ts +15 -0
  13. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapPlayerClose.ts +24 -0
  14. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapPlayerOpen.ts +18 -0
  15. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapSceneView.ts +15 -0
  16. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapScroll.ts +17 -0
  17. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoComplete.ts +21 -0
  18. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoPause.ts +24 -0
  19. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoProgress.ts +24 -0
  20. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoStart.ts +34 -0
  21. package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoStop.ts +32 -0
  22. package/packages/analytics/src/clients/TwentyFourIQ/types.ts +115 -0
  23. package/packages/analytics/src/constants.ts +1 -1
  24. package/packages/utils/src/index.ts +1 -0
  25. package/packages/utils/src/keyPress/index.ts +5 -1
  26. package/packages/utils/src/keyPress/keyPressSimulator.ts +30 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@24i/bigscreen-sdk",
3
- "version": "1.0.23-alpha.2405",
3
+ "version": "1.0.23-alpha.2409",
4
4
  "description": "SmartApps BIGscreen SDK monorepo",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://github.com/24i/smartapps-bigscreen-sdk#readme",
39
39
  "dependencies": {
40
- "@24i/appstage-shared-analytics": "1.0.16-alpha.58",
40
+ "@24i/appstage-shared-analytics": "1.0.17-alpha.60",
41
41
  "@24i/appstage-shared-events-manager": "1.0.11",
42
42
  "@24i/appstage-shared-perf-utils": "1.0.11",
43
43
  "@24i/bigscreen-players-engine-base": "1.0.2",
@@ -90,6 +90,7 @@
90
90
  "./analytics/interface": "./packages/analytics/src/interface.ts",
91
91
  "./analytics/ConsoleAnalytics": "./packages/analytics/src/clients/ConsoleAnalytics/index.ts",
92
92
  "./analytics/GoogleAnalytics": "./packages/analytics/src/clients/GoogleAnalytics/index.ts",
93
+ "./analytics/TwentyFourIQ": "./packages/analytics/src/clients/TwentyFourIQ/index.ts",
93
94
  "./analytics": "./packages/analytics/src/index.ts",
94
95
  "./animations/mock": "./packages/animations/src/__mocks__/JSAnimations.ts",
95
96
  "./animations": "./packages/animations/src/index.ts",
@@ -1,8 +1,8 @@
1
- /* eslint-disable no-magic-numbers */
1
+ const RANDOM_SEED = 2147483647;
2
2
  /**
3
3
  * Recommended way to generate session id by Google.
4
4
  * Blackbox
5
5
  */
6
6
  export const generateSessionId = () => (
7
- Math.floor(Math.random() * (2147483647 - 0 + 1) + 0)
7
+ Math.floor(Math.random() * (RANDOM_SEED - 0 + 1) + 0)
8
8
  );
@@ -0,0 +1,116 @@
1
+ import { Storage } from '@24i/bigscreen-sdk/storage';
2
+ import { device } from '@24i/bigscreen-sdk/device';
3
+ import { MINUTE_IN_MS } from '@24i/bigscreen-sdk/utils/timeConstants';
4
+ import { createTimeout } from '@24i/bigscreen-sdk/utils/timers';
5
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
6
+ import {
7
+ TRIGGER_NAME_TO_24IQ_EVENTS,
8
+ } from './constants';
9
+ import { EVENTS_MAPPING } from './interface';
10
+ import type { AnalyticsClient, AnyPayload } from '../../interface';
11
+ import { generateSessionId } from './generateSessionId';
12
+ import { CorePayload, DeviceInfo, EventBody, Payload, SessionInfo } from './types';
13
+
14
+ // eslint-disable-next-line no-magic-numbers
15
+ const SESSION_TIMEOUT = 30 * MINUTE_IN_MS;
16
+
17
+ const TWENYFOURIQ_SESSION_COUNTER = '24iQ_session_counter';
18
+
19
+ export class TwentyFourIQClient implements AnalyticsClient {
20
+ name = '24iQ';
21
+
22
+ deviceInfo = {
23
+ manufacturer: '',
24
+ platform: '',
25
+ platformVersion: '',
26
+ deviceId: '',
27
+ appVersion: '',
28
+ applicationId: '',
29
+ deviceType: '',
30
+ };
31
+
32
+ constantPayload: CorePayload & SessionInfo & DeviceInfo = {
33
+ sessionNumber: 0,
34
+ sessionId: 0,
35
+ ...this.deviceInfo,
36
+ };
37
+
38
+ sessionTimeout = createTimeout();
39
+
40
+ isSessionActive = false;
41
+
42
+ sessionStartSent = false;
43
+
44
+ constructor(private baseURL: string, private appVersion: string = '') {
45
+ this.init();
46
+ }
47
+
48
+ async init() {
49
+ this.deviceInfo.manufacturer = await device.getManufacturerName();
50
+ this.deviceInfo.platform = await device.getPlatformName();
51
+ this.deviceInfo.platformVersion = await device.getPlatformVersion();
52
+ this.deviceInfo.deviceId = await device.getUuid();
53
+ await this.startSession();
54
+ }
55
+
56
+ async startSession() {
57
+ const sessionNumber = parseInt(
58
+ await Storage.getItem(TWENYFOURIQ_SESSION_COUNTER) ?? '0', 10,
59
+ ) + 1;
60
+ this.constantPayload.sessionNumber = sessionNumber;
61
+ this.constantPayload.sessionId = generateSessionId();
62
+ this.constantPayload.manufacturer = this.deviceInfo.manufacturer;
63
+ this.constantPayload.platform = this.deviceInfo.platform;
64
+ this.constantPayload.platformVersion = this.deviceInfo.platformVersion;
65
+ this.constantPayload.appVersion = this.appVersion;
66
+ await Storage.setItem(TWENYFOURIQ_SESSION_COUNTER, sessionNumber.toString());
67
+ this.isSessionActive = true;
68
+ this.setSessionTimeout();
69
+ }
70
+
71
+ setSessionTimeout() {
72
+ this.sessionTimeout.set(() => {
73
+ this.isSessionActive = false;
74
+ this.sessionStartSent = false;
75
+ }, SESSION_TIMEOUT);
76
+ }
77
+
78
+ async sendEvent(eventBody: EventBody) {
79
+ try {
80
+ await fetch(this.baseURL, {
81
+ method: 'POST',
82
+ body: JSON.stringify(eventBody),
83
+ headers: {
84
+ Accept: 'application/json',
85
+ 'Content-Type': 'application/json;charset=UTF-8',
86
+ },
87
+ });
88
+ } catch (error) {
89
+ console.warn(`[${this.name}] Error sendEvent: `, error);
90
+ }
91
+ }
92
+
93
+ async onEvent(triggerName: AnalyticsTriggers, payload: AnyPayload): Promise<void> {
94
+ const events = TRIGGER_NAME_TO_24IQ_EVENTS[triggerName];
95
+ if (this.isSessionActive) {
96
+ this.setSessionTimeout();
97
+ } else {
98
+ await this.startSession();
99
+ }
100
+ if (!events) return;
101
+ await Promise.all(
102
+ events.map(async (event) => {
103
+ const mappingFunction = EVENTS_MAPPING[event];
104
+ try {
105
+ const eventBody = mappingFunction?.(triggerName, {
106
+ ...this.constantPayload,
107
+ ...payload,
108
+ } as unknown as Payload);
109
+ if (eventBody) await this.sendEvent(eventBody);
110
+ } catch (e) {
111
+ console.warn(`[${this.name}] Error onEvent: `, e);
112
+ }
113
+ }),
114
+ );
115
+ }
116
+ }
@@ -0,0 +1,99 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+
3
+ export enum AnalyticsPrefix {
4
+ SCROLL = 'SCROLL_',
5
+ PLAYBACK = 'PLAYBACK_',
6
+ }
7
+
8
+ export enum AnalyticsEvents {
9
+ INSTALLED_APP = 'Installed app',
10
+ LOADED_APP = 'Loaded App',
11
+ LOGGED_IN = 'Logged In',
12
+ LOGGED_OUT = 'Logged Out',
13
+ CANCELLED_PURCHASE = 'Cancelled Purchase',
14
+ PURCHASE_COMPLETE = 'Purchase Complete',
15
+ HOME = 'home',
16
+ DETAILS = 'details',
17
+ PLAYER = 'player',
18
+ TECHNICAL_INFO = 'Technical information',
19
+ }
20
+
21
+ export enum DefaultScreens {
22
+ PLAYBACK = 'playback',
23
+ }
24
+
25
+ export const TWENTY_FOUR_IQ_TRIGGERS = [
26
+ // App
27
+ AnalyticsTriggers.APP_CLOSE,
28
+
29
+ // Scenes
30
+ AnalyticsTriggers.SCENE_VIEW,
31
+
32
+ // Data loading / Player buffering
33
+ AnalyticsTriggers.BUFFERING_START,
34
+ AnalyticsTriggers.BUFFERING_STOP,
35
+
36
+ // Playback
37
+ AnalyticsTriggers.PLAYBACK_10,
38
+ AnalyticsTriggers.PLAYBACK_25,
39
+ AnalyticsTriggers.PLAYBACK_50,
40
+ AnalyticsTriggers.PLAYBACK_75,
41
+ AnalyticsTriggers.PLAYBACK_90,
42
+ AnalyticsTriggers.PLAYBACK_PAUSE,
43
+ AnalyticsTriggers.PLAYBACK_START,
44
+ AnalyticsTriggers.PLAYBACK_STOP,
45
+
46
+ // Player
47
+ AnalyticsTriggers.PLAYER_CLOSE,
48
+ AnalyticsTriggers.PLAYER_OPEN,
49
+
50
+ // Scrolling in scene
51
+ AnalyticsTriggers.SCROLL_25,
52
+ AnalyticsTriggers.SCROLL_50,
53
+ AnalyticsTriggers.SCROLL_75,
54
+ AnalyticsTriggers.SCROLL_90,
55
+
56
+ // Ads
57
+ AnalyticsTriggers.AD_LOADED,
58
+ AnalyticsTriggers.AD_SKIPPED,
59
+ ];
60
+
61
+ export enum EVENTS {
62
+ SCENE_VIEW = 'scene_view',
63
+ BUFFERING = 'buffering',
64
+ VIDEO_PROGRESS = 'video_progress',
65
+ VIDEO_START = 'video_start',
66
+ VIDEO_COMPLETE = 'video_complete',
67
+ VIDEO_STOP = 'video_stop',
68
+ VIDEO_PAUSE = 'video_pause',
69
+ PLAYER_CLOSE = 'player_close',
70
+ PLAYER_OPEN = 'player_open',
71
+ SCROLL = 'scroll',
72
+ AD_LOADED = 'ad_loaded',
73
+ AD_SKIPPED = 'ad_skipped',
74
+ }
75
+
76
+ export const TRIGGER_NAME_TO_24IQ_EVENTS: { [K in AnalyticsTriggers]?: EVENTS[]; } = {
77
+ [AnalyticsTriggers.SCENE_VIEW]: [EVENTS.SCENE_VIEW],
78
+ [AnalyticsTriggers.BUFFERING_START]: [EVENTS.BUFFERING],
79
+ [AnalyticsTriggers.BUFFERING_STOP]: [EVENTS.BUFFERING],
80
+ [AnalyticsTriggers.PLAYBACK_10]: [EVENTS.VIDEO_PROGRESS],
81
+ [AnalyticsTriggers.PLAYBACK_25]: [EVENTS.VIDEO_PROGRESS],
82
+ [AnalyticsTriggers.PLAYBACK_50]: [EVENTS.VIDEO_PROGRESS],
83
+ [AnalyticsTriggers.PLAYBACK_75]: [EVENTS.VIDEO_PROGRESS],
84
+ [AnalyticsTriggers.PLAYBACK_90]: [EVENTS.VIDEO_COMPLETE],
85
+ [AnalyticsTriggers.PLAYBACK_PAUSE]: [EVENTS.VIDEO_PAUSE],
86
+ [AnalyticsTriggers.PLAYBACK_START]: [EVENTS.VIDEO_START],
87
+ [AnalyticsTriggers.PLAYBACK_STOP]: [EVENTS.VIDEO_STOP],
88
+ [AnalyticsTriggers.PLAYER_CLOSE]: [EVENTS.PLAYER_CLOSE],
89
+ [AnalyticsTriggers.PLAYER_OPEN]: [EVENTS.PLAYER_OPEN],
90
+ [AnalyticsTriggers.SCROLL_25]: [EVENTS.SCROLL],
91
+ [AnalyticsTriggers.SCROLL_50]: [EVENTS.SCROLL],
92
+ [AnalyticsTriggers.SCROLL_75]: [EVENTS.SCROLL],
93
+ [AnalyticsTriggers.SCROLL_90]: [EVENTS.SCROLL],
94
+ [AnalyticsTriggers.APP_CLOSE]: [EVENTS.VIDEO_STOP, EVENTS.PLAYER_CLOSE],
95
+ [AnalyticsTriggers.AD_LOADED]: [EVENTS.AD_LOADED],
96
+ [AnalyticsTriggers.AD_SKIPPED]: [EVENTS.AD_SKIPPED],
97
+ };
98
+
99
+ export const HUNDRED_PERCENT = 100;
@@ -0,0 +1,8 @@
1
+ /* eslint-disable no-magic-numbers */
2
+ /**
3
+ * Recommended way to generate session id by Google.
4
+ * Blackbox
5
+ */
6
+ export const generateSessionId = () => (
7
+ Math.floor(Math.random() * (2147483647 - 0 + 1) + 0)
8
+ );
@@ -0,0 +1,34 @@
1
+ import { time } from '@24i/bigscreen-sdk/time';
2
+ import { MINUTES_PER_HOUR } from '@24i/bigscreen-sdk/utils';
3
+
4
+ export const getTimezoneOffsetString = (): string => {
5
+ const timezoneOffset = time.getTimezoneOffset();
6
+ const offsetHours = Math.floor(Math.abs(timezoneOffset) / MINUTES_PER_HOUR);
7
+ const offsetMinutesRemainder = Math.abs(timezoneOffset) % MINUTES_PER_HOUR;
8
+
9
+ const sign = timezoneOffset <= 0 ? '+' : '-';
10
+
11
+ const offsetHoursString = offsetHours.toString().padStart(2, '0');
12
+ const offsetMinutesString = offsetMinutesRemainder.toString().padStart(2, '0');
13
+ return `${sign}${offsetHoursString}:${offsetMinutesString}`;
14
+ };
15
+
16
+ export const formatDateTime = (date: Date): string => {
17
+ if (Number.isNaN(date.getTime())) {
18
+ return '';
19
+ }
20
+ const year = date.getUTCFullYear();
21
+ const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
22
+ const day = date.getUTCDate().toString().padStart(2, '0');
23
+ const hours = date.getUTCHours().toString().padStart(2, '0');
24
+ const minutes = date.getUTCMinutes().toString().padStart(2, '0');
25
+ const seconds = date.getUTCSeconds().toString().padStart(2, '0');
26
+
27
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}+00:00`;
28
+ };
29
+
30
+ export const getAssetId = (url: string = ''): string => {
31
+ const urlParts = url.split('/');
32
+ const lastPart = urlParts[urlParts.length - 1];
33
+ return lastPart !== '' ? lastPart : '';
34
+ };
@@ -0,0 +1,2 @@
1
+ export { TwentyFourIQClient } from './TwentyFourIQClient';
2
+ export { TWENTY_FOUR_IQ_TRIGGERS } from './constants';
@@ -0,0 +1,31 @@
1
+ import {
2
+ EVENTS,
3
+ } from './constants';
4
+ import { mapSceneView } from './mappers/mapSceneView';
5
+ import { mapBuffering } from './mappers/mapBuffering';
6
+ import { mapScroll } from './mappers/mapScroll';
7
+ import { mapVideoProgress } from './mappers/mapVideoProgress';
8
+ import { mapVideoStop } from './mappers/mapVideoStop';
9
+ import { mapVideoComplete } from './mappers/mapVideoComplete';
10
+ import { mapPlayerOpen } from './mappers/mapPlayerOpen';
11
+ import { mapPlayerClose } from './mappers/mapPlayerClose';
12
+ import { mapVideoStart } from './mappers/mapVideoStart';
13
+ import { mapVideoPause } from './mappers/mapVideoPause';
14
+ import { mapAdLoaded } from './mappers/mapAdLoaded';
15
+ import { mapAdSkipped } from './mappers/mapAdSkipped';
16
+ import { EventMappingFunction } from './types';
17
+
18
+ export const EVENTS_MAPPING: Record<EVENTS, EventMappingFunction> = {
19
+ [EVENTS.SCENE_VIEW]: mapSceneView,
20
+ [EVENTS.BUFFERING]: mapBuffering,
21
+ [EVENTS.SCROLL]: mapScroll,
22
+ [EVENTS.PLAYER_OPEN]: mapPlayerOpen,
23
+ [EVENTS.PLAYER_CLOSE]: mapPlayerClose,
24
+ [EVENTS.VIDEO_START]: mapVideoStart,
25
+ [EVENTS.VIDEO_STOP]: mapVideoStop,
26
+ [EVENTS.VIDEO_PROGRESS]: mapVideoProgress,
27
+ [EVENTS.VIDEO_COMPLETE]: mapVideoComplete,
28
+ [EVENTS.VIDEO_PAUSE]: mapVideoPause,
29
+ [EVENTS.AD_LOADED]: mapAdLoaded,
30
+ [EVENTS.AD_SKIPPED]: mapAdSkipped,
31
+ };
@@ -0,0 +1,13 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { getAssetId } from '../helper';
3
+ import { Payload, AdLoadedResult } from '../types';
4
+ import { mapBase } from './mapBase';
5
+
6
+ export const mapAdLoaded = (triggerName: AnalyticsTriggers, payload: Payload): AdLoadedResult => ({
7
+ ...mapBase(payload),
8
+ action: triggerName,
9
+ event_trigger: triggerName,
10
+ thing_id: getAssetId(payload.sceneId),
11
+ player_advertisment_name: '', // TODO: adPayload?.adName,
12
+ player_advertisment_position: 0, // TODO: adPayload?.adPosition,
13
+ });
@@ -0,0 +1,16 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { getAssetId } from '../helper';
3
+ import { Payload, AdSkippedResult } from '../types';
4
+ import { mapBase } from './mapBase';
5
+
6
+ export const mapAdSkipped = (
7
+ triggerName: AnalyticsTriggers,
8
+ payload: Payload,
9
+ ): AdSkippedResult => ({
10
+ ...mapBase(payload),
11
+ action: triggerName,
12
+ event_trigger: triggerName,
13
+ thing_id: getAssetId(payload.sceneId),
14
+ player_advertisment_name: '', // TODO: adPayload?.adName,
15
+ player_advertisment_position: 0, // TODO: adPayload?.adPosition,
16
+ });
@@ -0,0 +1,21 @@
1
+ import { time } from '@24i/bigscreen-sdk/time';
2
+ import { Payload, BaseResult } from '../types';
3
+ import { formatDateTime, getTimezoneOffsetString } from '../helper';
4
+
5
+ export const mapBase = (payload: Payload): BaseResult => {
6
+ const timestampDate = time.getCurrentTime();
7
+ const formatedTimestamp = getTimezoneOffsetString();
8
+ return {
9
+ session_id: payload.sessionId.toString(),
10
+ timestamp_initiated: formatDateTime(timestampDate),
11
+ device_id: payload.deviceId,
12
+ device_type: payload.deviceType,
13
+ device_platform: payload.platform || '',
14
+ device_timezone: formatedTimestamp,
15
+ service_id: payload.serviceId || '',
16
+ user_id: payload.userId || '',
17
+ user_profile_id: payload.userProfileId,
18
+ custom_gdpr_status: payload.gdprStatus,
19
+ ...(!payload.userId && { user_anon_id: payload.deviceId }),
20
+ };
21
+ };
@@ -0,0 +1,15 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { getAssetId } from '../helper';
3
+ import { Payload, BufferingResult } from '../types';
4
+ import { mapBase } from './mapBase';
5
+
6
+ export const mapBuffering = (
7
+ triggerName: AnalyticsTriggers,
8
+ payload: Payload,
9
+ ): BufferingResult => ({
10
+ ...mapBase(payload),
11
+ action: triggerName,
12
+ event_trigger: triggerName,
13
+ thing_id: getAssetId(payload.sceneId),
14
+ source_page: payload.sceneName,
15
+ });
@@ -0,0 +1,24 @@
1
+ import { SECOND_IN_MS } from '@24i/bigscreen-sdk/utils';
2
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
3
+ import { EVENTS, HUNDRED_PERCENT } from '../constants';
4
+ import { PlayerCloseResult, Payload } from '../types';
5
+ import { mapBase } from './mapBase';
6
+ import { getAssetId } from '../helper';
7
+
8
+ export const mapPlayerClose = (
9
+ triggerName: AnalyticsTriggers,
10
+ payload: Payload,
11
+ ): PlayerCloseResult | undefined => {
12
+ const progressPercent = Number(payload.percentOfPlayback);
13
+ const assetDuration = Number(payload.duration) / SECOND_IN_MS
14
+ || payload?.asset?.duration || 0;
15
+ const duration = Math.round((assetDuration * progressPercent) / HUNDRED_PERCENT);
16
+ return {
17
+ ...mapBase(payload),
18
+ action: EVENTS.PLAYER_CLOSE,
19
+ event_trigger: triggerName,
20
+ thing_id: getAssetId(payload.sceneId),
21
+ duration,
22
+ progress_pct: progressPercent,
23
+ };
24
+ };
@@ -0,0 +1,18 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { DefaultScreens } from '../constants';
3
+ import { getAssetId } from '../helper';
4
+
5
+ import { PlayerOpenResult, Payload } from '../types';
6
+ import { mapBase } from './mapBase';
7
+
8
+ export const mapPlayerOpen = (
9
+ triggerName: AnalyticsTriggers,
10
+ payload: Payload,
11
+ ): PlayerOpenResult => ({
12
+ ...mapBase(payload),
13
+ action: triggerName,
14
+ event_trigger: triggerName,
15
+ source_page: DefaultScreens.PLAYBACK,
16
+ thing_id: getAssetId(payload.sceneId),
17
+ source_rail: '', // TODO: payload.payload.asset.sectionLabel,
18
+ });
@@ -0,0 +1,15 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { getAssetId } from '../helper';
3
+ import { Payload, SceneViewResult } from '../types';
4
+ import { mapBase } from './mapBase';
5
+
6
+ export const mapSceneView = (
7
+ triggerName: AnalyticsTriggers,
8
+ payload: Payload,
9
+ ): SceneViewResult | undefined => ({
10
+ ...mapBase(payload),
11
+ action: triggerName,
12
+ event_trigger: triggerName,
13
+ source_page: payload.sceneName,
14
+ thing_id: getAssetId(payload.sceneId),
15
+ });
@@ -0,0 +1,17 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { EVENTS } from '../constants';
3
+ import { getAssetId } from '../helper';
4
+ import { Payload, ScrollResult } from '../types';
5
+ import { mapBase } from './mapBase';
6
+
7
+ export const mapScroll = (triggerName: AnalyticsTriggers, payload: Payload): ScrollResult => {
8
+ const percentScrolled = triggerName.split('_')[1];
9
+ return {
10
+ ...mapBase(payload),
11
+ action: EVENTS.SCROLL,
12
+ event_trigger: triggerName,
13
+ source_page: payload.sceneName,
14
+ thing_id: getAssetId(payload.sceneId),
15
+ percent_scrolled: percentScrolled,
16
+ };
17
+ };
@@ -0,0 +1,21 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { SECOND_IN_MS } from '@24i/bigscreen-sdk/utils';
3
+ import { EVENTS } from '../constants';
4
+ import { Payload, VideoCompleteResult } from '../types';
5
+ import { mapBase } from './mapBase';
6
+ import { getAssetId } from '../helper';
7
+
8
+ export const mapVideoComplete = (
9
+ triggerName: AnalyticsTriggers,
10
+ payload: Payload,
11
+ ): VideoCompleteResult => {
12
+ const assetDuration = (payload.duration || 0) / SECOND_IN_MS;
13
+ return {
14
+ ...mapBase(payload),
15
+ action: EVENTS.VIDEO_COMPLETE,
16
+ event_trigger: triggerName,
17
+ thing_id: getAssetId(payload.sceneId),
18
+ progress_pct: 90,
19
+ duration: assetDuration,
20
+ };
21
+ };
@@ -0,0 +1,24 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { SECOND_IN_MS } from '@24i/bigscreen-sdk/utils';
3
+ import { EVENTS, HUNDRED_PERCENT } from '../constants';
4
+ import { VideoPauseResult, Payload } from '../types';
5
+ import { mapBase } from './mapBase';
6
+ import { getAssetId } from '../helper';
7
+
8
+ export const mapVideoPause = (
9
+ triggerName: AnalyticsTriggers,
10
+ payload: Payload,
11
+ ): VideoPauseResult => {
12
+ const { asset, duration = 0 } = payload;
13
+ const progressPercent = Number(payload.percentOfPlayback);
14
+ const assetDuration = duration / SECOND_IN_MS || asset?.duration || 0;
15
+ const overallDuration = Math.round((assetDuration * progressPercent) / HUNDRED_PERCENT);
16
+ return {
17
+ ...mapBase(payload),
18
+ action: EVENTS.VIDEO_PAUSE,
19
+ event_trigger: triggerName,
20
+ thing_id: getAssetId(payload.sceneId),
21
+ duration: overallDuration,
22
+ progress_pct: progressPercent,
23
+ };
24
+ };
@@ -0,0 +1,24 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { SECOND_IN_MS } from '@24i/bigscreen-sdk/utils';
3
+ import { Payload, VideoProgressResult } from '../types';
4
+ import { EVENTS, HUNDRED_PERCENT } from '../constants';
5
+ import { mapBase } from './mapBase';
6
+ import { getAssetId } from '../helper';
7
+
8
+ export const mapVideoProgress = (
9
+ triggerName: AnalyticsTriggers,
10
+ payload: Payload,
11
+ ): VideoProgressResult => {
12
+ const { asset, duration = 0 } = payload;
13
+ const progressPercent = Number(triggerName.split('_')[1]);
14
+ const assetDuration = duration / SECOND_IN_MS || asset?.duration || 0;
15
+ const durationInSeconds = Math.round((assetDuration * progressPercent) / HUNDRED_PERCENT);
16
+ return {
17
+ ...mapBase(payload),
18
+ action: EVENTS.VIDEO_PROGRESS,
19
+ event_trigger: triggerName,
20
+ thing_id: getAssetId(payload.sceneId),
21
+ progress_pct: progressPercent,
22
+ duration: durationInSeconds,
23
+ };
24
+ };
@@ -0,0 +1,34 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { PropertyType } from '@24i/smartapps-datalayer/models';
3
+ import { SECOND_IN_MS } from '@24i/bigscreen-sdk/utils';
4
+ import { DefaultScreens, EVENTS } from '../constants';
5
+ import { VideoStartResult, Payload } from '../types';
6
+ import { mapBase } from './mapBase';
7
+ import { getAssetId } from '../helper';
8
+
9
+ const HUNDRED_PERCENT = 100;
10
+
11
+ export const mapVideoStart = (
12
+ triggerName: AnalyticsTriggers,
13
+ payload: Payload,
14
+ ): VideoStartResult => {
15
+ const { duration = 0, asset } = payload;
16
+ const assetDuration = duration / SECOND_IN_MS || asset?.duration || 0;
17
+ const startPosition = Number(asset?.properties?.find(
18
+ (property) => property.type === PropertyType.WATCH_PROGRESS,
19
+ ) || 0);
20
+ let progressPercent = 0;
21
+ if (assetDuration !== 0 && startPosition !== 0) {
22
+ progressPercent = Number(((startPosition / assetDuration) * HUNDRED_PERCENT).toFixed(2));
23
+ }
24
+ return {
25
+ ...mapBase(payload),
26
+ action: EVENTS.VIDEO_START,
27
+ event_trigger: triggerName,
28
+ thing_id: getAssetId(payload.sceneId),
29
+ duration: assetDuration,
30
+ progress_pct: progressPercent,
31
+ source_page: DefaultScreens.PLAYBACK,
32
+ source_rail: '', // TODO: asset.sectionLabel,
33
+ };
34
+ };
@@ -0,0 +1,32 @@
1
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
2
+ import { SECOND_IN_MS } from '@24i/bigscreen-sdk/utils';
3
+ import { PropertyType } from '@24i/smartapps-datalayer/models';
4
+ import { DefaultScreens, EVENTS, HUNDRED_PERCENT } from '../constants';
5
+ import { Payload, VideoStopResult } from '../types';
6
+ import { mapBase } from './mapBase';
7
+ import { getAssetId } from '../helper';
8
+
9
+ export const mapVideoStop = (
10
+ triggerName: AnalyticsTriggers,
11
+ payload: Payload,
12
+ ): VideoStopResult | undefined => {
13
+ const { duration = 0, asset } = payload;
14
+ const assetDuration = duration / SECOND_IN_MS || asset?.duration || 0;
15
+ const startPosition = Number(asset?.properties?.find(
16
+ (property) => property.type === PropertyType.WATCH_PROGRESS,
17
+ ) || 0);
18
+ let progressPercent = 0;
19
+ if (assetDuration !== 0 && startPosition !== 0) {
20
+ progressPercent = Number(((startPosition / assetDuration) * HUNDRED_PERCENT));
21
+ }
22
+ return {
23
+ ...mapBase(payload),
24
+ action: EVENTS.VIDEO_STOP,
25
+ event_trigger: triggerName,
26
+ thing_id: getAssetId(payload.sceneId),
27
+ progress_pct: progressPercent,
28
+ duration,
29
+ source_page: DefaultScreens.PLAYBACK,
30
+ source_rail: '', // TODO: payload.payload.asset.sectionLabel,
31
+ };
32
+ };
@@ -0,0 +1,115 @@
1
+ import { Asset } from '@24i/smartapps-datalayer/models';
2
+ import { AnalyticsTriggers } from '@24i/appstage-shared-analytics';
3
+ import type { AnyPayload, UserInfo, AppInfo } from '../../interface';
4
+
5
+ interface ScreenParams {
6
+ screen: string;
7
+ screenName: string;
8
+ id: string;
9
+ asset: Asset;
10
+ }
11
+ export interface CorePayload {
12
+ timestamp?: number;
13
+ params?: ScreenParams;
14
+ asset?: Asset;
15
+ source?: string;
16
+ duration?: number;
17
+ id?: string;
18
+ percentOfPlayback?: number;
19
+ }
20
+
21
+ export interface SessionInfo {
22
+ sessionId: number;
23
+ sessionNumber: number;
24
+ }
25
+
26
+ export interface DeviceInfo {
27
+ appVersion: string,
28
+ manufacturer: string,
29
+ platform: string,
30
+ platformVersion: string,
31
+ deviceId: string,
32
+ }
33
+
34
+ export interface SceneInfo {
35
+ sceneName: string,
36
+ sceneId: string,
37
+ sceneType?: string,
38
+ }
39
+
40
+ export type Payload = CorePayload & SceneInfo & SessionInfo & UserInfo & AppInfo;
41
+
42
+ export type EventBody = AnyPayload;
43
+
44
+ export type EventMappingFunction = (
45
+ triggerName: AnalyticsTriggers,
46
+ payload: Payload
47
+ ) => AnyPayload | void;
48
+
49
+ export type BaseResult = {
50
+ session_id: string;
51
+ timestamp_initiated: string;
52
+ device_id: string;
53
+ device_type: string;
54
+ device_platform: string;
55
+ device_timezone: string;
56
+ service_id: string;
57
+ user_id?: string;
58
+ user_profile_id?: string;
59
+ custom_gdpr_status?: boolean;
60
+ };
61
+
62
+ export type CoreResult = BaseResult & {
63
+ action: string;
64
+ event_trigger: string;
65
+ };
66
+ export type SceneViewResult = CoreResult & {
67
+ source_page: string;
68
+ thing_id: string;
69
+ };
70
+ export type BufferingResult = SceneViewResult;
71
+
72
+ export type ScrollResult = SceneViewResult & {
73
+ percent_scrolled: string;
74
+ };
75
+ export type VideoProgressResult = CoreResult & {
76
+ thing_id: string;
77
+ progress_pct: number;
78
+ duration: number;
79
+ };
80
+
81
+ export type PlayerOpenResult = CoreResult & {
82
+ thing_id: string;
83
+ source_page: string;
84
+ source_rail?: string | null;
85
+ };
86
+
87
+ export type VideoStartResult = CoreResult & {
88
+ thing_id: string;
89
+ duration: number;
90
+ progress_pct: number;
91
+ source_page: string;
92
+ source_rail?: string | null;
93
+ };
94
+
95
+ export type VideoPauseResult = CoreResult & {
96
+ thing_id: string;
97
+ duration: number;
98
+ progress_pct: number;
99
+ };
100
+
101
+ export type AdLoadedResult = CoreResult & {
102
+ thing_id: string;
103
+ player_advertisment_name: string;
104
+ player_advertisment_position: number;
105
+ };
106
+
107
+ export type AdSkippedResult = CoreResult & {
108
+ thing_id: string;
109
+ player_advertisment_name: string;
110
+ player_advertisment_position: number;
111
+ };
112
+
113
+ export type VideoCompleteResult = VideoPauseResult;
114
+ export type VideoStopResult = VideoStartResult;
115
+ export type PlayerCloseResult = VideoPauseResult;
@@ -1 +1 @@
1
- export * from '@24i/appstage-shared-analytics/dist/constants';
1
+ export * from '@24i/appstage-shared-analytics';
@@ -37,5 +37,6 @@ export type { XhrOptions, XhrResponse, RetryConfig, RSOptions, ShouldRetryParam
37
37
  export {
38
38
  registerKeyPressSimulator,
39
39
  unregisterKeyPressSimulator,
40
+ dispatchKeyboardEvent,
40
41
  simulateKeyPress,
41
42
  } from './keyPress';
@@ -1,2 +1,6 @@
1
- export { registerKeyPressSimulator, unregisterKeyPressSimulator } from './keyPressSimulator';
1
+ export {
2
+ registerKeyPressSimulator,
3
+ unregisterKeyPressSimulator,
4
+ dispatchKeyboardEvent,
5
+ } from './keyPressSimulator';
2
6
  export { simulateKeyPress } from './simulateKeyPress';
@@ -3,9 +3,19 @@ import { stopEvent } from '@24i/bigscreen-sdk/utils';
3
3
 
4
4
  let keysPressed: Record<number, boolean>;
5
5
 
6
+ interface CustomKeyboardEvent extends KeyboardEvent {
7
+ skipKeyPressSimulation: boolean;
8
+ }
9
+
10
+ const shouldSkipEvent = (e: KeyboardEvent) => (
11
+ Boolean((e as CustomKeyboardEvent).skipKeyPressSimulation)
12
+ );
13
+
6
14
  const onKeyDown = (e: KeyboardEvent) => {
15
+ if (shouldSkipEvent(e)) return;
7
16
  const { keyCode } = e;
8
17
  if (keysPressed[keyCode] === true) {
18
+ console.warn(`Key ${e.code} (${e.keyCode}) is skipped by the key press simulator`);
9
19
  stopEvent(e);
10
20
  } else if (typeof keysPressed[keyCode] !== 'undefined') {
11
21
  keysPressed[keyCode] = true;
@@ -42,3 +52,23 @@ export const unregisterKeyPressSimulator = () => {
42
52
  window.document.removeEventListener('keydown', onKeyDown, true);
43
53
  window.document.removeEventListener('keyup', onKeyUp, true);
44
54
  };
55
+
56
+ /**
57
+ * This should be the main method for manually dispatching keyboard events when the
58
+ * key press simulator is registered in the app. When parameter `skipKeyPressSimulation`
59
+ * is `true`, those event's won't be caught by the key press simulator and
60
+ * are no longer under it's influence. Key press simulator should work only with events
61
+ * generated from input device.
62
+ * @param target element target to dispatch event
63
+ * @param event dispatching event
64
+ * @param skipKeyPressSimulation default value is `true`, when false, the event
65
+ * will be caught by the simulator and other dispatched events will be stopped.
66
+ */
67
+ export const dispatchKeyboardEvent = (
68
+ target: HTMLElement,
69
+ event: KeyboardEvent,
70
+ skipKeyPressSimulation = true,
71
+ ) => {
72
+ (event as CustomKeyboardEvent).skipKeyPressSimulation = skipKeyPressSimulation;
73
+ target.dispatchEvent(event);
74
+ };