@gumlet/insights-js-core 1.0.3 → 1.1.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/.github/workflows/main.yml +87 -0
- package/.gitlab-ci.yml +54 -0
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/bitbucket-pipelines.yml +35 -0
- package/docs/payload-documentation.md +72 -0
- package/html/bitmovin.html +82 -0
- package/html/dashjs.html +55 -0
- package/html/hlsjs.html +72 -0
- package/html/html5.html +59 -0
- package/html/shaka.html +102 -0
- package/html/videojs.html +67 -0
- package/index.html +73 -0
- package/jest.config.js +187 -0
- package/js/adapters/Bitmovin7Adapter.js +352 -0
- package/js/adapters/BitmovinAdapter.js +198 -0
- package/js/adapters/DashjsAdapter.js +140 -0
- package/js/adapters/HTML5Adapter.js +774 -0
- package/js/adapters/HlsjsAdapter.js +152 -0
- package/js/adapters/ShakaAdapter.js +81 -0
- package/js/adapters/VideoJsAdapter.js +455 -0
- package/js/analyticsStateMachines/Bitmovin7AnalyticsStateMachine.js +471 -0
- package/js/analyticsStateMachines/BitmovinAnalyticsStateMachine.js +299 -0
- package/js/analyticsStateMachines/HTML5AnalyticsStateMachine.js +443 -0
- package/js/analyticsStateMachines/VideoJsAnalyticsStateMachine.js +503 -0
- package/js/cast/CastClient.js +50 -0
- package/js/cast/CastReceiver.js +37 -0
- package/js/core/AdapterFactory.js +41 -0
- package/js/core/Analytics.js +1357 -0
- package/js/core/AnalyticsStateMachineFactory.js +36 -0
- package/js/core/GumletInsightsExport.js +75 -0
- package/js/enums/CDNProviders.js +11 -0
- package/js/enums/Events.js +32 -0
- package/js/enums/GumletEnum.js +19 -0
- package/js/enums/MIMETypes.js +30 -0
- package/js/enums/Players.js +11 -0
- package/js/enums/StreamTypes.js +15 -0
- package/js/utils/EventsCall.js +22 -0
- package/js/utils/HttpCall.js +57 -0
- package/js/utils/LicenseCall.js +18 -0
- package/js/utils/Logger.js +40 -0
- package/js/utils/PlayerDetector.js +75 -0
- package/js/utils/PlayerInitCall.js +22 -0
- package/js/utils/SessionCreationCall.js +22 -0
- package/js/utils/Settings.js +3 -0
- package/js/utils/Utils.js +195 -0
- package/package.json +62 -1
- package/precommit.bash +8 -0
- package/tests/stage1.test.js +50 -0
- package/webpack.config.debug.js +34 -0
- package/webpack.config.js +40 -0
- package/webpack.config.release.js +62 -0
- package/gumlet-insights.min.js +0 -2
- package/gumlet-insights.min.js.LICENSE.txt +0 -10
|
@@ -0,0 +1,1357 @@
|
|
|
1
|
+
/* global __VERSION__ */
|
|
2
|
+
import LicenseCall from '../utils/LicenseCall';
|
|
3
|
+
import EventsCall from '../utils/EventsCall';
|
|
4
|
+
import SessionCreationCall from '../utils/SessionCreationCall';
|
|
5
|
+
import PlayerInitCall from '../utils/PlayerInitCall';
|
|
6
|
+
import Utils from '../utils/Utils';
|
|
7
|
+
import logger from '../utils/Logger';
|
|
8
|
+
import AdapterFactory from './AdapterFactory';
|
|
9
|
+
import AnalyticsStateMachineFactory from './AnalyticsStateMachineFactory';
|
|
10
|
+
import CastClient from '../cast/CastClient';
|
|
11
|
+
import CastReceiver from '../cast/CastReceiver';
|
|
12
|
+
import GumletEventEnum from '../enums/GumletEnum';
|
|
13
|
+
|
|
14
|
+
import {HTML5AnalyticsStateMachine} from '../analyticsStateMachines/HTML5AnalyticsStateMachine';
|
|
15
|
+
import {VideojsAnalyticsStateMachine} from '../analyticsStateMachines/VideoJsAnalyticsStateMachine';
|
|
16
|
+
|
|
17
|
+
import VideoJsAdapter from "../adapters/VideoJsAdapter";
|
|
18
|
+
import {HlsjsAdapter} from "../adapters/HlsjsAdapter";
|
|
19
|
+
import {DashjsAdapter} from "../adapters/DashjsAdapter";
|
|
20
|
+
import {HTML5Adapter} from "../adapters/HTML5Adapter";
|
|
21
|
+
import {ShakaAdapter} from "../adapters/ShakaAdapter";
|
|
22
|
+
|
|
23
|
+
class Analytics {
|
|
24
|
+
static PAGE_LOAD_TYPE = {
|
|
25
|
+
FOREGROUND: 1, BACKGROUND: 2
|
|
26
|
+
};
|
|
27
|
+
static LICENSE_CALL_PENDING_TIMEOUT = 200;
|
|
28
|
+
static PAGE_LOAD_TYPE_TIMEOUT = 200;
|
|
29
|
+
static CAST_RECEIVER_CONFIG_MESSAGE = 'CAST_RECEIVER_CONFIG_MESSAGE';
|
|
30
|
+
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.config = config;
|
|
33
|
+
|
|
34
|
+
// this.licenseCall = new LicenseCall();
|
|
35
|
+
this.analyticsCall = new EventsCall();
|
|
36
|
+
this.sessionCreationCall = new SessionCreationCall();
|
|
37
|
+
this.playerInitCall = new PlayerInitCall();
|
|
38
|
+
this.castClient = new CastClient();
|
|
39
|
+
this.castReceiver = new CastReceiver();
|
|
40
|
+
|
|
41
|
+
this.droppedSampleFrames = 0;
|
|
42
|
+
this.licensing = 'granted';
|
|
43
|
+
this.startupTime = 0;
|
|
44
|
+
this.pageLoadType = Analytics.PAGE_LOAD_TYPE.FOREGROUND;
|
|
45
|
+
|
|
46
|
+
this.autoplay = undefined;
|
|
47
|
+
|
|
48
|
+
this.isCastClient = false;
|
|
49
|
+
this.isCastReceiver = false;
|
|
50
|
+
this.isAllowedToSendSamples = false;
|
|
51
|
+
this.samplesQueue = [];
|
|
52
|
+
|
|
53
|
+
this.previousState = undefined;
|
|
54
|
+
this.previousStateTimeStamp = new Date();
|
|
55
|
+
|
|
56
|
+
this.firstPlayTimestamp = 0;
|
|
57
|
+
|
|
58
|
+
this.isMuted = false;
|
|
59
|
+
this.isFullScreen = undefined;
|
|
60
|
+
this.videoWidthPixels = undefined;
|
|
61
|
+
this.videoHeightPixels = undefined;
|
|
62
|
+
this.upscalePercentage = undefined;
|
|
63
|
+
this.downscalePercentage = undefined;
|
|
64
|
+
this.videoBitrate = undefined;
|
|
65
|
+
this.audioCodec = undefined;
|
|
66
|
+
this.videoCodec = undefined;
|
|
67
|
+
this.currentTime = 0;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
this.orientation = screen.orientation.type.match(/\w+/)[0];
|
|
71
|
+
screen.orientation.onchange = function (){
|
|
72
|
+
// logs 'portrait' or 'landscape'
|
|
73
|
+
this.orientation = screen.orientation.type.match(/\w+/)[0];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} catch (e) {
|
|
77
|
+
this.orientation = "undetected";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// this.setPageLoadType();
|
|
81
|
+
|
|
82
|
+
this.setConfigParameters();
|
|
83
|
+
this.init();
|
|
84
|
+
this.setupSample();
|
|
85
|
+
// this.sendAnalyticsSetupCall();
|
|
86
|
+
this.setupStateMachineCallbacks();
|
|
87
|
+
|
|
88
|
+
// Casting related settings ignored for now
|
|
89
|
+
|
|
90
|
+
// if (this.config.cast && this.config.cast.receiver) {
|
|
91
|
+
// this.isCastReceiver = true;
|
|
92
|
+
// this.castReceiver.setUp();
|
|
93
|
+
// this.castReceiver.setCallback((event) => {
|
|
94
|
+
// switch (event.type) {
|
|
95
|
+
// case Analytics.CAST_RECEIVER_CONFIG_MESSAGE:
|
|
96
|
+
// this.castClientConfig = event.data;
|
|
97
|
+
// this.updateSampleToCastClientConfig(this.sample, this.castClientConfig);
|
|
98
|
+
// this.updateSamplesToCastClientConfig(this.samplesQueue, event.data);
|
|
99
|
+
// this.isAllowedToSendSamples = true;
|
|
100
|
+
// break;
|
|
101
|
+
// }
|
|
102
|
+
// });
|
|
103
|
+
// }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// updateSamplesToCastClientConfig(samples, castClientConfig) {
|
|
107
|
+
// for (let i = 0; i < samples.length; i++) {
|
|
108
|
+
// this.updateSampleToCastClientConfig(samples[i], castClientConfig);
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
111
|
+
//
|
|
112
|
+
// updateSampleToCastClientConfig(sample, castClientConfig) {
|
|
113
|
+
// const {config, userId, impressionId, domain, path, language, userAgent} = castClientConfig;
|
|
114
|
+
// sample.impressionId = impressionId;
|
|
115
|
+
// sample.userId = userId;
|
|
116
|
+
// sample.userAgent = userAgent;
|
|
117
|
+
// sample.domain = domain;
|
|
118
|
+
// sample.path = path;
|
|
119
|
+
// sample.language = language;
|
|
120
|
+
//
|
|
121
|
+
// this.setConfigParameters(sample, config);
|
|
122
|
+
// }
|
|
123
|
+
|
|
124
|
+
// setPageLoadType() {
|
|
125
|
+
// window.setTimeout(() => {
|
|
126
|
+
// if (document[Utils.getHiddenProp()] === true) {
|
|
127
|
+
// this.pageLoadType = Analytics.PAGE_LOAD_TYPE.BACKGROUND;
|
|
128
|
+
// }
|
|
129
|
+
// }, Analytics.PAGE_LOAD_TYPE_TIMEOUT);
|
|
130
|
+
// this.pageURL = window.location.href;
|
|
131
|
+
// console.log(window.location.href)
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
init() {
|
|
135
|
+
if (!this.isCastReceiver && (this.config.property_id == '' || !Utils.validString(this.config.property_id))) {
|
|
136
|
+
console.error('Invalid analytics property_id provided');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
logger.setLogging(this.config.debug || false);
|
|
141
|
+
|
|
142
|
+
// if (!this.isCastReceiver) {
|
|
143
|
+
//this.checkLicensing(this.config.property_id);
|
|
144
|
+
// } else {
|
|
145
|
+
// this.licensing = 'granted';
|
|
146
|
+
// }
|
|
147
|
+
|
|
148
|
+
this.propertyId = this.config.property_id;
|
|
149
|
+
|
|
150
|
+
// if (typeof window === "window" && window)//(typeof window.parent.location !== "undefined")
|
|
151
|
+
if (typeof window !== "undefined" && typeof window.parent !== "undefined")
|
|
152
|
+
{
|
|
153
|
+
this.pageURL = (window.location != window.parent.location)
|
|
154
|
+
? document.referrer
|
|
155
|
+
: document.location.href ;
|
|
156
|
+
|
|
157
|
+
}else if(this.config.page_url){
|
|
158
|
+
this.pageURL = this.config.page_url;
|
|
159
|
+
}else{
|
|
160
|
+
this.pageURL = null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// this.setConfigParameters();
|
|
164
|
+
let test = false;
|
|
165
|
+
if (this.config.test) {
|
|
166
|
+
test = true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let overrideSessionID = null;
|
|
170
|
+
if (this.config.sessionID) {
|
|
171
|
+
overrideSessionID = this.config.sessionID;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let sendSessionRequest = true;
|
|
175
|
+
if (this.config.hasOwnProperty('sendSessionRequest')) {
|
|
176
|
+
sendSessionRequest = this.config.sendSessionRequest;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let overrideUserID = null;
|
|
180
|
+
if (this.config.userID) {
|
|
181
|
+
overrideUserID = this.config.userID;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
this.setUserId(test, overrideUserID);
|
|
185
|
+
this.setSessionId(test, overrideSessionID, sendSessionRequest);
|
|
186
|
+
this.setPlayerInstanceId();
|
|
187
|
+
this.setPlaybackId();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
setConfigParameters(sample = this.sample, config = this.config) {
|
|
191
|
+
// Random custom strings
|
|
192
|
+
this.customData1 = Utils.getCustomDataString(config.customData1);
|
|
193
|
+
this.customData2 = Utils.getCustomDataString(config.customData2);
|
|
194
|
+
this.customData3 = Utils.getCustomDataString(config.customData3);
|
|
195
|
+
this.customData4 = Utils.getCustomDataString(config.customData4);
|
|
196
|
+
this.customData5 = Utils.getCustomDataString(config.customData5);
|
|
197
|
+
this.customData6 = Utils.getCustomDataString(config.customData6);
|
|
198
|
+
this.customData7 = Utils.getCustomDataString(config.customData7);
|
|
199
|
+
this.customData8 = Utils.getCustomDataString(config.customData8);
|
|
200
|
+
this.customData9 = Utils.getCustomDataString(config.customData9);
|
|
201
|
+
this.customData10 = Utils.getCustomDataString(config.customData10);
|
|
202
|
+
|
|
203
|
+
// Player specific custom data
|
|
204
|
+
this.customPlayerIntegrationVersion = Utils.getCustomDataString(config.customPlayerIntegrationVersion);
|
|
205
|
+
this.customPlayerName = Utils.getCustomDataString(config.customPlayerName);
|
|
206
|
+
this.customPageType = Utils.getCustomDataString(config.customPageType);
|
|
207
|
+
|
|
208
|
+
// User specific custom data
|
|
209
|
+
this.customUserId = Utils.getCustomDataString(config.userId);
|
|
210
|
+
this.userName = Utils.getCustomDataString(config.userName);
|
|
211
|
+
this.userEMail = Utils.getCustomDataString(config.userEMail);
|
|
212
|
+
this.userPhone = Utils.getCustomDataString(config.userPhone);
|
|
213
|
+
this.userProfileImage = Utils.getCustomDataString(config.userProfileImage);
|
|
214
|
+
this.userAddressLine1 = Utils.getCustomDataString(config.userAddressLine1);
|
|
215
|
+
this.userAddressLine2 = Utils.getCustomDataString(config.userAddressLine2);
|
|
216
|
+
this.userCity = Utils.getCustomDataString(config.userCity);
|
|
217
|
+
this.userState = Utils.getCustomDataString(config.userState);
|
|
218
|
+
this.userCountry = Utils.getCustomDataString(config.userCountry);
|
|
219
|
+
this.userZipcode = Utils.getCustomDataString(config.userZipcode);
|
|
220
|
+
|
|
221
|
+
// Video specific custom data
|
|
222
|
+
this.customContentType = Utils.getCustomDataString(config.customContentType);
|
|
223
|
+
this.customVideoDurationMillis = Utils.getCustomDataString(config.customVideoDurationMillis);
|
|
224
|
+
this.customEncodingVariant = Utils.getCustomDataString(config.customEncodingVariant);
|
|
225
|
+
this.customVideoLanguage = Utils.getCustomDataString(config.customVideoLanguage);
|
|
226
|
+
this.customVideoId = Utils.getCustomDataString(config.customVideoId);
|
|
227
|
+
this.customVideoSeries = Utils.getCustomDataString(config.customVideoSeries);
|
|
228
|
+
this.customVideoProducer = Utils.getCustomDataString(config.customVideoProducer);
|
|
229
|
+
this.customVideoTitle = Utils.getCustomDataString(config.customVideoTitle);
|
|
230
|
+
this.customVideoVariantName = Utils.getCustomDataString(config.customVideoVariantName);
|
|
231
|
+
this.customVideoVariant = Utils.getCustomDataString(config.customVideoVariant);
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
this.SDKVersion = "1.0.0";
|
|
235
|
+
this.experimentName = config.experimentName;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
updateCustomUserData(config){
|
|
239
|
+
// User specific custom data
|
|
240
|
+
this.customUserId = Utils.getCustomDataString(config.userId);
|
|
241
|
+
this.userName = Utils.getCustomDataString(config.userName);
|
|
242
|
+
this.userEMail = Utils.getCustomDataString(config.userEMail);
|
|
243
|
+
this.userPhone = Utils.getCustomDataString(config.userPhone);
|
|
244
|
+
this.userProfileImage = Utils.getCustomDataString(config.userProfileImage);
|
|
245
|
+
this.userAddressLine1 = Utils.getCustomDataString(config.userAddressLine1);
|
|
246
|
+
this.userAddressLine2 = Utils.getCustomDataString(config.userAddressLine2);
|
|
247
|
+
this.userCity = Utils.getCustomDataString(config.userCity);
|
|
248
|
+
this.userState = Utils.getCustomDataString(config.userState);
|
|
249
|
+
this.userCountry = Utils.getCustomDataString(config.userCountry);
|
|
250
|
+
this.userZipcode = Utils.getCustomDataString(config.userZipcode);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
updateCustomVideoData(config){
|
|
254
|
+
// Video specific custom data
|
|
255
|
+
this.customContentType = Utils.getCustomDataString(config.customContentType);
|
|
256
|
+
this.customVideoDurationMillis = Utils.getCustomDataString(config.customVideoDurationMillis);
|
|
257
|
+
this.customEncodingVariant = Utils.getCustomDataString(config.customEncodingVariant);
|
|
258
|
+
this.customVideoLanguage = Utils.getCustomDataString(config.customVideoLanguage);
|
|
259
|
+
this.customVideoId = Utils.getCustomDataString(config.customVideoId);
|
|
260
|
+
this.customVideoSeries = Utils.getCustomDataString(config.customVideoSeries);
|
|
261
|
+
this.customVideoProducer = Utils.getCustomDataString(config.customVideoProducer);
|
|
262
|
+
this.customVideoTitle = Utils.getCustomDataString(config.customVideoTitle);
|
|
263
|
+
this.customVideoVariantName = Utils.getCustomDataString(config.customVideoVariantName);
|
|
264
|
+
this.customVideoVariant = Utils.getCustomDataString(config.customVideoVariant);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
updateCustomData(config){
|
|
268
|
+
this.customData1 = Utils.getCustomDataString(config.customData1);
|
|
269
|
+
this.customData2 = Utils.getCustomDataString(config.customData2);
|
|
270
|
+
this.customData3 = Utils.getCustomDataString(config.customData3);
|
|
271
|
+
this.customData4 = Utils.getCustomDataString(config.customData4);
|
|
272
|
+
this.customData5 = Utils.getCustomDataString(config.customData5);
|
|
273
|
+
this.customData6 = Utils.getCustomDataString(config.customData6);
|
|
274
|
+
this.customData7 = Utils.getCustomDataString(config.customData7);
|
|
275
|
+
this.customData8 = Utils.getCustomDataString(config.customData8);
|
|
276
|
+
this.customData9 = Utils.getCustomDataString(config.customData9);
|
|
277
|
+
this.customData10 = Utils.getCustomDataString(config.customData10);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
updateCustomPlayerData(config){
|
|
281
|
+
this.customPlayerIntegrationVersion = Utils.getCustomDataString(config.customPlayerIntegrationVersion);
|
|
282
|
+
this.customPlayerName = Utils.getCustomDataString(config.customPlayerName);
|
|
283
|
+
this.customPageType = Utils.getCustomDataString(config.customPageType);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
setSessionData() {
|
|
287
|
+
this.sessionData = {
|
|
288
|
+
session_id: this.sessionId,
|
|
289
|
+
property_id: this.propertyId,
|
|
290
|
+
user_id: this.userId,
|
|
291
|
+
custom_user_id: this.customUserId,
|
|
292
|
+
custom_data_1: this.customData1,
|
|
293
|
+
custom_data_2: this.customData2,
|
|
294
|
+
custom_data_3: this.customData3,
|
|
295
|
+
custom_data_4: this.customData4,
|
|
296
|
+
custom_data_5: this.customData5,
|
|
297
|
+
custom_data_6: this.customData6,
|
|
298
|
+
custom_data_7: this.customData7,
|
|
299
|
+
custom_data_8: this.customData8,
|
|
300
|
+
custom_data_9: this.customData9,
|
|
301
|
+
custom_data_10: this.customData10,
|
|
302
|
+
user_name: this.userName,
|
|
303
|
+
user_email: this.userEMail,
|
|
304
|
+
user_phone: this.userPhone,
|
|
305
|
+
user_profile_image: this.userProfileImage,
|
|
306
|
+
user_address_line1: this.userAddressLine1,
|
|
307
|
+
user_address_line2: this.userAddressLine2,
|
|
308
|
+
user_city: this.userCity,
|
|
309
|
+
user_state: this.userState,
|
|
310
|
+
user_country: this.userCountry,
|
|
311
|
+
user_zipcode: this.userZipcode,
|
|
312
|
+
viewer_client_version: this.SDKVersion,
|
|
313
|
+
meta_browser: this.meta_browser,
|
|
314
|
+
meta_device_manufacturer: this.meta_device_manufacturer,
|
|
315
|
+
meta_operating_system_version: this.meta_operating_system_version,
|
|
316
|
+
meta_operating_system: this.meta_operating_system,
|
|
317
|
+
meta_device_name: this.meta_device_name,
|
|
318
|
+
meta_browser_version: this.meta_browser_version,
|
|
319
|
+
meta_device_category: this.meta_device_category,
|
|
320
|
+
meta_device_architecture: this.meta_device_architecture,
|
|
321
|
+
meta_device_display_width: this.meta_device_display_width,
|
|
322
|
+
meta_device_display_height: this.meta_device_display_height,
|
|
323
|
+
meta_device_is_touchscreen: this.meta_device_is_touchscreen,
|
|
324
|
+
meta_device_display_dpr: this.meta_device_display_dpr
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (this.config.deviceData) {
|
|
328
|
+
this.sessionData.meta_device_name = this.config.deviceData.meta_device_name;
|
|
329
|
+
this.sessionData.meta_device_manufacturer = this.config.deviceData.meta_device_manufacturer;
|
|
330
|
+
this.sessionData.meta_operating_system_version = this.config.deviceData.meta_operating_system_version;
|
|
331
|
+
this.sessionData.meta_operating_system = this.config.deviceData.meta_operating_system;
|
|
332
|
+
this.sessionData.meta_browser = this.config.deviceData.meta_browser;
|
|
333
|
+
this.sessionData.meta_device_display_dpr = this.config.deviceData.meta_device_display_dpr;
|
|
334
|
+
this.sessionData.meta_browser_version = this.config.deviceData.meta_browser_version;
|
|
335
|
+
this.sessionData.meta_device_category = this.config.deviceData.meta_device_category;
|
|
336
|
+
this.sessionData.meta_device_architecture = this.config.deviceData.meta_device_architecture;
|
|
337
|
+
this.sessionData.meta_device_display_width = this.config.deviceData.meta_device_display_width;
|
|
338
|
+
this.sessionData.meta_device_display_height = this.config.deviceData.meta_device_display_height;
|
|
339
|
+
this.sessionData.meta_device_is_touchscreen = this.config.deviceData.meta_device_is_touchscreen;
|
|
340
|
+
}else{
|
|
341
|
+
this.sessionData.meta_device_display_width = window.screen.width;
|
|
342
|
+
this.sessionData.meta_device_display_height = window.screen.height;
|
|
343
|
+
this.sessionData.meta_device_display_dpr = parseInt(window.devicePixelRatio);
|
|
344
|
+
if ("ontouchstart" in document.documentElement){
|
|
345
|
+
this.sessionData.meta_device_is_touchscreen = "true";
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
setPlayerData(data=null) {
|
|
351
|
+
this.playerData = {
|
|
352
|
+
player_instance_id : this.playerInstanceId,
|
|
353
|
+
property_id : this.propertyId,
|
|
354
|
+
session_id : this.sessionId,
|
|
355
|
+
user_id : this.userId,
|
|
356
|
+
custom_user_id : this.customUserId,
|
|
357
|
+
custom_data_1 : this.customData1,
|
|
358
|
+
custom_data_2 : this.customData2,
|
|
359
|
+
custom_data_3 : this.customData3,
|
|
360
|
+
custom_data_4 : this.customData4,
|
|
361
|
+
custom_data_5 : this.customData5,
|
|
362
|
+
custom_data_6 : this.customData6,
|
|
363
|
+
custom_data_7 : this.customData7,
|
|
364
|
+
custom_data_8 : this.customData8,
|
|
365
|
+
custom_data_9 : this.customData9,
|
|
366
|
+
custom_data_10 : this.customData10,
|
|
367
|
+
player_integration_version : this.customPlayerIntegrationVersion,
|
|
368
|
+
meta_page_type : this.customPageType,
|
|
369
|
+
meta_page_url : this.pageURL,
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (this.config.deviceData) {
|
|
373
|
+
this.playerData.player_preload = this.config.playerData.player_preload;
|
|
374
|
+
this.playerData.player_autoplay = this.config.playerData.player_autoplay;
|
|
375
|
+
this.playerData.player_software_version = this.config.playerData.player_software_version;
|
|
376
|
+
this.playerData.player_integration_version = this.config.playerData.player_integration_version;
|
|
377
|
+
this.playerData.player_name = this.config.playerData.player_name;
|
|
378
|
+
this.playerData.player_language_code = this.config.playerData.player_language_code;
|
|
379
|
+
this.playerData.player_software = this.config.playerData.player_software;
|
|
380
|
+
this.playerData.meta_page_url = this.config.playerData.meta_page_url;
|
|
381
|
+
this.playerData.meta_page_type = this.config.playerData.meta_page_type;
|
|
382
|
+
this.playerData.player_height_pixels = this.config.playerData.player_height_pixels;
|
|
383
|
+
this.playerData.player_width_pixels = this.config.playerData.player_width_pixels;
|
|
384
|
+
}
|
|
385
|
+
// Player Height
|
|
386
|
+
if (data && Utils.validNumber(data.videoWindowHeight)) {
|
|
387
|
+
this.playerData.player_height_pixels = data.videoWindowHeight;
|
|
388
|
+
}
|
|
389
|
+
// Player width
|
|
390
|
+
if (data && Utils.validNumber(data.videoWindowWidth)) {
|
|
391
|
+
this.playerData.player_width_pixels = data.videoWindowWidth;
|
|
392
|
+
}
|
|
393
|
+
// Player is configured to autoplay
|
|
394
|
+
if (data && Utils.validBoolean(data.autoplay)) {
|
|
395
|
+
this.playerData.player_autoplay = data.autoplay;
|
|
396
|
+
}
|
|
397
|
+
// Player is configured to preload when page loads
|
|
398
|
+
if (data && Utils.validBoolean(data.preload)) {
|
|
399
|
+
this.playerData.player_preload = data.preload;
|
|
400
|
+
}
|
|
401
|
+
// Player software version
|
|
402
|
+
if (data && Utils.validString(data.version)) {
|
|
403
|
+
this.playerData.player_software_version = data.version;
|
|
404
|
+
}
|
|
405
|
+
// Player language
|
|
406
|
+
if (data && Utils.validString(data.audioLanguage)) {
|
|
407
|
+
this.playerData.player_language_code = data.audioLanguage;
|
|
408
|
+
}
|
|
409
|
+
// Player Software name
|
|
410
|
+
if (data && Utils.validString(data.playerSoftware)) {
|
|
411
|
+
this.playerData.player_software = data.playerSoftware;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
setUserId(test=false, override=null) {
|
|
416
|
+
if(override){
|
|
417
|
+
this.userId = override;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (test) {
|
|
421
|
+
this.userId = Utils.uuidv4();
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const userId = Utils.getCookie('gumlet_user_id');
|
|
425
|
+
if (!userId || userId === '') {
|
|
426
|
+
// let date = new Date();
|
|
427
|
+
// date.setTime(date.getTime() + (30*24*60*60*1000));
|
|
428
|
+
// document.cookie = 'gumlet_user_id=' + Utils.uuidv4()+'; expires='+date.toUTCString()+'; path=/';
|
|
429
|
+
// this.userId = Utils.getCookie('gumlet_user_id');
|
|
430
|
+
this.userId = Utils.setCookie('gumlet_user_id', 30*24*60);
|
|
431
|
+
} else {
|
|
432
|
+
this.userId = userId;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
setPlayerInstanceId() {
|
|
437
|
+
if(this.config.getUUID){
|
|
438
|
+
this.playerInstanceId = this.config.getUUID();
|
|
439
|
+
}else{
|
|
440
|
+
this.playerInstanceId = Utils.uuidv4();
|
|
441
|
+
}
|
|
442
|
+
this.setPlayerData();
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
setPlaybackId() {
|
|
446
|
+
if(this.config.getUUID){
|
|
447
|
+
this.playbackId = this.config.getUUID();
|
|
448
|
+
}else{
|
|
449
|
+
this.playbackId = Utils.uuidv4();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
setSessionId(test=false, override=null, sendSessionRequest=true) {
|
|
454
|
+
if (override) {
|
|
455
|
+
this.sessionId = override;
|
|
456
|
+
this.setSessionData();
|
|
457
|
+
if(sendSessionRequest){
|
|
458
|
+
this.sessionCreationCall.sendRequest(this.sessionData, Utils.noOp);
|
|
459
|
+
}
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (test) {
|
|
463
|
+
this.sessionId = Utils.uuidv4();
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const sessionId = Utils.getCookie('gumlet_session_id');
|
|
467
|
+
if (!sessionId || sessionId === '') {
|
|
468
|
+
// let date = new Date();
|
|
469
|
+
// date.setTime(date.getTime() + (30*60*1000));
|
|
470
|
+
// document.cookie = 'gumlet_session_id=' + Utils.uuidv4()+'; expires='+date.toUTCString()+'; path=/';
|
|
471
|
+
this.sessionId = Utils.setCookie('gumlet_session_id', 30);
|
|
472
|
+
this.setSessionData();
|
|
473
|
+
// Call Analytics API to create session.
|
|
474
|
+
this.sessionCreationCall.sendRequest(this.sessionData, Utils.noOp);
|
|
475
|
+
} else {
|
|
476
|
+
this.sessionId = sessionId;
|
|
477
|
+
this.setSessionData();
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
sendAnalyticsSetupCall() {
|
|
482
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.SETUP, {millis_from_previous_event: 0});
|
|
483
|
+
this.setState(GumletEventEnum.SETUP);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
getMillisFromPreviousState(){
|
|
487
|
+
let currentTime = new Date();
|
|
488
|
+
return currentTime.getTime() - this.previousStateTimeStamp.getTime();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
setVideoData(data){
|
|
492
|
+
if (data && Utils.validNumber(data.duration)) {
|
|
493
|
+
this.videoDuration = Utils.calculateTime(data.duration);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// for web i.e. from statemachines
|
|
497
|
+
if (data && Utils.validString(data.streamType)) {
|
|
498
|
+
this.videoSourceType = data.streamType;
|
|
499
|
+
if (data.streamType === "dash" && Utils.validString(data.mpdUrl)) {
|
|
500
|
+
this.videoSourceUrl = data.mpdUrl;
|
|
501
|
+
this.videoSourceHostname = (new URL(this.videoSourceUrl)).hostname;
|
|
502
|
+
}else if (data.streamType === "hls" && Utils.validString(data.m3u8Url)) {
|
|
503
|
+
this.videoSourceUrl = data.m3u8Url;
|
|
504
|
+
this.videoSourceHostname = (new URL(this.videoSourceUrl)).hostname;
|
|
505
|
+
}
|
|
506
|
+
else if (data.streamType === "hls" && Utils.validString(data.streamUrl)) {
|
|
507
|
+
this.videoSourceUrl = data.streamUrl;
|
|
508
|
+
this.videoSourceHostname = (new URL(this.videoSourceUrl)).hostname;
|
|
509
|
+
}
|
|
510
|
+
else if (data.streamType === "progressive" && Utils.validString(data.progUrl)) {
|
|
511
|
+
this.videoSourceUrl = data.progUrl;
|
|
512
|
+
this.videoSourceHostname = (new URL(this.videoSourceUrl)).hostname;
|
|
513
|
+
}else if(data && data.streamUrl){
|
|
514
|
+
this.videoSourceUrl = data.streamUrl;
|
|
515
|
+
this.videoSourceHostname = (new URL(this.videoSourceUrl)).hostname;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// override from react native SDK
|
|
520
|
+
if (data && data.streamUrl) {
|
|
521
|
+
this.videoSourceUrl = data.streamUrl;
|
|
522
|
+
}
|
|
523
|
+
if (data && data.sourceHostName) {
|
|
524
|
+
this.videoSourceHostname = data.sourceHostName;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (data && data.hasOwnProperty('muted')) {
|
|
528
|
+
this.isMuted = data.muted;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (data && data.currentVideoData && Utils.validNumber(data.currentVideoData.height) && data.currentVideoData.height > 0) {
|
|
532
|
+
this.videoHeightPixels = data.currentVideoData.height;
|
|
533
|
+
}
|
|
534
|
+
if (data && data.currentVideoData && Utils.validNumber(data.currentVideoData.width) && data.currentVideoData.width > 0) {
|
|
535
|
+
this.videoWidthPixels = data.currentVideoData.width;
|
|
536
|
+
}
|
|
537
|
+
if (data && data.currentVideoData && Utils.validNumber(data.currentVideoData.bitrate) && data.currentVideoData.bitrate > -1) {
|
|
538
|
+
// player gives the bbitrate in bits per second covert to normalised unit across all SDK to megabit per second
|
|
539
|
+
this.videoBitrate = data.currentVideoData.bitrate/1000000;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (data && data.currentVideoData && Utils.validString(data.currentVideoData.audioCodec) && data.currentVideoData.audioCodec.length > 0) {
|
|
543
|
+
this.audioCodec = data.currentVideoData.audioCodec;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (data && data.currentVideoData && Utils.validString(data.currentVideoData.videoCodec) && data.currentVideoData.videoCodec.length > 0) {
|
|
547
|
+
this.videoCodec = data.currentVideoData.videoCodec;
|
|
548
|
+
}
|
|
549
|
+
// calculate scaling if both videowidth and player width are there
|
|
550
|
+
let scaling = 0;
|
|
551
|
+
if (this.videoWidthPixels && this.playerData.player_width_pixels) {
|
|
552
|
+
scaling = (this.playerData.player_width_pixels - this.videoWidthPixels)/this.videoWidthPixels
|
|
553
|
+
}else {
|
|
554
|
+
this.upscalePercentage = undefined;
|
|
555
|
+
this.downscalePercentage = undefined;
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (scaling > 0) {
|
|
560
|
+
this.upscalePercentage = scaling*100;
|
|
561
|
+
this.downscalePercentage = 0;
|
|
562
|
+
}else if (scaling < 0) {
|
|
563
|
+
this.upscalePercentage = 0;
|
|
564
|
+
this.downscalePercentage = scaling*100*(-1);
|
|
565
|
+
}else {
|
|
566
|
+
this.upscalePercentage = 0;
|
|
567
|
+
this.downscalePercentage = 0;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const parsedURL = new URL(this.videoSourceUrl);
|
|
571
|
+
if(parsedURL.hostname === "video.gumlet.io" && !this.customVideoId){
|
|
572
|
+
this.customVideoId = parsedURL.pathname.split("/")[2];
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
setupStateMachineCallbacks() {
|
|
577
|
+
this.stateMachineCallbacks = {
|
|
578
|
+
// All of these are called in the onLeaveState Method.
|
|
579
|
+
// So it's the last sample
|
|
580
|
+
setup: (time, state, event) => {
|
|
581
|
+
// if (!this.isCastReceiver) {
|
|
582
|
+
// this.sample.impressionId = Utils.uuidv4();
|
|
583
|
+
// }
|
|
584
|
+
logger.log('Setup Gumlet analytics ' + this.analyticsVersion);
|
|
585
|
+
this.setDuration(time);
|
|
586
|
+
// this.sample.playerStartupTime = time;
|
|
587
|
+
// this.sample.pageLoadType = this.pageLoadType;
|
|
588
|
+
|
|
589
|
+
// if (window.performance && window.performance.timing) {
|
|
590
|
+
// const loadTime = Utils.getCurrentTimestamp() - window.performance.timing.navigationStart;
|
|
591
|
+
// this.sample.pageLoadTime = loadTime;
|
|
592
|
+
// logger.log('Page loaded in ' + loadTime + 'ms');
|
|
593
|
+
// }
|
|
594
|
+
this.setVideoData(event);
|
|
595
|
+
|
|
596
|
+
// this.setPlaybackSettingsFromLoadedEvent(event);
|
|
597
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.SETUP, {millis_from_previous_event: 0});
|
|
598
|
+
this.setState(GumletEventEnum.SETUP);
|
|
599
|
+
// this.sample.pageLoadType = this.pageLoadType;
|
|
600
|
+
// this.sample.pageLoadTime = 0;
|
|
601
|
+
},
|
|
602
|
+
|
|
603
|
+
// ready: Utils.noOp,
|
|
604
|
+
ready: (time, state, event) => {
|
|
605
|
+
this.setDuration(time);
|
|
606
|
+
this.setVideoData(event);
|
|
607
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
608
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAYER_READY);
|
|
609
|
+
this.setState(GumletEventEnum.PLAYER_READY);
|
|
610
|
+
// Make player instance call as data is recieved here for player
|
|
611
|
+
this.setPlayerData(event);
|
|
612
|
+
this.playerInitCall.sendRequest(this.playerData, Utils.noOp);
|
|
613
|
+
},
|
|
614
|
+
|
|
615
|
+
loaded: (time, state, event, latency=null) => {
|
|
616
|
+
this.setDuration(time);
|
|
617
|
+
this.setVideoData(event);
|
|
618
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
619
|
+
let overridePayload = {};
|
|
620
|
+
if (latency !== null) {
|
|
621
|
+
overridePayload = {millis_from_previous_event: latency, previous_event: GumletEventEnum.PLAYER_READY};
|
|
622
|
+
}
|
|
623
|
+
// Override millis from previous event and previous event to preserve event flow in case of
|
|
624
|
+
// HTML5 player where they are not preloaded/autoplayed and the video gets laoded after play button is clicked
|
|
625
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAYBACK_READY, overridePayload);
|
|
626
|
+
if (latency === null) {
|
|
627
|
+
// don't set playback ready event in state as it causes state flow mismatch if
|
|
628
|
+
// HTML5 player are not loaded on pageload as video source gets loaded after play button is clicked
|
|
629
|
+
this.setState(GumletEventEnum.PLAYBACK_READY);
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
|
|
633
|
+
startup: (time, state) => {
|
|
634
|
+
this.setDuration(time);
|
|
635
|
+
// this.sample.videoStartupTime = time;
|
|
636
|
+
// this.setState(state);
|
|
637
|
+
|
|
638
|
+
// this.startupTime += time;
|
|
639
|
+
// this.sample.startupTime = this.startupTime;
|
|
640
|
+
// this.sample.autoplay = this.autoplay;
|
|
641
|
+
|
|
642
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
643
|
+
// this.sample.autoplay = undefined;
|
|
644
|
+
},
|
|
645
|
+
'first_play': (time, state, event) => {
|
|
646
|
+
this.setDuration(time);
|
|
647
|
+
this.setVideoData(event);
|
|
648
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
649
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAY);
|
|
650
|
+
this.setState(GumletEventEnum.PLAY);
|
|
651
|
+
this.firstPlayTimestamp = new Date();
|
|
652
|
+
// Make a call for event_playbackStarted as well
|
|
653
|
+
},
|
|
654
|
+
play: (time, state, event) => {
|
|
655
|
+
this.setDuration(time);
|
|
656
|
+
this.setVideoData(event);
|
|
657
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
658
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAY);
|
|
659
|
+
this.setState(GumletEventEnum.PLAY);
|
|
660
|
+
},
|
|
661
|
+
|
|
662
|
+
updateSample: (playbackSettings) => {
|
|
663
|
+
this.setPlaybackSettingsFromLoadedEvent(playbackSettings);
|
|
664
|
+
},
|
|
665
|
+
|
|
666
|
+
playing: (time, state, event) => {
|
|
667
|
+
this.setDuration(time);
|
|
668
|
+
this.setVideoData(event);
|
|
669
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
670
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAYING);
|
|
671
|
+
this.setState(GumletEventEnum.PLAYING);
|
|
672
|
+
|
|
673
|
+
// this.setDuration(time);
|
|
674
|
+
// this.setState(state);
|
|
675
|
+
// this.sample.played = time;
|
|
676
|
+
//
|
|
677
|
+
// this.setDroppedFrames(event);
|
|
678
|
+
//
|
|
679
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
680
|
+
},
|
|
681
|
+
|
|
682
|
+
playback_started: (time, state, event) => {
|
|
683
|
+
this.setDuration(time);
|
|
684
|
+
this.setVideoData(event);
|
|
685
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
686
|
+
let currentTime = new Date();
|
|
687
|
+
let latency = currentTime.getTime() - this.firstPlayTimestamp.getTime();
|
|
688
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAYBACK_STARTED, {millis_from_previous_event: latency});
|
|
689
|
+
this.setState(GumletEventEnum.PLAYBACK_STARTED);
|
|
690
|
+
|
|
691
|
+
// this.setDuration(time);
|
|
692
|
+
// this.setState(state);
|
|
693
|
+
// this.sample.played = time;
|
|
694
|
+
//
|
|
695
|
+
// this.setDroppedFrames(event);
|
|
696
|
+
//
|
|
697
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
698
|
+
},
|
|
699
|
+
|
|
700
|
+
playingAndBye: (time, state, event) => {
|
|
701
|
+
this.setDuration(time);
|
|
702
|
+
// this.setState(state);
|
|
703
|
+
// this.sample.played = time;
|
|
704
|
+
|
|
705
|
+
this.setDroppedFrames(event);
|
|
706
|
+
|
|
707
|
+
this.sendUnloadRequest();
|
|
708
|
+
},
|
|
709
|
+
|
|
710
|
+
heartbeat: (time, state, event) => {
|
|
711
|
+
// this.setDroppedFrames(event);
|
|
712
|
+
// this.setState(state);
|
|
713
|
+
this.setDuration(time);
|
|
714
|
+
this.setVideoData(event);
|
|
715
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
716
|
+
// this.sample.played = this.sample.duration;
|
|
717
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
718
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAYBACK_UPDATE);
|
|
719
|
+
this.setState(GumletEventEnum.PLAYBACK_UPDATE);
|
|
720
|
+
},
|
|
721
|
+
|
|
722
|
+
qualitychange: (time, state) => {
|
|
723
|
+
this.setDuration(time);
|
|
724
|
+
// this.setState(state);
|
|
725
|
+
|
|
726
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
727
|
+
},
|
|
728
|
+
|
|
729
|
+
'qualitychange_pause': (time, state) => {
|
|
730
|
+
this.setDuration(time);
|
|
731
|
+
// this.setState(state);
|
|
732
|
+
|
|
733
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
734
|
+
},
|
|
735
|
+
|
|
736
|
+
'qualitychange_rebuffering': (time, state) => {
|
|
737
|
+
this.setDuration(time);
|
|
738
|
+
// this.setState(state);
|
|
739
|
+
|
|
740
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
741
|
+
},
|
|
742
|
+
|
|
743
|
+
videoChange: (event) => {
|
|
744
|
+
this.stateMachineCallbacks.setVideoTimeEndFromEvent(event);
|
|
745
|
+
this.stateMachineCallbacks.setVideoTimeStartFromEvent(event);
|
|
746
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
747
|
+
// this.setPlaybackVideoPropertiesFromEvent(event);
|
|
748
|
+
},
|
|
749
|
+
|
|
750
|
+
audioChange: (event) => {
|
|
751
|
+
this.stateMachineCallbacks.setVideoTimeEndFromEvent(event);
|
|
752
|
+
this.stateMachineCallbacks.setVideoTimeStartFromEvent(event);
|
|
753
|
+
// this.sample.audioBitrate = event.bitrate;
|
|
754
|
+
},
|
|
755
|
+
|
|
756
|
+
pause: (time, state, event) => {
|
|
757
|
+
this.setDuration(time);
|
|
758
|
+
this.setVideoData(event);
|
|
759
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
760
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PAUSE);
|
|
761
|
+
this.setState(GumletEventEnum.PAUSE);
|
|
762
|
+
|
|
763
|
+
// this.setDuration(time);
|
|
764
|
+
// this.setState(state);
|
|
765
|
+
//
|
|
766
|
+
// this.sample.paused = time;
|
|
767
|
+
//
|
|
768
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
769
|
+
},
|
|
770
|
+
'start_rebuffer': (time, state, event, test=false) => {
|
|
771
|
+
this.setDuration(time);
|
|
772
|
+
this.setVideoData(event);
|
|
773
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
774
|
+
if (!test) {
|
|
775
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.START_REBUFFER);
|
|
776
|
+
}
|
|
777
|
+
this.setState(GumletEventEnum.START_REBUFFER);
|
|
778
|
+
|
|
779
|
+
// this.setDuration(time);
|
|
780
|
+
// this.setState(state);
|
|
781
|
+
//
|
|
782
|
+
// this.sample.paused = time;
|
|
783
|
+
//
|
|
784
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
785
|
+
},
|
|
786
|
+
'end_rebuffer': (time, state, event, test=false) => {
|
|
787
|
+
this.setDuration(time);
|
|
788
|
+
this.setVideoData(event);
|
|
789
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
790
|
+
if (!test) {
|
|
791
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.END_REBUFFER);
|
|
792
|
+
}else {
|
|
793
|
+
return this.getSample(GumletEventEnum.END_REBUFFER);
|
|
794
|
+
}
|
|
795
|
+
this.setState(GumletEventEnum.END_REBUFFER);
|
|
796
|
+
|
|
797
|
+
// this.setDuration(time);
|
|
798
|
+
// this.setState(state);
|
|
799
|
+
//
|
|
800
|
+
// this.sample.paused = time;
|
|
801
|
+
//
|
|
802
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
803
|
+
},
|
|
804
|
+
'playback_seeked': (seekedFrom, seekedTo, seekLatency, toEvent) => {
|
|
805
|
+
// call seeked event
|
|
806
|
+
// this.setVideoData(event);
|
|
807
|
+
// this.setPlaybackSettingsFromLoadedEvent(event);
|
|
808
|
+
|
|
809
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.SEEKED, {from:seekedFrom, to:seekedTo});
|
|
810
|
+
this.setState(GumletEventEnum.SEEKED);
|
|
811
|
+
// Setup the sample again as additional data was passed to the sample which needs to be removed
|
|
812
|
+
this.setupSample();
|
|
813
|
+
// Call event after seek with latency
|
|
814
|
+
if (toEvent === 'PAUSE') {
|
|
815
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PAUSE, {millis_from_previous_event: seekLatency});
|
|
816
|
+
this.setState(GumletEventEnum.PAUSE);
|
|
817
|
+
}else if (toEvent === 'PLAYING') {
|
|
818
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.PLAYING, {millis_from_previous_event: seekLatency});
|
|
819
|
+
this.setState(GumletEventEnum.PLAYING);
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
|
|
823
|
+
'paused_seeking': (time, state, event) => {
|
|
824
|
+
this.setDuration(time);
|
|
825
|
+
// this.setState(state);
|
|
826
|
+
|
|
827
|
+
// this.sample.seeked = time;
|
|
828
|
+
|
|
829
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
830
|
+
},
|
|
831
|
+
|
|
832
|
+
'play_seeking': Utils.noOp,
|
|
833
|
+
|
|
834
|
+
'end_play_seeking': (time, state, event) => {
|
|
835
|
+
// this.setState(state);
|
|
836
|
+
this.setDuration(time);
|
|
837
|
+
|
|
838
|
+
// this.sample.seeked = time;
|
|
839
|
+
|
|
840
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
841
|
+
},
|
|
842
|
+
|
|
843
|
+
rebuffering: (time, state, event) => {
|
|
844
|
+
this.setDuration(time);
|
|
845
|
+
// this.setState(state);
|
|
846
|
+
|
|
847
|
+
// this.sample.buffered = time;
|
|
848
|
+
|
|
849
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
850
|
+
},
|
|
851
|
+
|
|
852
|
+
error: (event) => {
|
|
853
|
+
this.stateMachineCallbacks.setVideoTimeEndFromEvent(event);
|
|
854
|
+
this.stateMachineCallbacks.setVideoTimeStartFromEvent(event);
|
|
855
|
+
|
|
856
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.ERROR, {error_code:event.code, error:event.message});
|
|
857
|
+
this.setState(GumletEventEnum.ERROR);
|
|
858
|
+
// Setup the sample again as additional data was passed to the sample which needs to be removed
|
|
859
|
+
this.setupSample();
|
|
860
|
+
},
|
|
861
|
+
|
|
862
|
+
end: (time, state, event) => {
|
|
863
|
+
// this.sample.impressionId = Utils.uuidv4();
|
|
864
|
+
this.setPlaybackId();
|
|
865
|
+
this.setDuration(time);
|
|
866
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.END);
|
|
867
|
+
this.setState(GumletEventEnum.END);
|
|
868
|
+
},
|
|
869
|
+
|
|
870
|
+
ad: (time, state, event) => {
|
|
871
|
+
this.setDuration(time);
|
|
872
|
+
// this.setState(state);
|
|
873
|
+
// this.sample.ad = time;
|
|
874
|
+
|
|
875
|
+
this.setDroppedFrames(event);
|
|
876
|
+
|
|
877
|
+
// this.sendAnalyticsRequestAndClearValues();
|
|
878
|
+
},
|
|
879
|
+
|
|
880
|
+
mute: (time, event) => {
|
|
881
|
+
this.isMuted = true;
|
|
882
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
883
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.MUTE);
|
|
884
|
+
},
|
|
885
|
+
|
|
886
|
+
unMute: (time, event) => {
|
|
887
|
+
this.isMuted = false;
|
|
888
|
+
this.setPlaybackSettingsFromLoadedEvent(event);
|
|
889
|
+
this.sendAnalyticsRequestAndClearValues(GumletEventEnum.UNMUTE);
|
|
890
|
+
},
|
|
891
|
+
|
|
892
|
+
muting_ready: Utils.noOp,
|
|
893
|
+
muting_play: Utils.noOp,
|
|
894
|
+
muting_pause: Utils.noOp,
|
|
895
|
+
|
|
896
|
+
setVideoTimeEndFromEvent: (event) => {
|
|
897
|
+
// if (Utils.validNumber(event.currentTime)) {
|
|
898
|
+
// this.sample.videoTimeEnd = Utils.calculateTime(event.currentTime);
|
|
899
|
+
// }
|
|
900
|
+
},
|
|
901
|
+
|
|
902
|
+
setVideoTimeStartFromEvent: (event) => {
|
|
903
|
+
// if (Utils.validNumber(event.currentTime)) {
|
|
904
|
+
// this.sample.videoTimeStart = Utils.calculateTime(event.currentTime);
|
|
905
|
+
// }
|
|
906
|
+
},
|
|
907
|
+
|
|
908
|
+
startCasting: (timestamp, event) => {
|
|
909
|
+
if (event && event.resuming) {
|
|
910
|
+
this.isAllowedToSendSamples = false;
|
|
911
|
+
logger.warning('Player started casting but a session is already casting!');
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
this.isCastClient = true;
|
|
916
|
+
this.isAllowedToSendSamples = false;
|
|
917
|
+
|
|
918
|
+
const {domain, path, language, userAgent, userId, impressionId} = this.sample;
|
|
919
|
+
const castStartMessage = {
|
|
920
|
+
type: Analytics.CAST_RECEIVER_CONFIG_MESSAGE,
|
|
921
|
+
data: {
|
|
922
|
+
config: this.config,
|
|
923
|
+
userId,
|
|
924
|
+
domain,
|
|
925
|
+
path,
|
|
926
|
+
language,
|
|
927
|
+
userAgent,
|
|
928
|
+
impressionId
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
this.castClient.setUp();
|
|
933
|
+
this.castClient.sendMessage(castStartMessage);
|
|
934
|
+
},
|
|
935
|
+
|
|
936
|
+
casting: () => {
|
|
937
|
+
this.isCastClient = false;
|
|
938
|
+
this.samplesQueue = [];
|
|
939
|
+
this.isAllowedToSendSamples = true;
|
|
940
|
+
},
|
|
941
|
+
|
|
942
|
+
source_changing: () => {
|
|
943
|
+
// this.sample.impressionId = Utils.uuidv4();
|
|
944
|
+
},
|
|
945
|
+
|
|
946
|
+
resetSessionExpiry: () => {
|
|
947
|
+
if (this.config.test) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
if (this.config.sessionID) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
Utils.setCookie('gumlet_session_id', 30, this.sessionId);
|
|
956
|
+
Utils.setCookie('gumlet_user_id', 30*24*60, this.userId);
|
|
957
|
+
// const sessionId = Utils.getCookie('gumlet_session_id');
|
|
958
|
+
// if (!sessionId || sessionId === '') {
|
|
959
|
+
// this.setSessionId(test);
|
|
960
|
+
// }else {
|
|
961
|
+
// let date = new Date();
|
|
962
|
+
// date.setTime(date.getTime() + (30*60*1000));
|
|
963
|
+
// if(typeof window === "window" && window)
|
|
964
|
+
// {
|
|
965
|
+
// document.cookie = 'gumlet_session_id=' + sessionId+'; expires='+date.toUTCString()+'; path=/';
|
|
966
|
+
// }
|
|
967
|
+
// else{
|
|
968
|
+
// let gumlet_session_id = 'gumlet_session_id=' + sessionId+'; expires='+date.toUTCString()+'; path=/';
|
|
969
|
+
// }
|
|
970
|
+
|
|
971
|
+
// }
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
register = (player, opts = {}) => {
|
|
977
|
+
if (!player) {
|
|
978
|
+
this.analyticsStateMachine = new HTML5AnalyticsStateMachine(this.stateMachineCallbacks, opts);
|
|
979
|
+
return this.analyticsStateMachine;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
if (!opts.starttime) {
|
|
983
|
+
opts.starttime = Utils.getCurrentTimestamp();
|
|
984
|
+
}
|
|
985
|
+
this.analyticsStateMachine = AnalyticsStateMachineFactory.getAnalyticsStateMachine(player, this.stateMachineCallbacks, opts);
|
|
986
|
+
this.adapter = AdapterFactory.getAdapter(player, this.record, this.analyticsStateMachine, opts.mediaElement);
|
|
987
|
+
if (!this.adapter) {
|
|
988
|
+
logger.error('Could not detect player.');
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
registerVideoJSPlayer = (player, opts = {}) => {
|
|
994
|
+
if (!opts.starttime) {
|
|
995
|
+
opts.starttime = Utils.getCurrentTimestamp();
|
|
996
|
+
}
|
|
997
|
+
this.analyticsStateMachine = new VideojsAnalyticsStateMachine(this.stateMachineCallbacks, opts);
|
|
998
|
+
this.adapter = new VideoJsAdapter(player, this.record, this.analyticsStateMachine);
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
registerHLSJSPlayer = (player, opts = {}) => {
|
|
1002
|
+
if (!opts.starttime) {
|
|
1003
|
+
opts.starttime = Utils.getCurrentTimestamp();
|
|
1004
|
+
}
|
|
1005
|
+
this.analyticsStateMachine = new HTML5AnalyticsStateMachine(this.stateMachineCallbacks, opts);
|
|
1006
|
+
this.adapter = new HlsjsAdapter(player, this.record, this.analyticsStateMachine);
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
registerShakaPlayer = (player, opts = {}) => {
|
|
1010
|
+
if (!opts.starttime) {
|
|
1011
|
+
opts.starttime = Utils.getCurrentTimestamp();
|
|
1012
|
+
}
|
|
1013
|
+
this.analyticsStateMachine = new HTML5AnalyticsStateMachine(this.stateMachineCallbacks, opts);
|
|
1014
|
+
this.adapter = new ShakaAdapter(player, this.record, this.analyticsStateMachine, opts.mediaElement);
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
registerHTML5Player = (player, opts = {}) => {
|
|
1018
|
+
if (!opts.starttime) {
|
|
1019
|
+
opts.starttime = Utils.getCurrentTimestamp();
|
|
1020
|
+
}
|
|
1021
|
+
this.analyticsStateMachine = new HTML5AnalyticsStateMachine(this.stateMachineCallbacks, opts);
|
|
1022
|
+
this.adapter = new HTML5Adapter(player, this.record, this.analyticsStateMachine);
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
registerDashJSPlayer = (player, opts = {}) => {
|
|
1026
|
+
if (!opts.starttime) {
|
|
1027
|
+
opts.starttime = Utils.getCurrentTimestamp();
|
|
1028
|
+
}
|
|
1029
|
+
this.analyticsStateMachine = new HTML5AnalyticsStateMachine(this.stateMachineCallbacks, opts);
|
|
1030
|
+
this.adapter = new DashjsAdapter(player, this.record, this.analyticsStateMachine);
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
registerReactNativeVideoPlayer = (opts) => {
|
|
1034
|
+
if (!opts.starttime) {
|
|
1035
|
+
opts.starttime = Utils.getCurrentTimestamp();
|
|
1036
|
+
}
|
|
1037
|
+
this.analyticsStateMachine = new HTML5AnalyticsStateMachine(this.stateMachineCallbacks, opts);
|
|
1038
|
+
return this.analyticsStateMachine;
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
getCurrentImpressionId = () => {
|
|
1042
|
+
return this.sample.impressionId;
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
record = (eventType, eventObject) => {
|
|
1046
|
+
eventObject = eventObject || {};
|
|
1047
|
+
|
|
1048
|
+
this.analyticsStateMachine.callEvent(eventType, eventObject, Utils.getCurrentTimestamp());
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
setDuration(duration) {
|
|
1052
|
+
// this.sample.duration = duration;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
setState(state=undefined) {
|
|
1056
|
+
if (state) {
|
|
1057
|
+
this.previousState = state;
|
|
1058
|
+
this.previousStateTimeStamp = new Date();
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// setPlaybackVideoPropertiesFromEvent(event) {
|
|
1063
|
+
// if (Utils.validNumber(event.width)) {
|
|
1064
|
+
// this.sample.videoPlaybackWidth = event.width;
|
|
1065
|
+
// }
|
|
1066
|
+
// if (Utils.validNumber(event.height)) {
|
|
1067
|
+
// this.sample.videoPlaybackHeight = event.height;
|
|
1068
|
+
// }
|
|
1069
|
+
// if (Utils.validNumber(event.bitrate)) {
|
|
1070
|
+
// this.videoBitrate = event.bitrate;
|
|
1071
|
+
// }
|
|
1072
|
+
// }
|
|
1073
|
+
|
|
1074
|
+
setDroppedFrames = (event) => {
|
|
1075
|
+
// if (Utils.validNumber(event.droppedFrames)) {
|
|
1076
|
+
// this.sample.droppedFrames = 0;
|
|
1077
|
+
// }
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
setPlaybackSettingsFromLoadedEvent(loadedEvent) {
|
|
1081
|
+
if (loadedEvent && Utils.validNumber(loadedEvent.currentTime)) {
|
|
1082
|
+
this.currentTime = Utils.calculateTime(loadedEvent.currentTime);
|
|
1083
|
+
}
|
|
1084
|
+
if (loadedEvent && Utils.validBoolean(loadedEvent.isFullScreen)) {
|
|
1085
|
+
this.isFullScreen = loadedEvent.isFullScreen;
|
|
1086
|
+
}
|
|
1087
|
+
if (loadedEvent && Utils.validBoolean(loadedEvent.isCasting)) {
|
|
1088
|
+
this.isCasting = loadedEvent.isCasting;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
// if (Utils.validBoolean(loadedEvent.isLive)) {
|
|
1093
|
+
// this.sample.isLive = loadedEvent.isLive;
|
|
1094
|
+
// }
|
|
1095
|
+
// if (Utils.validString(loadedEvent.version)) {
|
|
1096
|
+
// this.sample.version = this.sample.player + '-' + loadedEvent.version;
|
|
1097
|
+
// }
|
|
1098
|
+
// if (Utils.validString(loadedEvent.type)) {
|
|
1099
|
+
// this.sample.playerTech = loadedEvent.type;
|
|
1100
|
+
// }
|
|
1101
|
+
// if (Utils.validString(loadedEvent.streamType)) {
|
|
1102
|
+
// this.sample.streamFormat = loadedEvent.streamType;
|
|
1103
|
+
// }
|
|
1104
|
+
// if (Utils.validString(loadedEvent.mpdUrl)) {
|
|
1105
|
+
// this.sample.mpdUrl = loadedEvent.mpdUrl;
|
|
1106
|
+
// }
|
|
1107
|
+
// if (Utils.validString(loadedEvent.m3u8Url)) {
|
|
1108
|
+
// this.sample.m3u8Url = loadedEvent.m3u8Url;
|
|
1109
|
+
// }
|
|
1110
|
+
// if (Utils.validString(loadedEvent.progUrl)) {
|
|
1111
|
+
// this.sample.progUrl = loadedEvent.progUrl;
|
|
1112
|
+
// }
|
|
1113
|
+
// if (Utils.validNumber(loadedEvent.videoWindowHeight)) {
|
|
1114
|
+
// this.sample.videoWindowHeight = loadedEvent.videoWindowHeight;
|
|
1115
|
+
// }
|
|
1116
|
+
// if (Utils.validBoolean(loadedEvent.isMuted)) {
|
|
1117
|
+
// this.isMuted = loadedEvent.isMuted;
|
|
1118
|
+
// }
|
|
1119
|
+
// if (Utils.validBoolean(loadedEvent.autoplay)) {
|
|
1120
|
+
// this.autoplay = loadedEvent.autoplay;
|
|
1121
|
+
// }
|
|
1122
|
+
//
|
|
1123
|
+
// if (this.sample.streamFormat === 'progressive') {
|
|
1124
|
+
// this.videoBitrate = loadedEvent.progBitrate;
|
|
1125
|
+
// }
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
setupSample() {
|
|
1129
|
+
// Base data that is sent to all events API call
|
|
1130
|
+
this.sample = {
|
|
1131
|
+
property_id : this.propertyId,
|
|
1132
|
+
session_id : this.sessionId,
|
|
1133
|
+
user_id : this.userId,
|
|
1134
|
+
player_instance_id : this.playerInstanceId,
|
|
1135
|
+
playback_id : this.playbackId,
|
|
1136
|
+
from : undefined, // int
|
|
1137
|
+
to : undefined, // int
|
|
1138
|
+
playback_time_instant_millis : undefined, // float
|
|
1139
|
+
bitrate_mbps : this.videoBitrate, // float
|
|
1140
|
+
// Event based i.e. when error is called
|
|
1141
|
+
error_code : undefined, // string
|
|
1142
|
+
error : undefined, // string
|
|
1143
|
+
error_text : undefined, // string
|
|
1144
|
+
|
|
1145
|
+
video_cover : undefined, // string
|
|
1146
|
+
video_cover_reference : undefined, // string
|
|
1147
|
+
player_remote_played : undefined, // boolean
|
|
1148
|
+
video_total_duration_millis : this.videoDuration, // int
|
|
1149
|
+
video_width_pixels : undefined, // int
|
|
1150
|
+
video_height_pixels : undefined, // int
|
|
1151
|
+
video_source_url : undefined, // string
|
|
1152
|
+
video_source_hostname : undefined, // string
|
|
1153
|
+
video_source_type : undefined, // string
|
|
1154
|
+
custom_content_type : this.customContentType, // string
|
|
1155
|
+
custom_video_duration_millis : this.customVideoDurationMillis, // int
|
|
1156
|
+
custom_encoding_variant : this.customEncodingVariant, // string
|
|
1157
|
+
custom_video_language : this.customVideoLanguage, // strirg
|
|
1158
|
+
custom_video_id : this.customVideoId, // string
|
|
1159
|
+
custom_video_series : this.customVideoSeries, // string
|
|
1160
|
+
custom_video_producer : this.customVideoProducer, // string
|
|
1161
|
+
custom_video_title : this.customVideoTitle, // string
|
|
1162
|
+
custom_video_variant_name : this.customVideoVariantName, // string
|
|
1163
|
+
custom_video_variant : this.customVideoVariant, // string
|
|
1164
|
+
muted : this.isMuted, // boolean
|
|
1165
|
+
// Setting Based
|
|
1166
|
+
casting : undefined, // boolean
|
|
1167
|
+
fullscreen : this.isFullScreen, // boolean
|
|
1168
|
+
video_downscale_percentage : undefined, // int
|
|
1169
|
+
video_upscale_percentage : undefined, // int
|
|
1170
|
+
|
|
1171
|
+
// Event Based
|
|
1172
|
+
orientation : undefined, // string
|
|
1173
|
+
orientation_from : undefined, // string
|
|
1174
|
+
quality : undefined, // string
|
|
1175
|
+
quality_from : undefined, // string
|
|
1176
|
+
previous_event : undefined, // string
|
|
1177
|
+
millis_from_previous_event : undefined, // integer
|
|
1178
|
+
|
|
1179
|
+
video_codec : undefined, // string
|
|
1180
|
+
audio_codec : undefined, // string
|
|
1181
|
+
|
|
1182
|
+
custom_data_1 : this.customData1,
|
|
1183
|
+
custom_data_2 : this.customData2,
|
|
1184
|
+
custom_data_3 : this.customData3,
|
|
1185
|
+
custom_data_4 : this.customData4,
|
|
1186
|
+
custom_data_5 : this.customData5,
|
|
1187
|
+
custom_data_6 : this.customData6,
|
|
1188
|
+
custom_data_7 : this.customData7,
|
|
1189
|
+
custom_data_8 : this.customData8,
|
|
1190
|
+
custom_data_9 : this.customData9,
|
|
1191
|
+
custom_data_10 : this.customData10
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
getSample(event=null, overrideData={}) {
|
|
1196
|
+
let sampleData = this.sample;
|
|
1197
|
+
|
|
1198
|
+
sampleData.event = event;
|
|
1199
|
+
if(this.config.getUUID){
|
|
1200
|
+
sampleData.event_id = this.config.getUUID();
|
|
1201
|
+
}else{
|
|
1202
|
+
sampleData.event_id = Utils.uuidv4();
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
sampleData.custom_data_1 = this.customData1;
|
|
1206
|
+
sampleData.custom_data_2 = this.customData2;
|
|
1207
|
+
sampleData.custom_data_3 = this.customData3;
|
|
1208
|
+
sampleData.custom_data_4 = this.customData4;
|
|
1209
|
+
sampleData.custom_data_5 = this.customData5;
|
|
1210
|
+
sampleData.custom_data_6 = this.customData6;
|
|
1211
|
+
sampleData.custom_data_7 = this.customData7;
|
|
1212
|
+
sampleData.custom_data_8 = this.customData8;
|
|
1213
|
+
sampleData.custom_data_9 = this.customData9;
|
|
1214
|
+
sampleData.custom_data_10 = this.customData1;
|
|
1215
|
+
|
|
1216
|
+
sampleData.custom_content_type = this.customContentType;
|
|
1217
|
+
sampleData.custom_video_duration_millis = this.customVideoDurationMillis;
|
|
1218
|
+
sampleData.custom_encoding_variant = this.customEncodingVariant;
|
|
1219
|
+
sampleData.custom_video_language = this.customVideoLanguage;
|
|
1220
|
+
sampleData.custom_video_id = this.customVideoId;
|
|
1221
|
+
sampleData.custom_video_series = this.customVideoSeries;
|
|
1222
|
+
sampleData.custom_video_producer = this.customVideoProducer;
|
|
1223
|
+
sampleData.custom_video_title = this.customVideoTitle;
|
|
1224
|
+
sampleData.custom_video_variant_name = this.customVideoVariantName;
|
|
1225
|
+
sampleData.custom_video_variant = this.customVideoVariant;
|
|
1226
|
+
|
|
1227
|
+
sampleData.millis_from_previous_event = this.getMillisFromPreviousState();
|
|
1228
|
+
sampleData.previous_event = this.previousState;
|
|
1229
|
+
sampleData.fullscreen = this.isFullScreen;
|
|
1230
|
+
sampleData.muted = this.isMuted;
|
|
1231
|
+
sampleData.video_width_pixels = this.videoWidthPixels;
|
|
1232
|
+
sampleData.video_height_pixels = this.videoHeightPixels;
|
|
1233
|
+
sampleData.video_total_duration_millis = this.videoDuration;
|
|
1234
|
+
sampleData.bitrate = this.videoBitrate;
|
|
1235
|
+
sampleData.audio_codec = this.audioCodec;
|
|
1236
|
+
sampleData.video_codec = this.videoCodec;
|
|
1237
|
+
sampleData.orientation = this.orientation;
|
|
1238
|
+
sampleData.playback_time_instant_millis = this.currentTime;
|
|
1239
|
+
sampleData.video_source_type = this.videoSourceType;
|
|
1240
|
+
sampleData.video_source_url = this.videoSourceUrl;
|
|
1241
|
+
sampleData.video_upscale_percentage = this.upscalePercentage;
|
|
1242
|
+
sampleData.video_downscale_percentage = this.downscalePercentage;
|
|
1243
|
+
sampleData.video_source_hostname = this.videoSourceHostname;
|
|
1244
|
+
Object.keys(overrideData).forEach(function(key) {
|
|
1245
|
+
sampleData[key] = overrideData[key]
|
|
1246
|
+
})
|
|
1247
|
+
return sampleData;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// checkLicensing(key) {
|
|
1251
|
+
// this.licenseCall.sendRequest(key,
|
|
1252
|
+
// this.sample.domain,
|
|
1253
|
+
// this.sample.analyticsVersion,
|
|
1254
|
+
// this.handleLicensingResponse.bind(this));
|
|
1255
|
+
// }
|
|
1256
|
+
|
|
1257
|
+
// handleLicensingResponse(licensingResponse) {
|
|
1258
|
+
// if (licensingResponse.status === 'granted') {
|
|
1259
|
+
// this.licensing = 'granted';
|
|
1260
|
+
// } else if (licensingResponse.status === 'skip') {
|
|
1261
|
+
// this.licensing = 'denied';
|
|
1262
|
+
// logger.log('Impression should not be sampled');
|
|
1263
|
+
// } else {
|
|
1264
|
+
// this.licensing = 'denied';
|
|
1265
|
+
// logger.log('Analytics license denied, reason: ' + licensingResponse.message);
|
|
1266
|
+
// }
|
|
1267
|
+
// }
|
|
1268
|
+
|
|
1269
|
+
sendAnalyticsRequest(event, overrideData) {
|
|
1270
|
+
// TODO: remove this not needed as added z param to all calls in Http.js
|
|
1271
|
+
// this.sample.time = Utils.getCurrentTimestamp();
|
|
1272
|
+
|
|
1273
|
+
let sample = this.getSample(event, overrideData);
|
|
1274
|
+
this.analyticsCall.sendRequest(sample, Utils.noOp);
|
|
1275
|
+
return;
|
|
1276
|
+
|
|
1277
|
+
// if (!this.isCastClient && !this.isCastReceiver) {
|
|
1278
|
+
// this.analyticsCall.sendRequest(sample, Utils.noOp);
|
|
1279
|
+
// return;
|
|
1280
|
+
// }
|
|
1281
|
+
|
|
1282
|
+
// if (!this.isAllowedToSendSamples) {
|
|
1283
|
+
// const copySample = {...this.sample};
|
|
1284
|
+
// this.samplesQueue.push(copySample);
|
|
1285
|
+
// } else {
|
|
1286
|
+
// for (let i = 0; i < this.samplesQueue.length; i++) {
|
|
1287
|
+
// this.analyticsCall.sendRequest(this.samplesQueue[i], Utils.noOp);
|
|
1288
|
+
// }
|
|
1289
|
+
// this.samplesQueue = [];
|
|
1290
|
+
//
|
|
1291
|
+
// this.analyticsCall.sendRequest(this.sample, Utils.noOp);
|
|
1292
|
+
// }
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
sendAnalyticsRequestAndClearValues(event=null, overrideData={}) {
|
|
1296
|
+
if (!event) {
|
|
1297
|
+
logger.log('event null passed not hitting the injestion API');
|
|
1298
|
+
return False;
|
|
1299
|
+
}
|
|
1300
|
+
this.sendAnalyticsRequest(event, overrideData);
|
|
1301
|
+
// this.clearValues();
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
sendUnloadRequest() {
|
|
1305
|
+
if (this.licensing === 'denied') {
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
if (typeof navigator.sendBeacon === 'undefined') {
|
|
1310
|
+
this.sendAnalyticsRequestSynchronous();
|
|
1311
|
+
}
|
|
1312
|
+
else {
|
|
1313
|
+
const success = navigator.sendBeacon(this.analyticsCall.getAnalyticsServerUrl(),
|
|
1314
|
+
JSON.stringify(this.sample));
|
|
1315
|
+
if (!success) {
|
|
1316
|
+
this.sendAnalyticsRequestSynchronous();
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
sendAnalyticsRequestSynchronous() {
|
|
1322
|
+
if (this.licensing === 'denied') {
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
this.analyticsCall.sendRequestSynchronous(this.sample, Utils.noOp);
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
clearValues() {
|
|
1330
|
+
this.sample.ad = 0;
|
|
1331
|
+
this.sample.paused = 0;
|
|
1332
|
+
this.sample.played = 0;
|
|
1333
|
+
this.sample.seeked = 0;
|
|
1334
|
+
this.sample.buffered = 0;
|
|
1335
|
+
|
|
1336
|
+
this.sample.playerStartupTime = 0;
|
|
1337
|
+
this.sample.videoStartupTime = 0;
|
|
1338
|
+
this.sample.startupTime = 0;
|
|
1339
|
+
|
|
1340
|
+
this.sample.duration = 0;
|
|
1341
|
+
this.sample.droppedFrames = 0;
|
|
1342
|
+
this.sample.pageLoadType = 0;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
getDroppedFrames(frames) {
|
|
1346
|
+
if (frames != undefined && frames != 0) {
|
|
1347
|
+
const droppedFrames = frames - this.droppedSampleFrames;
|
|
1348
|
+
this.droppedSampleFrames = frames;
|
|
1349
|
+
return droppedFrames;
|
|
1350
|
+
}
|
|
1351
|
+
else {
|
|
1352
|
+
return 0;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
export default Analytics;
|