@24i/bigscreen-sdk 1.0.14-alpha.2280 → 1.0.14-alpha.2284
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/package.json +3 -3
- package/packages/analytics/src/clients/GoogleAnalytics/GoogleAnalytics.ts +27 -18
- package/packages/analytics/src/clients/GoogleAnalytics/constants.ts +64 -9
- package/packages/analytics/src/clients/GoogleAnalytics/interface.ts +26 -14
- package/packages/analytics/src/clients/GoogleAnalytics/mapPayload.ts +31 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@24i/bigscreen-sdk",
|
|
3
|
-
"version": "1.0.14-alpha.
|
|
3
|
+
"version": "1.0.14-alpha.2284",
|
|
4
4
|
"description": "SmartApps BIGscreen SDK monorepo",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/24i/smartapps-bigscreen-sdk#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@24i/appstage-shared-analytics": "1.0.
|
|
40
|
+
"@24i/appstage-shared-analytics": "1.0.1-alpha1",
|
|
41
41
|
"@24i/appstage-shared-events-manager": "1.0.7",
|
|
42
42
|
"@24i/appstage-shared-perf-utils": "1.0.5",
|
|
43
43
|
"@24i/player-base": "6.10.0",
|
|
44
|
-
"@24i/smartapps-datalayer": "3.0.7-alpha.
|
|
44
|
+
"@24i/smartapps-datalayer": "3.0.7-alpha.993",
|
|
45
45
|
"@sentry/browser": "7.35.0",
|
|
46
46
|
"@sentry/types": "7.35.0",
|
|
47
47
|
"@types/gtag.js": "^0.0.12",
|
|
@@ -34,15 +34,20 @@ export class GoogleAnalytics implements AnalyticsClient {
|
|
|
34
34
|
cid: '',
|
|
35
35
|
sid: 0,
|
|
36
36
|
uamb: 0,
|
|
37
|
-
uap: '',
|
|
38
|
-
uapv: '',
|
|
39
|
-
uam: '',
|
|
40
37
|
seg: 0,
|
|
41
38
|
sct: 0,
|
|
42
39
|
_p: generateUuid(),
|
|
40
|
+
'up.device_manufacturer': '',
|
|
41
|
+
'up.device_platform': '',
|
|
42
|
+
'up.device_platform_version': '',
|
|
43
|
+
'up.app_version': '',
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
manufacturer = '';
|
|
47
|
+
|
|
48
|
+
platform = '';
|
|
49
|
+
|
|
50
|
+
platformVersion = '';
|
|
46
51
|
|
|
47
52
|
lastOnEvent: number | undefined = undefined;
|
|
48
53
|
|
|
@@ -58,7 +63,7 @@ export class GoogleAnalytics implements AnalyticsClient {
|
|
|
58
63
|
|
|
59
64
|
firstVisit: boolean | undefined = undefined;
|
|
60
65
|
|
|
61
|
-
constructor(private id: string) {
|
|
66
|
+
constructor(private id: string, private appVersion: string = '') {
|
|
62
67
|
this.init();
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -73,16 +78,20 @@ export class GoogleAnalytics implements AnalyticsClient {
|
|
|
73
78
|
if (this.firstVisit) {
|
|
74
79
|
await Storage.setItem(GA_FIRST_VISIT, '0');
|
|
75
80
|
}
|
|
81
|
+
this.manufacturer = await device.getManufacturerName();
|
|
82
|
+
this.platform = await device.getPlatformName();
|
|
83
|
+
this.platformVersion = await device.getPlatformVersion();
|
|
76
84
|
await this.startSession();
|
|
77
|
-
params.uap = await device.getPlatformName();
|
|
78
|
-
params.uapv = await device.getPlatformVersion();
|
|
79
|
-
params.uam = await device.getModelName();
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
async startSession() {
|
|
83
88
|
const sessionNumber = parseInt(await Storage.getItem(GA_SESSION_COUNTER) ?? '0', 10) + 1;
|
|
84
89
|
this.constantUrlParams.sct = sessionNumber;
|
|
85
90
|
this.constantUrlParams.sid = generateSessionId();
|
|
91
|
+
this.constantUrlParams['up.device_manufacturer'] = this.manufacturer;
|
|
92
|
+
this.constantUrlParams['up.device_platform'] = this.platform;
|
|
93
|
+
this.constantUrlParams['up.device_platform_version'] = this.platformVersion;
|
|
94
|
+
this.constantUrlParams['up.app_version'] = this.appVersion;
|
|
86
95
|
await Storage.setItem(GA_SESSION_COUNTER, sessionNumber.toString());
|
|
87
96
|
this.isSessionActive = true;
|
|
88
97
|
this.setSessionTimeout();
|
|
@@ -113,11 +122,14 @@ export class GoogleAnalytics implements AnalyticsClient {
|
|
|
113
122
|
const engagementTime = this.lastOnEvent ? now - this.lastOnEvent : undefined;
|
|
114
123
|
this.lastOnEvent = now;
|
|
115
124
|
await Promise.all(events.map(async (event, index) => {
|
|
116
|
-
|
|
125
|
+
const sessionInfo = await this.getSessionInfo(
|
|
126
|
+
index === 0 ? engagementTime : undefined,
|
|
127
|
+
);
|
|
117
128
|
const gtagPayload = mapPayload(
|
|
118
|
-
event, triggerName,
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
event, triggerName, {
|
|
130
|
+
...payload,
|
|
131
|
+
...sessionInfo,
|
|
132
|
+
},
|
|
121
133
|
);
|
|
122
134
|
const urlParams = mapEventParamsToUrlParams(payload as SceneInfo);
|
|
123
135
|
this.send(event, gtagPayload, urlParams);
|
|
@@ -162,12 +174,6 @@ export class GoogleAnalytics implements AnalyticsClient {
|
|
|
162
174
|
|
|
163
175
|
private sendQueueWithDelay = debounce(this.sendQueue, SEND_DEBOUNCE_MS);
|
|
164
176
|
|
|
165
|
-
private shouldContinueWithA24iOperational() {
|
|
166
|
-
const { a24iOperational } = this;
|
|
167
|
-
if (!a24iOperational) this.a24iOperational = true;
|
|
168
|
-
return !a24iOperational;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
177
|
private async getSessionInfo(engagementTime: number | undefined): Promise<SessionInfo> {
|
|
172
178
|
const sessionStarted = !this.sessionStartSent;
|
|
173
179
|
this.sessionStartSent = true;
|
|
@@ -176,6 +182,9 @@ export class GoogleAnalytics implements AnalyticsClient {
|
|
|
176
182
|
const { firstVisit } = this;
|
|
177
183
|
this.firstVisit = false;
|
|
178
184
|
return {
|
|
185
|
+
appVersion: this.appVersion,
|
|
186
|
+
manufacturer: this.manufacturer,
|
|
187
|
+
platform: this.platform,
|
|
179
188
|
sessionStarted,
|
|
180
189
|
engagementTime,
|
|
181
190
|
firstEvent,
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { GAEventsNames } from './interface';
|
|
2
2
|
|
|
3
|
+
const stringParameter = 'ep';
|
|
4
|
+
const numericParameter = 'epn';
|
|
5
|
+
|
|
3
6
|
export const GOOGLE_ANALYTICS_TRIGGERS = [
|
|
7
|
+
'scene_view',
|
|
4
8
|
'app_close',
|
|
9
|
+
// player triggers
|
|
5
10
|
'playback_10',
|
|
6
11
|
'playback_25',
|
|
7
12
|
'playback_50',
|
|
@@ -12,42 +17,92 @@ export const GOOGLE_ANALYTICS_TRIGGERS = [
|
|
|
12
17
|
'playback_stop',
|
|
13
18
|
'player_close',
|
|
14
19
|
'player_open',
|
|
15
|
-
'
|
|
20
|
+
'heartbeat_5',
|
|
21
|
+
// scroll triggers
|
|
16
22
|
'scroll_25',
|
|
17
23
|
'scroll_50',
|
|
18
24
|
'scroll_75',
|
|
19
25
|
'scroll_90',
|
|
26
|
+
// additional triggers
|
|
27
|
+
'app_error',
|
|
28
|
+
'toggle_favorite',
|
|
29
|
+
'search',
|
|
30
|
+
'rate_content',
|
|
31
|
+
// ads triggers
|
|
32
|
+
'ad_loaded',
|
|
33
|
+
'ad_skipped',
|
|
34
|
+
// user triggers
|
|
35
|
+
'login',
|
|
36
|
+
'logout',
|
|
37
|
+
'sign_up',
|
|
38
|
+
// purchases
|
|
39
|
+
'purchase_cancel',
|
|
40
|
+
'purchase_complete',
|
|
41
|
+
'purchase_start',
|
|
42
|
+
|
|
20
43
|
] as const;
|
|
21
44
|
|
|
22
45
|
export const TRIGGER_NAME_TO_GA_EVENTS: Record<
|
|
23
46
|
typeof GOOGLE_ANALYTICS_TRIGGERS[number], GAEventsNames[]
|
|
24
47
|
> = {
|
|
25
48
|
// App
|
|
26
|
-
app_close: ['
|
|
49
|
+
app_close: ['close_player_session', 'video_progress'],
|
|
27
50
|
|
|
28
51
|
// Playback
|
|
52
|
+
heartbeat_5: ['video_progress'],
|
|
29
53
|
playback_10: ['video_progress'],
|
|
30
54
|
playback_25: ['video_progress'],
|
|
31
55
|
playback_50: ['video_progress'],
|
|
32
56
|
playback_75: ['video_progress'],
|
|
33
|
-
playback_90: ['
|
|
57
|
+
playback_90: ['video_complete'],
|
|
34
58
|
playback_pause: ['video_progress'],
|
|
35
59
|
playback_start: ['video_start'],
|
|
36
60
|
playback_stop: ['video_progress'],
|
|
37
61
|
|
|
38
62
|
// Player
|
|
39
|
-
player_close: ['
|
|
40
|
-
player_open: ['
|
|
63
|
+
player_close: ['close_player_session', 'video_progress'],
|
|
64
|
+
player_open: ['open_player_session'],
|
|
41
65
|
|
|
42
66
|
// Scenes
|
|
43
|
-
scene_view: [
|
|
44
|
-
'page_view',
|
|
45
|
-
'a24i_operational',
|
|
46
|
-
],
|
|
67
|
+
scene_view: ['page_view'],
|
|
47
68
|
|
|
48
69
|
// Scrolling in scene
|
|
49
70
|
scroll_25: ['scroll'],
|
|
50
71
|
scroll_50: ['scroll'],
|
|
51
72
|
scroll_75: ['scroll'],
|
|
52
73
|
scroll_90: ['scroll'],
|
|
74
|
+
|
|
75
|
+
// purchases
|
|
76
|
+
purchase_cancel: [],
|
|
77
|
+
purchase_complete: [],
|
|
78
|
+
purchase_start: [],
|
|
79
|
+
|
|
80
|
+
// additional triggers
|
|
81
|
+
app_error: [],
|
|
82
|
+
toggle_favorite: [],
|
|
83
|
+
search: [],
|
|
84
|
+
rate_content: [],
|
|
85
|
+
|
|
86
|
+
// ads triggers
|
|
87
|
+
ad_loaded: [],
|
|
88
|
+
ad_skipped: [],
|
|
89
|
+
|
|
90
|
+
// user triggers
|
|
91
|
+
login: ['login'],
|
|
92
|
+
logout: [],
|
|
93
|
+
sign_up: [],
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const gtagPayloadParams: Record<string, string> = {
|
|
97
|
+
contentType: `${stringParameter}.content_type`,
|
|
98
|
+
episodeNumber: `${numericParameter}.episode_number`,
|
|
99
|
+
seasonNumber: `${numericParameter}.season_number`,
|
|
100
|
+
currentTime: `${numericParameter}.video_current_time`,
|
|
101
|
+
duration: `${numericParameter}.video_duration`,
|
|
102
|
+
percent: `${numericParameter}.video_current_percent`,
|
|
103
|
+
provider: `${stringParameter}.video_provider`,
|
|
104
|
+
title: `${stringParameter}.video_title`,
|
|
105
|
+
seriesTitle: `${stringParameter}.video_series_title`,
|
|
106
|
+
url: `${stringParameter}.video_url`,
|
|
107
|
+
assetId: `${stringParameter}.video_asset_id`,
|
|
53
108
|
};
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
export type GAEventsNames = (
|
|
2
|
-
| '
|
|
3
|
-
| '
|
|
4
|
-
| '
|
|
5
|
-
| '
|
|
6
|
-
| '
|
|
7
|
-
| '
|
|
8
|
-
| '
|
|
9
|
-
| '
|
|
2
|
+
| 'app_close' // When the playback is active at the time the app or website is closing.
|
|
3
|
+
| 'page_view' // Each time the page loads or the browser history state is changed
|
|
4
|
+
| 'scroll' // The first time a user reaches the bottom of each page
|
|
5
|
+
| 'video_progress' // When the video progresses past 10%, 25%, 50%, and 75% duration time
|
|
6
|
+
| 'video_start' // When the video starts playing
|
|
7
|
+
| 'video_complete' // When the video ends
|
|
8
|
+
| 'open_player_session' // When the user opens a player scene and the player is initiated
|
|
9
|
+
| 'close_player_session' // When the user exits the player scene with initiated player
|
|
10
|
+
| 'select_content' // When a user has selected content
|
|
11
|
+
| 'login' // When a user logs in
|
|
12
|
+
| 'sign_up' // When a user has signed up Allows you to see which methods of signup are popular
|
|
13
|
+
| 'search' // When a user searches your content
|
|
14
|
+
| 'purchase' // When a user completes a purchase
|
|
15
|
+
| 'share' // When a user has shared content
|
|
16
|
+
| 'user_engagement' // Periodically, while the app is in the foreground
|
|
10
17
|
);
|
|
11
18
|
|
|
12
19
|
export type QueuedEvent = {
|
|
@@ -16,6 +23,9 @@ export type QueuedEvent = {
|
|
|
16
23
|
};
|
|
17
24
|
|
|
18
25
|
export type SessionInfo = {
|
|
26
|
+
appVersion: string,
|
|
27
|
+
manufacturer: string,
|
|
28
|
+
platform: string,
|
|
19
29
|
engagementTime: number | undefined,
|
|
20
30
|
sessionStarted: boolean,
|
|
21
31
|
firstEvent: boolean,
|
|
@@ -29,18 +39,20 @@ export type ConstantUrlParams = {
|
|
|
29
39
|
sid: number,
|
|
30
40
|
/** 1 for mobile devices, 0 otherwise */
|
|
31
41
|
uamb: number,
|
|
32
|
-
/** Platform name */
|
|
33
|
-
uap: string,
|
|
34
|
-
/** Platform version */
|
|
35
|
-
uapv: string,
|
|
36
|
-
/** Device model name */
|
|
37
|
-
uam: string,
|
|
38
42
|
/** Session engagement 0 for first event of session, 1 otherwise */
|
|
39
43
|
seg: number,
|
|
40
44
|
/** Session count */
|
|
41
45
|
sct: number,
|
|
42
46
|
/** Random page hash */
|
|
43
47
|
_p: string,
|
|
48
|
+
/** Device manufacturer e.g. 'Samsung' */
|
|
49
|
+
'up.device_manufacturer': string,
|
|
50
|
+
/** Platform e.g. 'Tizen' */
|
|
51
|
+
'up.device_platform': string,
|
|
52
|
+
/** Platform version e.g. '5.0' */
|
|
53
|
+
'up.device_platform_version': string,
|
|
54
|
+
/** Version of application 'v1.0.0' */
|
|
55
|
+
'up.app_version': string,
|
|
44
56
|
};
|
|
45
57
|
|
|
46
58
|
export type EventUrlParams = {
|
|
@@ -1,29 +1,46 @@
|
|
|
1
|
-
import type { AnalyticsEventsNames } from '../../interface';
|
|
2
|
-
import type { EventUrlParams, GAEventsNames
|
|
1
|
+
import type { AnalyticsEventsNames, AnyPayload } from '../../interface';
|
|
2
|
+
import type { EventUrlParams, GAEventsNames } from './interface';
|
|
3
|
+
import { gtagPayloadParams } from './constants';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const map: Record<string, string> = {
|
|
6
|
+
language: 'ul',
|
|
7
|
+
resolution: 'sr',
|
|
8
|
+
sceneId: 'dl',
|
|
9
|
+
sceneName: 'dt',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const mapEventParamsToUrlParams = (eventParams: Record<string, any>)
|
|
13
|
+
: EventUrlParams => {
|
|
14
|
+
const urlParams = {};
|
|
15
|
+
Object.entries(eventParams).forEach(([key]) => {
|
|
16
|
+
if (map[key]) {
|
|
17
|
+
Object.assign(urlParams, {
|
|
18
|
+
[map[key]]: eventParams[key] || '',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
10
22
|
return urlParams as EventUrlParams;
|
|
11
23
|
};
|
|
12
24
|
|
|
13
25
|
export const mapPayload = (
|
|
14
26
|
eventName: GAEventsNames,
|
|
15
27
|
triggerName: AnalyticsEventsNames,
|
|
16
|
-
|
|
28
|
+
payload: AnyPayload,
|
|
17
29
|
) => {
|
|
18
30
|
const gtagPayload: Record<string, any> = {
|
|
19
31
|
'ep.event_trigger': triggerName,
|
|
20
|
-
_et:
|
|
21
|
-
_ee:
|
|
22
|
-
_fv:
|
|
23
|
-
_ss:
|
|
32
|
+
_et: payload.engagementTime ?? 0,
|
|
33
|
+
_ee: payload.firstEvent ? 1 : 0,
|
|
34
|
+
_fv: payload.firstVisit ? 1 : 0,
|
|
35
|
+
_ss: payload.sessionStarted ? 1 : 0,
|
|
24
36
|
};
|
|
25
37
|
if (eventName === 'scroll') {
|
|
26
|
-
gtagPayload['epn.
|
|
38
|
+
gtagPayload['epn.percent_scrolled'] = parseInt(triggerName.split('_')[1], 10);
|
|
27
39
|
}
|
|
40
|
+
Object.keys(payload).forEach((key: keyof typeof payload) => {
|
|
41
|
+
if (gtagPayloadParams[key] !== undefined) {
|
|
42
|
+
gtagPayload[gtagPayloadParams[key]] = payload[key];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
28
45
|
return gtagPayload;
|
|
29
46
|
};
|