@mparticle/web-sdk 2.28.0 → 2.28.1
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/dist/mparticle.common.js +407 -23
- package/dist/mparticle.esm.js +407 -23
- package/dist/mparticle.js +453 -41
- package/package.json +1 -1
- package/src/apiClient.ts +43 -42
- package/src/forwarders.js +32 -0
- package/src/persistence.interfaces.ts +2 -2
- package/src/sdkRuntimeModels.ts +1 -0
package/src/apiClient.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import Constants from './constants';
|
|
2
2
|
import Types from './types';
|
|
3
3
|
import { BatchUploader } from './batchUploader';
|
|
4
|
-
import { MParticleWebSDK, SDKEvent } from './sdkRuntimeModels';
|
|
4
|
+
import { MParticleWebSDK, SDKEvent, SDKDataPlan } from './sdkRuntimeModels';
|
|
5
5
|
import KitBlocker from './kitBlocking';
|
|
6
6
|
import { Dictionary, getRampNumber, isEmpty, parseNumber } from './utils';
|
|
7
7
|
import { IUploadObject } from './serverModel';
|
|
8
8
|
import { MPForwarder } from './forwarders.interfaces';
|
|
9
|
-
import { IMParticleUser } from './identity-user-interfaces';
|
|
10
|
-
|
|
11
|
-
export type ForwardingStatsData = Dictionary<any>;
|
|
9
|
+
import { IMParticleUser, ISDKUserAttributes } from './identity-user-interfaces';
|
|
10
|
+
import { AsyncUploader, FetchUploader, XHRUploader } from './uploaders';
|
|
12
11
|
|
|
13
12
|
export interface IAPIClient {
|
|
14
13
|
uploader: BatchUploader | null;
|
|
@@ -18,18 +17,30 @@ export interface IAPIClient {
|
|
|
18
17
|
sendEventToServer: (event: SDKEvent, _options?: Dictionary<any>) => void;
|
|
19
18
|
sendSingleEventToServer: (event: SDKEvent) => void;
|
|
20
19
|
sendBatchForwardingStatsToServer: (
|
|
21
|
-
forwardingStatsData:
|
|
20
|
+
forwardingStatsData: IForwardingStatsData,
|
|
22
21
|
xhr: XMLHttpRequest
|
|
23
22
|
) => void;
|
|
24
|
-
|
|
25
|
-
forwardingStatsData: ForwardingStatsData
|
|
26
|
-
) => void;
|
|
23
|
+
initializeForwarderStatsUploader: () => AsyncUploader;
|
|
27
24
|
prepareForwardingStats: (
|
|
28
25
|
forwarder: MPForwarder,
|
|
29
26
|
event: IUploadObject
|
|
30
27
|
) => void;
|
|
31
28
|
}
|
|
32
29
|
|
|
30
|
+
export interface IForwardingStatsData {
|
|
31
|
+
mid: number; // Module Id
|
|
32
|
+
esid: number; // Event Subscription Id
|
|
33
|
+
n: string; // Event Name
|
|
34
|
+
attrs: ISDKUserAttributes; // User Attributes
|
|
35
|
+
sdk: string; // SDK Version
|
|
36
|
+
dt: number; // Data Type
|
|
37
|
+
et: number; // Event Type
|
|
38
|
+
dbg: boolean; // Development Mode (for debugging in Live Stream)
|
|
39
|
+
ct: number; // Current Timestamp
|
|
40
|
+
eec: number; // Expanded Event Count
|
|
41
|
+
dp: SDKDataPlan; // Data Plan
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
export default function APIClient(
|
|
34
45
|
this: IAPIClient,
|
|
35
46
|
mpInstance: MParticleWebSDK,
|
|
@@ -161,41 +172,26 @@ export default function APIClient(
|
|
|
161
172
|
}
|
|
162
173
|
};
|
|
163
174
|
|
|
164
|
-
this.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (xhr.readyState === 4) {
|
|
170
|
-
if (xhr.status === 202) {
|
|
171
|
-
mpInstance.Logger.verbose(
|
|
172
|
-
'Successfully sent ' +
|
|
173
|
-
xhr.statusText +
|
|
174
|
-
' from server'
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
const xhr = mpInstance._Helpers.createXHR(xhrCallback);
|
|
180
|
-
url = mpInstance._Helpers.createServiceUrl(
|
|
181
|
-
mpInstance._Store.SDKConfig.v1SecureServiceUrl,
|
|
182
|
-
mpInstance._Store.devToken
|
|
183
|
-
);
|
|
184
|
-
data = forwardingStatsData;
|
|
175
|
+
this.initializeForwarderStatsUploader = (): AsyncUploader => {
|
|
176
|
+
const {
|
|
177
|
+
v1SecureServiceUrl: forwardingDomain,
|
|
178
|
+
} = mpInstance._Store.SDKConfig;
|
|
179
|
+
const { devToken } = mpInstance._Store;
|
|
185
180
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
);
|
|
194
|
-
}
|
|
181
|
+
const uploadUrl: string = `https://${forwardingDomain}${devToken}/Forwarding`;
|
|
182
|
+
|
|
183
|
+
const uploader: AsyncUploader = window.fetch
|
|
184
|
+
? new FetchUploader(uploadUrl)
|
|
185
|
+
: new XHRUploader(uploadUrl);
|
|
186
|
+
|
|
187
|
+
return uploader;
|
|
195
188
|
};
|
|
196
189
|
|
|
197
|
-
this.prepareForwardingStats = function(
|
|
198
|
-
|
|
190
|
+
this.prepareForwardingStats = function(
|
|
191
|
+
forwarder: MPForwarder,
|
|
192
|
+
event:SDKEvent,
|
|
193
|
+
) : void {
|
|
194
|
+
let forwardingStatsData: IForwardingStatsData;
|
|
199
195
|
const queue = mpInstance._Forwarders.getForwarderStatsQueue();
|
|
200
196
|
|
|
201
197
|
if (forwarder && forwarder.isVisible) {
|
|
@@ -212,6 +208,11 @@ export default function APIClient(
|
|
|
212
208
|
eec: event.ExpandedEventCount,
|
|
213
209
|
dp: event.DataPlan,
|
|
214
210
|
};
|
|
211
|
+
|
|
212
|
+
const {
|
|
213
|
+
sendSingleForwardingStatsToServer,
|
|
214
|
+
setForwarderStatsQueue,
|
|
215
|
+
} = mpInstance._Forwarders;
|
|
215
216
|
|
|
216
217
|
if (
|
|
217
218
|
mpInstance._Helpers.getFeatureFlag(
|
|
@@ -219,9 +220,9 @@ export default function APIClient(
|
|
|
219
220
|
)
|
|
220
221
|
) {
|
|
221
222
|
queue.push(forwardingStatsData);
|
|
222
|
-
|
|
223
|
+
setForwarderStatsQueue(queue);
|
|
223
224
|
} else {
|
|
224
|
-
|
|
225
|
+
sendSingleForwardingStatsToServer(forwardingStatsData);
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
};
|
package/src/forwarders.js
CHANGED
|
@@ -3,11 +3,16 @@ import filteredMparticleUser from './filteredMparticleUser';
|
|
|
3
3
|
import { isEmpty } from './utils';
|
|
4
4
|
import KitFilterHelper from './kitFilterHelper';
|
|
5
5
|
import Constants from './constants';
|
|
6
|
+
import APIClient from './apiClient';
|
|
6
7
|
|
|
7
8
|
const { Modify, Identify, Login, Logout } = Constants.IdentityMethods;
|
|
8
9
|
|
|
9
10
|
export default function Forwarders(mpInstance, kitBlocker) {
|
|
10
11
|
var self = this;
|
|
12
|
+
this.forwarderStatsUploader = new APIClient(
|
|
13
|
+
mpInstance,
|
|
14
|
+
kitBlocker
|
|
15
|
+
).initializeForwarderStatsUploader();
|
|
11
16
|
|
|
12
17
|
const UserAttributeActionTypes = {
|
|
13
18
|
setUserAttribute: 'setUserAttribute',
|
|
@@ -771,4 +776,31 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
771
776
|
);
|
|
772
777
|
}
|
|
773
778
|
};
|
|
779
|
+
|
|
780
|
+
this.sendSingleForwardingStatsToServer = async forwardingStatsData => {
|
|
781
|
+
// https://go.mparticle.com/work/SQDSDKS-6568
|
|
782
|
+
const fetchPayload = {
|
|
783
|
+
method: 'post',
|
|
784
|
+
body: JSON.stringify(forwardingStatsData),
|
|
785
|
+
headers: {
|
|
786
|
+
Accept: 'text/plain;charset=UTF-8',
|
|
787
|
+
'Content-Type': 'text/plain;charset=UTF-8',
|
|
788
|
+
},
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
const response = await this.forwarderStatsUploader.upload(fetchPayload);
|
|
792
|
+
|
|
793
|
+
let message;
|
|
794
|
+
// This is a fire and forget, so we only need to log the response based on the code, and not return any response body
|
|
795
|
+
if (response.status === 202) {
|
|
796
|
+
// https://go.mparticle.com/work/SQDSDKS-6670
|
|
797
|
+
message = 'Successfully sent forwarding stats to mParticle Servers';
|
|
798
|
+
} else {
|
|
799
|
+
message =
|
|
800
|
+
'Issue with forwarding stats to mParticle Servers, received HTTP Code of ' +
|
|
801
|
+
response.statusText;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
mpInstance?.Logger?.verbose(message);
|
|
805
|
+
};
|
|
774
806
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
Product,
|
|
6
6
|
UserIdentities,
|
|
7
7
|
} from '@mparticle/web-sdk';
|
|
8
|
-
import {
|
|
8
|
+
import { IForwardingStatsData } from './apiClient';
|
|
9
9
|
import {
|
|
10
10
|
IntegrationAttributes,
|
|
11
11
|
ServerSettings,
|
|
@@ -18,7 +18,7 @@ import { UserAttributes } from './identity-user-interfaces';
|
|
|
18
18
|
export type UploadsTable = Dictionary<any>;
|
|
19
19
|
export interface iForwardingStatsBatches {
|
|
20
20
|
uploadsTable: UploadsTable;
|
|
21
|
-
forwardingStatsEventQueue:
|
|
21
|
+
forwardingStatsEventQueue: IForwardingStatsData[];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export interface IGlobalStoreV2MinifiedKeys {
|