@webex/internal-plugin-metrics 3.7.0 → 3.8.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.
Files changed (40) hide show
  1. package/dist/business-metrics.js +74 -100
  2. package/dist/business-metrics.js.map +1 -1
  3. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +24 -15
  4. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -1
  5. package/dist/call-diagnostic/call-diagnostic-metrics.js +56 -7
  6. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -1
  7. package/dist/call-diagnostic/config.js +19 -12
  8. package/dist/call-diagnostic/config.js.map +1 -1
  9. package/dist/call-diagnostic-events-batcher.js +59 -0
  10. package/dist/call-diagnostic-events-batcher.js.map +1 -0
  11. package/dist/generic-metrics.js +2 -2
  12. package/dist/generic-metrics.js.map +1 -1
  13. package/dist/metrics.js +1 -1
  14. package/dist/metrics.types.js.map +1 -1
  15. package/dist/new-metrics.js +28 -5
  16. package/dist/new-metrics.js.map +1 -1
  17. package/dist/types/business-metrics.d.ts +10 -28
  18. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +14 -1
  19. package/dist/types/call-diagnostic/config.d.ts +2 -0
  20. package/dist/types/generic-metrics.d.ts +2 -2
  21. package/dist/types/metrics.types.d.ts +9 -1
  22. package/dist/types/new-metrics.d.ts +15 -3
  23. package/package.json +12 -12
  24. package/src/business-metrics.ts +66 -76
  25. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +36 -14
  26. package/src/call-diagnostic/call-diagnostic-metrics.ts +72 -3
  27. package/src/call-diagnostic/config.ts +8 -0
  28. package/src/generic-metrics.ts +2 -2
  29. package/src/metrics.types.ts +10 -1
  30. package/src/new-metrics.ts +32 -4
  31. package/test/unit/spec/business/business-metrics.ts +2 -2
  32. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +85 -0
  33. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +243 -2
  34. package/test/unit/spec/new-metrics.ts +23 -0
  35. package/dist/behavioral/behavioral-metrics.js +0 -199
  36. package/dist/behavioral/behavioral-metrics.js.map +0 -1
  37. package/dist/behavioral/config.js +0 -11
  38. package/dist/behavioral/config.js.map +0 -1
  39. package/dist/types/behavioral/behavioral-metrics.d.ts +0 -63
  40. package/dist/types/behavioral/config.d.ts +0 -1
@@ -13,6 +13,8 @@ import {
13
13
  } from '@webex/internal-plugin-metrics';
14
14
  import uuid from 'uuid';
15
15
  import {omit} from 'lodash';
16
+ import { glob } from 'glob';
17
+ import { expect } from 'chai';
16
18
 
17
19
  //@ts-ignore
18
20
  global.window = {location: {hostname: 'whatever'}};
@@ -745,6 +747,52 @@ describe('internal-plugin-metrics', () => {
745
747
  });
746
748
  });
747
749
 
750
+ it('should prepare diagnostic event successfully when triggeredTime is supplied in the options object', () => {
751
+ const options = {meetingId: fakeMeeting.id, triggeredTime: 'fake-triggered-time'};
752
+ const getOriginStub = sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
753
+ const clearEmptyKeysRecursivelyStub = sinon.stub(
754
+ CallDiagnosticUtils,
755
+ 'clearEmptyKeysRecursively'
756
+ );
757
+
758
+ const res = cd.prepareDiagnosticEvent(
759
+ {
760
+ canProceed: false,
761
+ identifiers: {
762
+ correlationId: 'id',
763
+ webexConferenceIdStr: 'webexConferenceIdStr1',
764
+ globalMeetingId: 'globalMeetingId1',
765
+ },
766
+ name: 'client.alert.displayed',
767
+ },
768
+ options
769
+ );
770
+
771
+ assert.calledWith(getOriginStub, options, options.meetingId);
772
+ assert.calledOnce(clearEmptyKeysRecursivelyStub);
773
+ assert.deepEqual(res, {
774
+ event: {
775
+ canProceed: false,
776
+ identifiers: {
777
+ correlationId: 'id',
778
+ webexConferenceIdStr: 'webexConferenceIdStr1',
779
+ globalMeetingId: 'globalMeetingId1',
780
+ },
781
+ name: 'client.alert.displayed',
782
+ },
783
+ eventId: 'my-fake-id',
784
+ origin: {
785
+ origin: 'fake-origin',
786
+ },
787
+ originTime: {
788
+ sent: 'not_defined_yet',
789
+ triggered: 'fake-triggered-time',
790
+ },
791
+ senderCountryCode: 'UK',
792
+ version: 1,
793
+ });
794
+ });
795
+
748
796
  describe('#submitClientEvent', () => {
749
797
  it('should submit client event successfully with meetingId', () => {
750
798
  const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
@@ -796,6 +844,7 @@ describe('internal-plugin-metrics', () => {
796
844
  userType: 'host',
797
845
  isConvergedArchitectureEnabled: undefined,
798
846
  webexSubServiceType: undefined,
847
+ webClientPreload: undefined,
799
848
  },
800
849
  options
801
850
  );
@@ -821,6 +870,7 @@ describe('internal-plugin-metrics', () => {
821
870
  userType: 'host',
822
871
  isConvergedArchitectureEnabled: undefined,
823
872
  webexSubServiceType: undefined,
873
+ webClientPreload: undefined,
824
874
  },
825
875
  eventId: 'my-fake-id',
826
876
  origin: {
@@ -857,6 +907,7 @@ describe('internal-plugin-metrics', () => {
857
907
  userType: 'host',
858
908
  isConvergedArchitectureEnabled: undefined,
859
909
  webexSubServiceType: undefined,
910
+ webClientPreload: undefined,
860
911
  },
861
912
  eventId: 'my-fake-id',
862
913
  origin: {
@@ -930,6 +981,7 @@ describe('internal-plugin-metrics', () => {
930
981
  userType: 'host',
931
982
  isConvergedArchitectureEnabled: undefined,
932
983
  webexSubServiceType: undefined,
984
+ webClientPreload: undefined,
933
985
  },
934
986
  options
935
987
  );
@@ -956,6 +1008,7 @@ describe('internal-plugin-metrics', () => {
956
1008
  userType: 'host',
957
1009
  isConvergedArchitectureEnabled: undefined,
958
1010
  webexSubServiceType: undefined,
1011
+ webClientPreload: undefined,
959
1012
  },
960
1013
  eventId: 'my-fake-id',
961
1014
  origin: {
@@ -993,6 +1046,7 @@ describe('internal-plugin-metrics', () => {
993
1046
  userType: 'host',
994
1047
  isConvergedArchitectureEnabled: undefined,
995
1048
  webexSubServiceType: undefined,
1049
+ webClientPreload: undefined,
996
1050
  },
997
1051
  eventId: 'my-fake-id',
998
1052
  origin: {
@@ -1110,6 +1164,7 @@ describe('internal-plugin-metrics', () => {
1110
1164
  },
1111
1165
  loginType: 'login-ci',
1112
1166
  name: 'client.alert.displayed',
1167
+ webClientPreload: undefined
1113
1168
  },
1114
1169
  options
1115
1170
  );
@@ -1131,6 +1186,7 @@ describe('internal-plugin-metrics', () => {
1131
1186
  },
1132
1187
  loginType: 'login-ci',
1133
1188
  name: 'client.alert.displayed',
1189
+ webClientPreload: undefined
1134
1190
  },
1135
1191
  eventId: 'my-fake-id',
1136
1192
  origin: {
@@ -1204,6 +1260,7 @@ describe('internal-plugin-metrics', () => {
1204
1260
  },
1205
1261
  loginType: 'login-ci',
1206
1262
  name: 'client.alert.displayed',
1263
+ webClientPreload: undefined,
1207
1264
  },
1208
1265
  options
1209
1266
  );
@@ -1231,6 +1288,7 @@ describe('internal-plugin-metrics', () => {
1231
1288
  },
1232
1289
  eventData: {webClientDomain: 'whatever'},
1233
1290
  loginType: 'login-ci',
1291
+ webClientPreload: undefined,
1234
1292
  },
1235
1293
  },
1236
1294
  options.preLoginId
@@ -1273,6 +1331,7 @@ describe('internal-plugin-metrics', () => {
1273
1331
  joinFlowVersion: 'Other',
1274
1332
  isConvergedArchitectureEnabled: undefined,
1275
1333
  webexSubServiceType: undefined,
1334
+ webClientPreload: undefined,
1276
1335
  },
1277
1336
  eventId: 'my-fake-id',
1278
1337
  origin: {
@@ -1325,6 +1384,84 @@ describe('internal-plugin-metrics', () => {
1325
1384
  joinFlowVersion: 'Other',
1326
1385
  isConvergedArchitectureEnabled: undefined,
1327
1386
  webexSubServiceType: undefined,
1387
+ webClientPreload: undefined,
1388
+ },
1389
+ eventId: 'my-fake-id',
1390
+ origin: {
1391
+ origin: 'fake-origin',
1392
+ },
1393
+ originTime: {
1394
+ sent: 'not_defined_yet',
1395
+ triggered: now.toISOString(),
1396
+ },
1397
+ senderCountryCode: 'UK',
1398
+ version: 1,
1399
+ });
1400
+ });
1401
+
1402
+ it('should submit client event successfully with webClientPreload', () => {
1403
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
1404
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
1405
+ const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
1406
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
1407
+
1408
+ webex.meetings.config.metrics.webClientPreload = true;
1409
+
1410
+ const options = {
1411
+ correlationId: 'correlationId',
1412
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1413
+ globalMeetingId: 'globalMeetingId1',
1414
+ sessionCorrelationId: 'sessionCorrelationId1',
1415
+ };
1416
+
1417
+ cd.submitClientEvent({
1418
+ name: 'client.alert.displayed',
1419
+ options,
1420
+ });
1421
+
1422
+ assert.notCalled(generateClientEventErrorPayloadSpy);
1423
+ assert.calledWith(
1424
+ prepareDiagnosticEventSpy,
1425
+ {
1426
+ canProceed: true,
1427
+ eventData: {
1428
+ webClientDomain: 'whatever',
1429
+ },
1430
+ identifiers: {
1431
+ correlationId: 'correlationId',
1432
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1433
+ sessionCorrelationId: 'sessionCorrelationId1',
1434
+ globalMeetingId: 'globalMeetingId1',
1435
+ deviceId: 'deviceUrl',
1436
+ locusUrl: 'locus-url',
1437
+ orgId: 'orgId',
1438
+ userId: 'userId',
1439
+ },
1440
+ loginType: 'login-ci',
1441
+ name: 'client.alert.displayed',
1442
+ webClientPreload: true,
1443
+ },
1444
+ options
1445
+ );
1446
+ assert.calledWith(submitToCallDiagnosticsSpy, {
1447
+ event: {
1448
+ canProceed: true,
1449
+ eventData: {
1450
+ webClientDomain: 'whatever',
1451
+ },
1452
+ identifiers: {
1453
+ correlationId: 'correlationId',
1454
+ webexConferenceIdStr: 'webexConferenceIdStr1',
1455
+ sessionCorrelationId: 'sessionCorrelationId1',
1456
+ globalMeetingId: 'globalMeetingId1',
1457
+ deviceId: 'deviceUrl',
1458
+ locusUrl: 'locus-url',
1459
+ orgId: 'orgId',
1460
+ userId: 'userId',
1461
+ },
1462
+ loginType: 'login-ci',
1463
+ name: 'client.alert.displayed',
1464
+ webClientPreload: true,
1328
1465
  },
1329
1466
  eventId: 'my-fake-id',
1330
1467
  origin: {
@@ -1396,6 +1533,7 @@ describe('internal-plugin-metrics', () => {
1396
1533
  userType: 'host',
1397
1534
  isConvergedArchitectureEnabled: undefined,
1398
1535
  webexSubServiceType: undefined,
1536
+ webClientPreload: undefined,
1399
1537
  },
1400
1538
  eventId: 'my-fake-id',
1401
1539
  origin: {
@@ -1475,6 +1613,7 @@ describe('internal-plugin-metrics', () => {
1475
1613
  userType: 'host',
1476
1614
  isConvergedArchitectureEnabled: undefined,
1477
1615
  webexSubServiceType: undefined,
1616
+ webClientPreload: undefined,
1478
1617
  },
1479
1618
  eventId: 'my-fake-id',
1480
1619
  origin: {
@@ -1546,6 +1685,7 @@ describe('internal-plugin-metrics', () => {
1546
1685
  ],
1547
1686
  loginType: 'login-ci',
1548
1687
  name: 'client.alert.displayed',
1688
+ webClientPreload: undefined,
1549
1689
  },
1550
1690
  eventId: 'my-fake-id',
1551
1691
  origin: {
@@ -1619,6 +1759,7 @@ describe('internal-plugin-metrics', () => {
1619
1759
  ],
1620
1760
  loginType: 'login-ci',
1621
1761
  name: 'client.alert.displayed',
1762
+ webClientPreload: undefined,
1622
1763
  },
1623
1764
  eventId: 'my-fake-id',
1624
1765
  origin: {
@@ -1701,6 +1842,7 @@ describe('internal-plugin-metrics', () => {
1701
1842
  userType: 'host',
1702
1843
  isConvergedArchitectureEnabled: undefined,
1703
1844
  webexSubServiceType: undefined,
1845
+ webClientPreload: undefined,
1704
1846
  },
1705
1847
  eventId: 'my-fake-id',
1706
1848
  origin: {
@@ -2626,10 +2768,21 @@ describe('internal-plugin-metrics', () => {
2626
2768
  webexScheduled: true,
2627
2769
  pmr: false,
2628
2770
  enableEvent: true,
2771
+ isConvergedWebinar: true,
2629
2772
  };
2630
2773
  assert.deepEqual(cd.getSubServiceType(fakeMeeting), 'Webinar');
2631
2774
  });
2632
2775
 
2776
+ it('returns subServicetype as Webcast when meeting is Webinar and enable webcast', () => {
2777
+ fakeMeeting.meetingInfo = {
2778
+ webexScheduled: true,
2779
+ pmr: false,
2780
+ enableEvent: true,
2781
+ isConvergedWebinarWebcast: true,
2782
+ };
2783
+ assert.deepEqual(cd.getSubServiceType(fakeMeeting), 'Webcast');
2784
+ });
2785
+
2633
2786
  it('returns subServicetype as undefined when correct parameters are not found', () => {
2634
2787
  fakeMeeting.meetingInfo = {};
2635
2788
  assert.deepEqual(cd.getSubServiceType(fakeMeeting), undefined);
@@ -2693,6 +2846,7 @@ describe('internal-plugin-metrics', () => {
2693
2846
  userType: 'host',
2694
2847
  isConvergedArchitectureEnabled: undefined,
2695
2848
  webexSubServiceType: undefined,
2849
+ webClientPreload: undefined,
2696
2850
  },
2697
2851
  eventId: 'my-fake-id',
2698
2852
  origin: {
@@ -2759,11 +2913,12 @@ describe('internal-plugin-metrics', () => {
2759
2913
  });
2760
2914
  });
2761
2915
 
2762
- it('includes expected joinFlowVersion from options when in-meeting', async () => {
2916
+ it('includes expected joinFlowVersion and meetingJoinPhase from options when in-meeting', async () => {
2763
2917
  // meetingId means in-meeting
2764
2918
  const options = {
2765
2919
  meetingId: fakeMeeting.id,
2766
2920
  joinFlowVersion: 'NewFTE',
2921
+ meetingJoinPhase: 'join',
2767
2922
  };
2768
2923
 
2769
2924
  const triggered = new Date();
@@ -2777,6 +2932,11 @@ describe('internal-plugin-metrics', () => {
2777
2932
  fetchOptions.body.metrics[0].eventPayload.event.joinFlowVersion,
2778
2933
  options.joinFlowVersion
2779
2934
  );
2935
+
2936
+ assert.equal(
2937
+ fetchOptions.body.metrics[0].eventPayload.event.meetingJoinPhase,
2938
+ options.meetingJoinPhase
2939
+ );
2780
2940
  });
2781
2941
 
2782
2942
  it('includes expected joinFlowVersion from meeting callStateForMetrics when in-meeting', async () => {
@@ -2815,12 +2975,13 @@ describe('internal-plugin-metrics', () => {
2815
2975
  );
2816
2976
  });
2817
2977
 
2818
- it('includes expected joinFlowVersion from options during prejoin', async () => {
2978
+ it('includes expected joinFlowVersion and meetingJoinPhase from options during prejoin', async () => {
2819
2979
  // correlationId and no meeting id means prejoin
2820
2980
  const options = {
2821
2981
  correlationId: 'myCorrelationId',
2822
2982
  preLoginId: 'myPreLoginId',
2823
2983
  joinFlowVersion: 'NewFTE',
2984
+ meetingJoinPhase: 'pre-join',
2824
2985
  };
2825
2986
 
2826
2987
  const triggered = new Date();
@@ -2834,6 +2995,11 @@ describe('internal-plugin-metrics', () => {
2834
2995
  fetchOptions.body.metrics[0].eventPayload.event.joinFlowVersion,
2835
2996
  options.joinFlowVersion
2836
2997
  );
2998
+
2999
+ assert.equal(
3000
+ fetchOptions.body.metrics[0].eventPayload.event.meetingJoinPhase,
3001
+ options.meetingJoinPhase
3002
+ );
2837
3003
  });
2838
3004
  });
2839
3005
 
@@ -2880,5 +3046,80 @@ describe('internal-plugin-metrics', () => {
2880
3046
  assert.deepEqual(cd.device, device);
2881
3047
  });
2882
3048
  });
3049
+
3050
+ describe('#submitDelayedClientEvents', () => {
3051
+ it('does not call submitClientEvent if there were no delayed events', () => {
3052
+ const submitClientEventSpy = sinon.spy(cd, 'submitClientEvent');
3053
+
3054
+ cd.submitDelayedClientEvents();
3055
+
3056
+ assert.notCalled(submitClientEventSpy);
3057
+ });
3058
+
3059
+ it('calls submitClientEvent for every delayed event and clears delayedClientEvents array', () => {
3060
+ const submitClientEventSpy = sinon.spy(cd, 'submitClientEvent');
3061
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
3062
+
3063
+ const options = {
3064
+ correlationId: 'correlationId',
3065
+ };
3066
+
3067
+ cd.submitClientEvent({
3068
+ name: 'client.alert.displayed',
3069
+ options,
3070
+ delaySubmitEvent: true,
3071
+ });
3072
+
3073
+ cd.submitClientEvent({
3074
+ name: 'client.alert.removed',
3075
+ options,
3076
+ delaySubmitEvent: true,
3077
+ });
3078
+
3079
+ cd.submitClientEvent({
3080
+ name: 'client.call.aborted',
3081
+ options,
3082
+ delaySubmitEvent: true,
3083
+ });
3084
+
3085
+ assert.notCalled(submitToCallDiagnosticsSpy);
3086
+ assert.calledThrice(submitClientEventSpy);
3087
+ submitClientEventSpy.resetHistory();
3088
+
3089
+ cd.submitDelayedClientEvents();
3090
+
3091
+ assert.calledThrice(submitClientEventSpy);
3092
+ assert.calledWith(submitClientEventSpy.firstCall, {
3093
+ name: 'client.alert.displayed',
3094
+ payload: undefined,
3095
+ options: {
3096
+ correlationId: 'correlationId',
3097
+ triggeredTime: now.toISOString(),
3098
+ },
3099
+ });
3100
+ assert.calledWith(submitClientEventSpy.secondCall, {
3101
+ name: 'client.alert.removed',
3102
+ payload: undefined,
3103
+ options: {
3104
+ correlationId: 'correlationId',
3105
+ triggeredTime: now.toISOString(),
3106
+ },
3107
+ });
3108
+ assert.calledWith(submitClientEventSpy.thirdCall, {
3109
+ name: 'client.call.aborted',
3110
+ payload: undefined,
3111
+ options: {
3112
+ correlationId: 'correlationId',
3113
+ triggeredTime: now.toISOString(),
3114
+ },
3115
+ });
3116
+ submitClientEventSpy.resetHistory();
3117
+
3118
+ cd.submitDelayedClientEvents();
3119
+
3120
+ // should not call submitClientEvent again if delayedClientEvents was cleared
3121
+ assert.notCalled(submitClientEventSpy);
3122
+ });
3123
+ });
2883
3124
  });
2884
3125
  });
@@ -59,6 +59,7 @@ describe('internal-plugin-metrics', () => {
59
59
  webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp = sinon.stub();
60
60
  webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps = sinon.stub();
61
61
  webex.internal.newMetrics.callDiagnosticMetrics.submitClientEvent = sinon.stub();
62
+ webex.internal.newMetrics.callDiagnosticMetrics.submitDelayedClientEvents = sinon.stub();
62
63
  webex.internal.newMetrics.callDiagnosticMetrics.submitMQE = sinon.stub();
63
64
  webex.internal.newMetrics.callDiagnosticMetrics.clientMetricsAliasUser = sinon.stub();
64
65
  webex.internal.newMetrics.callDiagnosticMetrics.buildClientEventFetchRequestOptions =
@@ -93,12 +94,14 @@ describe('internal-plugin-metrics', () => {
93
94
  name: 'foobar',
94
95
  payload: {},
95
96
  table: 'test',
97
+ metadata: { foo: 'bar' },
96
98
  });
97
99
 
98
100
  assert.calledWith(webex.internal.newMetrics.businessMetrics.submitBusinessEvent, {
99
101
  name: 'foobar',
100
102
  payload: {},
101
103
  table: 'test',
104
+ metadata: { foo: 'bar' },
102
105
  });
103
106
  });
104
107
 
@@ -118,6 +121,7 @@ describe('internal-plugin-metrics', () => {
118
121
  name: 'client.alert.displayed',
119
122
  payload: undefined,
120
123
  options: {meetingId: '123'},
124
+ delaySubmitEvent: false,
121
125
  });
122
126
  });
123
127
 
@@ -256,5 +260,24 @@ describe('internal-plugin-metrics', () => {
256
260
  sinon.restore();
257
261
  });
258
262
  });
263
+
264
+ describe('#setDelaySubmitClientEvents', () => {
265
+ it('sets delaySubmitClientEvents correctly and calls submitDelayedClientEvents when set to false', () => {
266
+ sinon.assert.match(webex.internal.newMetrics.delaySubmitClientEvents, false);
267
+
268
+ webex.internal.newMetrics.setDelaySubmitClientEvents(true);
269
+
270
+ assert.notCalled(webex.internal.newMetrics.callDiagnosticMetrics.submitDelayedClientEvents);
271
+
272
+ sinon.assert.match(webex.internal.newMetrics.delaySubmitClientEvents, true);
273
+
274
+ webex.internal.newMetrics.setDelaySubmitClientEvents(false);
275
+
276
+ assert.calledOnce(webex.internal.newMetrics.callDiagnosticMetrics.submitDelayedClientEvents);
277
+ assert.calledWith(webex.internal.newMetrics.callDiagnosticMetrics.submitDelayedClientEvents);
278
+
279
+ sinon.assert.match(webex.internal.newMetrics.delaySubmitClientEvents, false);
280
+ });
281
+ });
259
282
  });
260
283
  });
@@ -1,199 +0,0 @@
1
- "use strict";
2
-
3
- var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
4
- var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
5
- var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
6
- _Object$defineProperty(exports, "__esModule", {
7
- value: true
8
- });
9
- exports.default = void 0;
10
- var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
13
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/assertThisInitialized"));
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
15
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
16
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
17
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
18
- var _lodash = require("lodash");
19
- var _common = require("@webex/common");
20
- var _webexCore = require("@webex/webex-core");
21
- var _metrics = require("../metrics");
22
- var _config = require("./config");
23
- var _clientMetricsBatcher = _interopRequireDefault(require("../client-metrics-batcher"));
24
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
26
- var _BrowserDetection = (0, _common.BrowserDetection)(),
27
- getOSVersion = _BrowserDetection.getOSVersion,
28
- getBrowserName = _BrowserDetection.getBrowserName,
29
- getBrowserVersion = _BrowserDetection.getBrowserVersion;
30
-
31
- /**
32
- * @description Util class to handle Behavioral Metrics
33
- * @export
34
- * @class BehavioralMetrics
35
- */
36
- var BehavioralMetrics = exports.default = /*#__PURE__*/function (_StatelessWebexPlugin) {
37
- (0, _inherits2.default)(BehavioralMetrics, _StatelessWebexPlugin);
38
- var _super = _createSuper(BehavioralMetrics);
39
- /**
40
- * Constructor
41
- * @param {any[]} args
42
- */
43
- function BehavioralMetrics() {
44
- var _this;
45
- (0, _classCallCheck2.default)(this, BehavioralMetrics);
46
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
47
- args[_key] = arguments[_key];
48
- }
49
- _this = _super.call.apply(_super, [this].concat(args));
50
- // @ts-ignore
51
- // @ts-ignore
52
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "clientMetricsBatcher", void 0);
53
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "logger", void 0);
54
- // to avoid adding @ts-ignore everywhere
55
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "device", void 0);
56
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "version", void 0);
57
- _this.logger = _this.webex.logger;
58
- // @ts-ignore
59
- _this.device = _this.webex.internal.device;
60
- // @ts-ignore
61
- _this.version = _this.webex.version;
62
- // @ts-ignore
63
- _this.clientMetricsBatcher = new _clientMetricsBatcher.default({}, {
64
- parent: _this.webex
65
- });
66
- return _this;
67
- }
68
-
69
- /**
70
- * Returns the deviceId from our registration with WDM.
71
- * @returns {string} deviceId or empty string
72
- */
73
- (0, _createClass2.default)(BehavioralMetrics, [{
74
- key: "getDeviceId",
75
- value: function getDeviceId() {
76
- var url = this.device.url;
77
- if (url && url.length !== 0) {
78
- var n = url.lastIndexOf('/');
79
- if (n !== -1) {
80
- return url.substring(n + 1);
81
- }
82
- }
83
- return '';
84
- }
85
-
86
- /**
87
- * Returns the context object to be submitted with all behavioral metrics.
88
- * @returns {BehavioralEventContext}
89
- */
90
- }, {
91
- key: "getContext",
92
- value: function getContext() {
93
- var context = {
94
- app: {
95
- version: this.version
96
- },
97
- device: {
98
- id: this.getDeviceId()
99
- },
100
- locale: window.navigator.language,
101
- os: {
102
- name: (0, _metrics.getOSNameInternal)(),
103
- version: getOSVersion()
104
- }
105
- };
106
- return context;
107
- }
108
-
109
- /**
110
- * Returns the default tags to be included with all behavioral metrics.
111
- * @returns {BehavioralEventPayload}
112
- */
113
- }, {
114
- key: "getDefaultTags",
115
- value: function getDefaultTags() {
116
- var tags = {
117
- browser: getBrowserName(),
118
- browserHeight: window.innerHeight,
119
- browserVersion: getBrowserVersion(),
120
- browserWidth: window.innerWidth,
121
- domain: window.location.hostname,
122
- inIframe: window.self !== window.top,
123
- locale: window.navigator.language,
124
- os: (0, _metrics.getOSNameInternal)()
125
- };
126
- return tags;
127
- }
128
-
129
- /**
130
- * Creates the object to send to our metrics endpoint for a behavioral event
131
- * @param {MetricEventProduct} product
132
- * @param {MetricEventAgent} agent
133
- * @param {string} target
134
- * @param {MetricEventVerb} verb
135
- * @returns {BehavioralEventPayload}
136
- */
137
- }, {
138
- key: "createEventObject",
139
- value: function createEventObject(_ref) {
140
- var product = _ref.product,
141
- agent = _ref.agent,
142
- target = _ref.target,
143
- verb = _ref.verb,
144
- payload = _ref.payload;
145
- var metricName = "".concat(product, ".").concat(agent, ".").concat(target, ".").concat(verb);
146
- var allTags = payload;
147
- allTags = (0, _lodash.merge)(allTags, this.getDefaultTags());
148
- var event = {
149
- context: this.getContext(),
150
- metricName: metricName,
151
- tags: allTags,
152
- timestamp: (0, _now.default)(),
153
- type: ['behavioral']
154
- };
155
- return event;
156
- }
157
-
158
- /**
159
- * Returns true once we're ready to submit behavioral metrics, after startup.
160
- * @returns {boolean} true when deviceId is defined and non-empty
161
- */
162
- }, {
163
- key: "isReadyToSubmitBehavioralEvents",
164
- value: function isReadyToSubmitBehavioralEvents() {
165
- var deviceId = this.getDeviceId();
166
- return deviceId && deviceId.length !== 0;
167
- }
168
-
169
- /**
170
- * Submit a behavioral metric to our metrics endpoint.
171
- * @param {MetricEventProduct} product the product from which the metric is being submitted, e.g. 'webex' web client, 'wxcc_desktop'
172
- * @param {MetricEventAgent} agent the source of the action for this metric
173
- * @param {string} target the 'thing' that this metric includes information about
174
- * @param {MetricEventVerb} verb the action that this metric includes information about
175
- * @param {BehavioralEventPayload} payload information specific to this event. This should be flat, i.e. it should not include nested objects.
176
- * @returns {Promise<any>}
177
- */
178
- }, {
179
- key: "submitBehavioralEvent",
180
- value: function submitBehavioralEvent(_ref2) {
181
- var product = _ref2.product,
182
- agent = _ref2.agent,
183
- target = _ref2.target,
184
- verb = _ref2.verb,
185
- payload = _ref2.payload;
186
- this.logger.log(_config.BEHAVIORAL_LOG_IDENTIFIER, "BehavioralMetrics: @submitBehavioralEvent. Submit Behavioral event: ".concat(product, ".").concat(agent, ".").concat(target, ".").concat(verb));
187
- var behavioralEvent = this.createEventObject({
188
- product: product,
189
- agent: agent,
190
- target: target,
191
- verb: verb,
192
- payload: payload
193
- });
194
- return this.clientMetricsBatcher.request(behavioralEvent);
195
- }
196
- }]);
197
- return BehavioralMetrics;
198
- }(_webexCore.StatelessWebexPlugin);
199
- //# sourceMappingURL=behavioral-metrics.js.map