@mparticle/web-sdk 2.18.1 → 2.18.3

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.
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  SDKEvent,
3
- SDKConsentState,
4
- SDKGDPRConsentState,
5
3
  SDKGeoLocation,
6
- SDKCCPAConsentState,
7
4
  SDKProduct,
8
5
  SDKPromotion,
9
6
  SDKUserIdentity,
@@ -12,7 +9,13 @@ import {
12
9
  SDKIdentityTypeEnum,
13
10
  } from './sdkRuntimeModels';
14
11
  import * as EventsApi from '@mparticle/event-models';
12
+ import {
13
+ SDKConsentState,
14
+ SDKGDPRConsentState,
15
+ SDKCCPAConsentState,
16
+ } from './consent.interfaces';
15
17
  import Types from './types';
18
+ import { isEmpty } from './utils';
16
19
 
17
20
  export function convertEvents(
18
21
  mpid: string,
@@ -26,6 +29,8 @@ export function convertEvents(
26
29
  return null;
27
30
  }
28
31
 
32
+ const user = mpInstance.Identity.getCurrentUser();
33
+
29
34
  const uploadEvents: EventsApi.BaseEvent[] = [];
30
35
  let lastEvent: SDKEvent = null;
31
36
  for (const sdkEvent of sdkEvents) {
@@ -42,6 +47,15 @@ export function convertEvents(
42
47
  return null;
43
48
  }
44
49
 
50
+ let currentConsentState: SDKConsentState = null;
51
+
52
+ // Add the consent state from either the Last Event or the user
53
+ if (!isEmpty(lastEvent.ConsentState)) {
54
+ currentConsentState = lastEvent.ConsentState;
55
+ } else if (!isEmpty(user)) {
56
+ currentConsentState = user.getConsentState();
57
+ }
58
+
45
59
  const upload: EventsApi.Batch = {
46
60
  source_request_id: mpInstance._Helpers.generateUniqueId(),
47
61
  mpid,
@@ -64,7 +78,7 @@ export function convertEvents(
64
78
  },
65
79
  user_attributes: lastEvent.UserAttributes,
66
80
  user_identities: convertUserIdentities(lastEvent.UserIdentities),
67
- consent_state: convertConsentState(lastEvent.ConsentState),
81
+ consent_state: convertConsentState(currentConsentState),
68
82
  integration_attributes: lastEvent.IntegrationAttributes,
69
83
  };
70
84
 
@@ -82,7 +96,7 @@ export function convertEvents(
82
96
  export function convertConsentState(
83
97
  sdkConsentState?: SDKConsentState
84
98
  ): EventsApi.ConsentState | null {
85
- if (!sdkConsentState) {
99
+ if (isEmpty(sdkConsentState)) {
86
100
  return null;
87
101
  }
88
102
  const consentState: EventsApi.ConsentState = {
@@ -327,7 +341,8 @@ export function convertPromotionAction(
327
341
  return null;
328
342
  }
329
343
  const promotionAction: EventsApi.PromotionAction = {
330
- action: sdkEvent.PromotionAction.PromotionActionType as EventsApi.PromotionActionActionEnum,
344
+ action: sdkEvent.PromotionAction
345
+ .PromotionActionType as EventsApi.PromotionActionActionEnum,
331
346
  promotions: convertPromotions(sdkEvent.PromotionAction.PromotionList),
332
347
  };
333
348
  return promotionAction;
@@ -388,9 +403,8 @@ export function convertShoppingCart(
388
403
  export function convertCommerceEvent(
389
404
  sdkEvent: SDKEvent
390
405
  ): EventsApi.CommerceEvent {
391
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
392
- sdkEvent
393
- );
406
+ const commonEventData: EventsApi.CommonEventData =
407
+ convertBaseEventData(sdkEvent);
394
408
  let commerceEventData: EventsApi.CommerceEventData = {
395
409
  custom_flags: sdkEvent.CustomFlags,
396
410
  product_action: convertProductAction(sdkEvent),
@@ -409,9 +423,8 @@ export function convertCommerceEvent(
409
423
  export function convertCrashReportEvent(
410
424
  sdkEvent: SDKEvent
411
425
  ): EventsApi.CrashReportEvent {
412
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
413
- sdkEvent
414
- );
426
+ const commonEventData: EventsApi.CommonEventData =
427
+ convertBaseEventData(sdkEvent);
415
428
  let crashReportEventData: EventsApi.CrashReportEventData = {
416
429
  message: sdkEvent.EventName,
417
430
  };
@@ -425,9 +438,8 @@ export function convertCrashReportEvent(
425
438
  export function convertAST(
426
439
  sdkEvent: SDKEvent
427
440
  ): EventsApi.ApplicationStateTransitionEvent {
428
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
429
- sdkEvent
430
- );
441
+ const commonEventData: EventsApi.CommonEventData =
442
+ convertBaseEventData(sdkEvent);
431
443
  let astEventData: EventsApi.ApplicationStateTransitionEventData = {
432
444
  application_transition_type:
433
445
  EventsApi
@@ -447,9 +459,8 @@ export function convertAST(
447
459
  export function convertSessionEndEvent(
448
460
  sdkEvent: SDKEvent
449
461
  ): EventsApi.SessionEndEvent {
450
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
451
- sdkEvent
452
- );
462
+ const commonEventData: EventsApi.CommonEventData =
463
+ convertBaseEventData(sdkEvent);
453
464
  let sessionEndEventData: EventsApi.SessionEndEventData = {
454
465
  session_duration_ms: sdkEvent.SessionLength,
455
466
  //note: External Events DTO does not support the session mpids array as of this time.
@@ -465,9 +476,8 @@ export function convertSessionEndEvent(
465
476
  export function convertSessionStartEvent(
466
477
  sdkEvent: SDKEvent
467
478
  ): EventsApi.SessionStartEvent {
468
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
469
- sdkEvent
470
- );
479
+ const commonEventData: EventsApi.CommonEventData =
480
+ convertBaseEventData(sdkEvent);
471
481
  let sessionStartEventData: EventsApi.SessionStartEventData = {};
472
482
  sessionStartEventData = Object.assign(
473
483
  sessionStartEventData,
@@ -482,9 +492,8 @@ export function convertSessionStartEvent(
482
492
  export function convertPageViewEvent(
483
493
  sdkEvent: SDKEvent
484
494
  ): EventsApi.ScreenViewEvent {
485
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
486
- sdkEvent
487
- );
495
+ const commonEventData: EventsApi.CommonEventData =
496
+ convertBaseEventData(sdkEvent);
488
497
  let screenViewEventData: EventsApi.ScreenViewEventData = {
489
498
  custom_flags: sdkEvent.CustomFlags,
490
499
  screen_name: sdkEvent.EventName,
@@ -497,9 +506,8 @@ export function convertPageViewEvent(
497
506
  }
498
507
 
499
508
  export function convertOptOutEvent(sdkEvent: SDKEvent): EventsApi.OptOutEvent {
500
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
501
- sdkEvent
502
- );
509
+ const commonEventData: EventsApi.CommonEventData =
510
+ convertBaseEventData(sdkEvent);
503
511
  let optOutEventData: EventsApi.OptOutEventData = {
504
512
  is_opted_out: sdkEvent.OptOut,
505
513
  };
@@ -511,9 +519,8 @@ export function convertOptOutEvent(sdkEvent: SDKEvent): EventsApi.OptOutEvent {
511
519
  }
512
520
 
513
521
  export function convertCustomEvent(sdkEvent: SDKEvent): EventsApi.CustomEvent {
514
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
515
- sdkEvent
516
- );
522
+ const commonEventData: EventsApi.CommonEventData =
523
+ convertBaseEventData(sdkEvent);
517
524
  let customEventData: EventsApi.CustomEventData = {
518
525
  custom_event_type: convertSdkEventType(
519
526
  sdkEvent.EventCategory
@@ -596,7 +603,7 @@ export function convertBaseEventData(
596
603
  session_start_unixtime_ms: sdkEvent.SessionStartDate,
597
604
  custom_attributes: sdkEvent.EventAttributes,
598
605
  location: convertSDKLocation(sdkEvent.Location),
599
- source_message_id: sdkEvent.SourceMessageId
606
+ source_message_id: sdkEvent.SourceMessageId,
600
607
  };
601
608
 
602
609
  return commonEventData;
@@ -617,9 +624,8 @@ export function convertSDKLocation(
617
624
  export function convertUserAttributeChangeEvent(
618
625
  sdkEvent: SDKEvent
619
626
  ): EventsApi.UserAttributeChangeEvent | null {
620
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
621
- sdkEvent
622
- );
627
+ const commonEventData: EventsApi.CommonEventData =
628
+ convertBaseEventData(sdkEvent);
623
629
  let userAttributeChangeEvent: EventsApi.UserAttributeChangeEventData = {
624
630
  user_attribute_name: sdkEvent.UserAttributeChanges.UserAttributeName,
625
631
  new: sdkEvent.UserAttributeChanges.New,
@@ -642,9 +648,8 @@ export function convertUserAttributeChangeEvent(
642
648
  export function convertUserIdentityChangeEvent(
643
649
  sdkEvent: SDKEvent
644
650
  ): EventsApi.UserIdentityChangeEvent | null {
645
- const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
646
- sdkEvent
647
- );
651
+ const commonEventData: EventsApi.CommonEventData =
652
+ convertBaseEventData(sdkEvent);
648
653
 
649
654
  let userIdentityChangeEvent: EventsApi.UserIdentityChangeEventData = {
650
655
  new: {
@@ -683,48 +688,48 @@ export function convertUserIdentityTypeToServerIdentityType(
683
688
  ): EventsApi.IdentityType {
684
689
  switch (identityType) {
685
690
  case SDKIdentityTypeEnum.other:
686
- return EventsApi.IdentityTypeEnum.other
691
+ return EventsApi.IdentityTypeEnum.other;
687
692
  case SDKIdentityTypeEnum.customerId:
688
- return EventsApi.IdentityTypeEnum.customerId
693
+ return EventsApi.IdentityTypeEnum.customerId;
689
694
  case SDKIdentityTypeEnum.facebook:
690
- return EventsApi.IdentityTypeEnum.facebook
695
+ return EventsApi.IdentityTypeEnum.facebook;
691
696
  case SDKIdentityTypeEnum.twitter:
692
- return EventsApi.IdentityTypeEnum.twitter
697
+ return EventsApi.IdentityTypeEnum.twitter;
693
698
  case SDKIdentityTypeEnum.google:
694
- return EventsApi.IdentityTypeEnum.google
699
+ return EventsApi.IdentityTypeEnum.google;
695
700
  case SDKIdentityTypeEnum.microsoft:
696
- return EventsApi.IdentityTypeEnum.microsoft
701
+ return EventsApi.IdentityTypeEnum.microsoft;
697
702
  case SDKIdentityTypeEnum.yahoo:
698
- return EventsApi.IdentityTypeEnum.yahoo
703
+ return EventsApi.IdentityTypeEnum.yahoo;
699
704
  case SDKIdentityTypeEnum.email:
700
- return EventsApi.IdentityTypeEnum.email
705
+ return EventsApi.IdentityTypeEnum.email;
701
706
  case SDKIdentityTypeEnum.alias:
702
- return EventsApi.IdentityTypeEnum.alias
707
+ return EventsApi.IdentityTypeEnum.alias;
703
708
  case SDKIdentityTypeEnum.facebookCustomAudienceId:
704
- return EventsApi.IdentityTypeEnum.facebookCustomAudienceId
709
+ return EventsApi.IdentityTypeEnum.facebookCustomAudienceId;
705
710
  case SDKIdentityTypeEnum.otherId2:
706
- return EventsApi.IdentityTypeEnum.otherId2
711
+ return EventsApi.IdentityTypeEnum.otherId2;
707
712
  case SDKIdentityTypeEnum.otherId3:
708
- return EventsApi.IdentityTypeEnum.otherId3
713
+ return EventsApi.IdentityTypeEnum.otherId3;
709
714
  case SDKIdentityTypeEnum.otherId4:
710
- return EventsApi.IdentityTypeEnum.otherId4
715
+ return EventsApi.IdentityTypeEnum.otherId4;
711
716
  case SDKIdentityTypeEnum.otherId5:
712
- return EventsApi.IdentityTypeEnum.otherId5
717
+ return EventsApi.IdentityTypeEnum.otherId5;
713
718
  case SDKIdentityTypeEnum.otherId6:
714
- return EventsApi.IdentityTypeEnum.otherId6
719
+ return EventsApi.IdentityTypeEnum.otherId6;
715
720
  case SDKIdentityTypeEnum.otherId7:
716
- return EventsApi.IdentityTypeEnum.otherId7
721
+ return EventsApi.IdentityTypeEnum.otherId7;
717
722
  case SDKIdentityTypeEnum.otherId8:
718
- return EventsApi.IdentityTypeEnum.otherId8
723
+ return EventsApi.IdentityTypeEnum.otherId8;
719
724
  case SDKIdentityTypeEnum.otherId9:
720
- return EventsApi.IdentityTypeEnum.otherId9
725
+ return EventsApi.IdentityTypeEnum.otherId9;
721
726
  case SDKIdentityTypeEnum.otherId10:
722
- return EventsApi.IdentityTypeEnum.otherId10
727
+ return EventsApi.IdentityTypeEnum.otherId10;
723
728
  case SDKIdentityTypeEnum.mobileNumber:
724
- return EventsApi.IdentityTypeEnum.mobileNumber
729
+ return EventsApi.IdentityTypeEnum.mobileNumber;
725
730
  case SDKIdentityTypeEnum.phoneNumber2:
726
- return EventsApi.IdentityTypeEnum.phoneNumber2
731
+ return EventsApi.IdentityTypeEnum.phoneNumber2;
727
732
  case SDKIdentityTypeEnum.phoneNumber3:
728
- return EventsApi.IdentityTypeEnum.phoneNumber3
733
+ return EventsApi.IdentityTypeEnum.phoneNumber3;
729
734
  }
730
735
  }
@@ -8,7 +8,6 @@ import {
8
8
  BaseEvent,
9
9
  MParticleUser,
10
10
  MParticleWebSDK,
11
- SDKConsentState,
12
11
  SDKEvent,
13
12
  SDKGeoLocation,
14
13
  SDKProduct,
@@ -17,35 +16,16 @@ import {
17
16
  import { parseNumber, parseStringOrNumber, Dictionary } from './utils';
18
17
  import { ServerSettings } from './store';
19
18
  import { MPID } from '@mparticle/web-sdk';
19
+ import {
20
+ IConsentStateDTO,
21
+ IGDPRConsentStateDTO,
22
+ IPrivacyV2DTO,
23
+ SDKConsentState,
24
+ } from './consent.interfaces';
20
25
 
21
26
  const MessageType = Types.MessageType;
22
27
  const ApplicationTransitionType = Types.ApplicationTransitionType;
23
28
 
24
- // TODO: Move to Consent Module
25
- export interface IPrivacyV2DTO {
26
- c: boolean; // Consented
27
- ts: number; // Timestamp
28
- d: string; // Document
29
- l: string; // Location
30
- h: string; // HardwareID
31
- }
32
-
33
- // TODO: Move to Consent Module
34
- export interface IGDPRConsentStateDTO {
35
- [key: string]: IPrivacyV2DTO;
36
- }
37
-
38
- // TODO: Move to Consent Module
39
- export interface ICCPAConsentStateDTO {
40
- data_sale_opt_out: IPrivacyV2DTO;
41
- }
42
-
43
- // TODO: Break this up into GDPR and CCPA interfaces
44
- export interface IConsentStateDTO {
45
- gdpr?: IGDPRConsentStateDTO;
46
- ccpa?: ICCPAConsentStateDTO;
47
- }
48
-
49
29
  // TODO: Confirm which attributes are optional
50
30
  export interface IServerDTO {
51
31
  id: string | number;
package/src/store.ts CHANGED
@@ -7,16 +7,15 @@ import {
7
7
  IdentityCallback,
8
8
  SDKEventCustomFlags,
9
9
  } from '@mparticle/web-sdk';
10
+ import { IKitConfigs } from './configAPIClient';
10
11
  import Constants from './constants';
11
12
  import {
12
13
  DataPlanResult,
13
14
  Kit,
14
15
  KitBlockerOptions,
15
- KitConfigs,
16
16
  LogLevelType,
17
17
  MParticleWebSDK,
18
18
  MPForwarder,
19
- SDKConsentState,
20
19
  SDKDataPlan,
21
20
  SDKEvent,
22
21
  SDKGeoLocation,
@@ -24,6 +23,7 @@ import {
24
23
  SDKProduct,
25
24
  } from './sdkRuntimeModels';
26
25
  import { isNumber, isDataPlanSlug, Dictionary } from './utils';
26
+ import { SDKConsentState } from './consent.interfaces';
27
27
 
28
28
  // This represents the runtime configuration of the SDK AFTER
29
29
  // initialization has been complete and all settings and
@@ -45,7 +45,7 @@ export interface SDKConfig {
45
45
  appVersion?: string;
46
46
  package?: string;
47
47
  flags?: { [key: string]: string | number | boolean };
48
- kitConfigs: KitConfigs[];
48
+ kitConfigs: IKitConfigs[];
49
49
  kits: Dictionary<Kit>;
50
50
  logLevel?: LogLevelType;
51
51
  cookieDomain?: string;
@@ -102,6 +102,13 @@ export type PixelConfiguration = Dictionary;
102
102
  export type MigrationData = Dictionary;
103
103
  export type ServerSettings = Dictionary;
104
104
 
105
+ type WrapperSDKTypes = 'flutter' | 'none';
106
+ interface WrapperSDKInfo {
107
+ name: WrapperSDKTypes;
108
+ version: string | null;
109
+ isInfoSet: boolean;
110
+ }
111
+
105
112
  // Temporary Interface until Store can be refactored as a class
106
113
  export interface IStore {
107
114
  isEnabled: boolean;
@@ -144,6 +151,7 @@ export interface IStore {
144
151
  pixelConfigurations: PixelConfiguration[];
145
152
  integrationDelayTimeoutStart: number; // UNIX Timestamp
146
153
  webviewBridgeEnabled?: boolean;
154
+ wrapperSDKInfo: WrapperSDKInfo;
147
155
  }
148
156
 
149
157
  // TODO: Merge this with SDKStoreApi in sdkRuntimeModels
@@ -191,6 +199,11 @@ export default function Store(
191
199
  kits: {},
192
200
  configuredForwarders: [],
193
201
  pixelConfigurations: [],
202
+ wrapperSDKInfo: {
203
+ name: 'none',
204
+ version: null,
205
+ isInfoSet: false,
206
+ },
194
207
  };
195
208
 
196
209
  for (var key in defaultStore) {
@@ -1,67 +0,0 @@
1
- export default function ConfigAPIClient() {
2
- this.getSDKConfiguration = function(
3
- apiKey,
4
- config,
5
- completeSDKInitialization,
6
- mpInstance
7
- ) {
8
- var url;
9
- try {
10
- var xhrCallback = function() {
11
- if (xhr.readyState === 4) {
12
- // when a 200 returns, merge current config with what comes back from config, prioritizing user inputted config
13
- if (xhr.status === 200) {
14
- config = mpInstance._Helpers.extend(
15
- {},
16
- config,
17
- JSON.parse(xhr.responseText)
18
- );
19
- completeSDKInitialization(apiKey, config, mpInstance);
20
- mpInstance.Logger.verbose(
21
- 'Successfully received configuration from server'
22
- );
23
- } else {
24
- // if for some reason a 200 doesn't return, then we initialize with the just the passed through config
25
- completeSDKInitialization(apiKey, config, mpInstance);
26
- mpInstance.Logger.verbose(
27
- 'Issue with receiving configuration from server, received HTTP Code of ' +
28
- xhr.status
29
- );
30
- }
31
- }
32
- };
33
-
34
- var xhr = mpInstance._Helpers.createXHR(xhrCallback);
35
- url =
36
- 'https://' +
37
- mpInstance._Store.SDKConfig.configUrl +
38
- apiKey +
39
- '/config?env=';
40
- if (config.isDevelopmentMode) {
41
- url = url + '1';
42
- } else {
43
- url = url + '0';
44
- }
45
-
46
- var dataPlan = config.dataPlan;
47
- if (dataPlan) {
48
- if (dataPlan.planId) {
49
- url = url + '&plan_id=' + dataPlan.planId || '';
50
- }
51
- if (dataPlan.planVersion) {
52
- url = url + '&plan_version=' + dataPlan.planVersion || '';
53
- }
54
- }
55
-
56
- if (xhr) {
57
- xhr.open('get', url);
58
- xhr.send(null);
59
- }
60
- } catch (e) {
61
- completeSDKInitialization(apiKey, config, mpInstance);
62
- mpInstance.Logger.error(
63
- 'Error getting forwarder configuration from mParticle servers.'
64
- );
65
- }
66
- };
67
- }