@amplitude/analytics-react-native 0.0.1-dev.6 → 0.0.1-dev.9
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/README.md +150 -0
- package/android/src/main/java/com/amplitude/reactnative/AmplitudeReactNativeModule.kt +5 -5
- package/ios/AmplitudeReactNative.swift +4 -4
- package/lib/commonjs/attribution/campaign-tracker.js +1 -1
- package/lib/commonjs/attribution/campaign-tracker.js.map +1 -1
- package/lib/commonjs/config.js +2 -22
- package/lib/commonjs/config.js.map +1 -1
- package/lib/commonjs/index.js +2 -16
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/plugins/context.js +4 -4
- package/lib/commonjs/plugins/context.js.map +1 -1
- package/lib/commonjs/plugins/identity.js +40 -0
- package/lib/commonjs/plugins/identity.js.map +1 -0
- package/lib/commonjs/react-native-client.js +23 -57
- package/lib/commonjs/react-native-client.js.map +1 -1
- package/lib/commonjs/storage/cookie.js +1 -6
- package/lib/commonjs/storage/cookie.js.map +1 -1
- package/lib/commonjs/utils/analytics-connector.js +15 -0
- package/lib/commonjs/utils/analytics-connector.js.map +1 -0
- package/lib/commonjs/utils/query-params.js +1 -6
- package/lib/commonjs/utils/query-params.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/attribution/campaign-tracker.js +1 -1
- package/lib/module/attribution/campaign-tracker.js.map +1 -1
- package/lib/module/config.js +1 -15
- package/lib/module/config.js.map +1 -1
- package/lib/module/index.js +3 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/plugins/context.js +4 -4
- package/lib/module/plugins/context.js.map +1 -1
- package/lib/module/plugins/identity.js +29 -0
- package/lib/module/plugins/identity.js.map +1 -0
- package/lib/module/react-native-client.js +21 -55
- package/lib/module/react-native-client.js.map +1 -1
- package/lib/module/storage/cookie.js +1 -6
- package/lib/module/storage/cookie.js.map +1 -1
- package/lib/module/utils/analytics-connector.js +5 -0
- package/lib/module/utils/analytics-connector.js.map +1 -0
- package/lib/module/utils/query-params.js +1 -6
- package/lib/module/utils/query-params.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/config.d.ts +1 -4
- package/lib/typescript/config.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/plugins/context.d.ts +5 -5
- package/lib/typescript/plugins/context.d.ts.map +1 -1
- package/lib/typescript/plugins/identity.d.ts +9 -0
- package/lib/typescript/plugins/identity.d.ts.map +1 -0
- package/lib/typescript/react-native-client.d.ts +7 -26
- package/lib/typescript/react-native-client.d.ts.map +1 -1
- package/lib/typescript/storage/cookie.d.ts.map +1 -1
- package/lib/typescript/utils/analytics-connector.d.ts +3 -0
- package/lib/typescript/utils/analytics-connector.d.ts.map +1 -0
- package/lib/typescript/utils/query-params.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -2
- package/src/attribution/campaign-tracker.ts +1 -1
- package/src/config.ts +1 -14
- package/src/index.ts +1 -4
- package/src/plugins/context.ts +9 -9
- package/src/plugins/identity.ts +21 -0
- package/src/react-native-client.ts +26 -60
- package/src/storage/cookie.ts +1 -4
- package/src/utils/analytics-connector.ts +5 -0
- package/src/utils/query-params.ts +1 -4
- package/src/version.ts +1 -1
- package/lib/commonjs/constants.js +0 -31
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/transports/send-beacon.js +0 -43
- package/lib/commonjs/transports/send-beacon.js.map +0 -1
- package/lib/commonjs/transports/xhr.js +0 -54
- package/lib/commonjs/transports/xhr.js.map +0 -1
- package/lib/commonjs/utils/snippet-helper.js +0 -56
- package/lib/commonjs/utils/snippet-helper.js.map +0 -1
- package/lib/module/constants.js +0 -13
- package/lib/module/constants.js.map +0 -1
- package/lib/module/transports/send-beacon.js +0 -33
- package/lib/module/transports/send-beacon.js.map +0 -1
- package/lib/module/transports/xhr.js +0 -44
- package/lib/module/transports/xhr.js.map +0 -1
- package/lib/module/utils/snippet-helper.js +0 -41
- package/lib/module/utils/snippet-helper.js.map +0 -1
- package/lib/typescript/constants.d.ts +0 -13
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/transports/send-beacon.d.ts +0 -6
- package/lib/typescript/transports/send-beacon.d.ts.map +0 -1
- package/lib/typescript/transports/xhr.d.ts +0 -7
- package/lib/typescript/transports/xhr.d.ts.map +0 -1
- package/lib/typescript/utils/snippet-helper.d.ts +0 -16
- package/lib/typescript/utils/snippet-helper.d.ts.map +0 -1
- package/src/constants.ts +0 -14
- package/src/transports/send-beacon.ts +0 -34
- package/src/transports/xhr.ts +0 -36
- package/src/utils/snippet-helper.ts +0 -35
package/src/index.ts
CHANGED
|
@@ -14,11 +14,8 @@ export {
|
|
|
14
14
|
setGroup,
|
|
15
15
|
setOptOut,
|
|
16
16
|
setSessionId,
|
|
17
|
-
setTransport,
|
|
18
17
|
setUserId,
|
|
19
18
|
track,
|
|
20
19
|
} from './react-native-client';
|
|
21
|
-
export { runQueuedFunctions } from './utils/snippet-helper';
|
|
22
20
|
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
23
|
-
|
|
24
|
-
export { Types };
|
|
21
|
+
export * as Types from '@amplitude/analytics-types';
|
package/src/plugins/context.ts
CHANGED
|
@@ -12,11 +12,11 @@ type NativeContext = {
|
|
|
12
12
|
version: string;
|
|
13
13
|
platform: string;
|
|
14
14
|
language: string;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
osName: string;
|
|
16
|
+
osVersion: string;
|
|
17
|
+
deviceBrand: string;
|
|
18
|
+
deviceManufacturer: string;
|
|
19
|
+
deviceModel: string;
|
|
20
20
|
carrier: string;
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -67,10 +67,10 @@ export class Context implements BeforePlugin {
|
|
|
67
67
|
const nativeContext = await this.nativeModule?.getApplicationContext();
|
|
68
68
|
const appVersion = nativeContext?.version || this.config.appVersion;
|
|
69
69
|
const platform = nativeContext?.platform || BROWSER_PLATFORM;
|
|
70
|
-
const osName = nativeContext?.
|
|
71
|
-
const osVersion = nativeContext?.
|
|
72
|
-
const deviceVendor = nativeContext?.
|
|
73
|
-
const deviceModel = nativeContext?.
|
|
70
|
+
const osName = nativeContext?.osName || this.uaResult.browser.name;
|
|
71
|
+
const osVersion = nativeContext?.osVersion || this.uaResult.browser.version;
|
|
72
|
+
const deviceVendor = nativeContext?.deviceManufacturer || this.uaResult.device.vendor;
|
|
73
|
+
const deviceModel = nativeContext?.deviceModel || this.uaResult.device.model || this.uaResult.os.name;
|
|
74
74
|
const language = nativeContext?.language || getLanguage();
|
|
75
75
|
const carrier = nativeContext?.carrier;
|
|
76
76
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BeforePlugin, PluginType, Event, Config } from '@amplitude/analytics-types';
|
|
2
|
+
import { getAnalyticsConnector } from '../utils/analytics-connector';
|
|
3
|
+
|
|
4
|
+
export class IdentityEventSender implements BeforePlugin {
|
|
5
|
+
name = 'identity';
|
|
6
|
+
type = PluginType.BEFORE as const;
|
|
7
|
+
|
|
8
|
+
identityStore = getAnalyticsConnector().identityStore;
|
|
9
|
+
|
|
10
|
+
async execute(context: Event): Promise<Event> {
|
|
11
|
+
const userProperties = context.user_properties as Record<string, any>;
|
|
12
|
+
if (userProperties) {
|
|
13
|
+
this.identityStore.editIdentity().setUserProperties(userProperties).commit();
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setup(_: Config): Promise<undefined> {
|
|
19
|
+
return Promise.resolve(undefined);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { AmplitudeCore, Destination,
|
|
1
|
+
import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';
|
|
2
2
|
import {
|
|
3
3
|
ReactNativeConfig,
|
|
4
4
|
Campaign,
|
|
5
|
-
EventOptions,
|
|
6
|
-
Identify as IIdentify,
|
|
7
|
-
Result,
|
|
8
|
-
Revenue as IRevenue,
|
|
9
|
-
TransportType,
|
|
10
5
|
ReactNativeOptions,
|
|
11
6
|
AdditionalReactNativeOptions,
|
|
12
7
|
AttributionReactNativeOptions,
|
|
13
8
|
} from '@amplitude/analytics-types';
|
|
14
|
-
import { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';
|
|
15
9
|
import { Context } from './plugins/context';
|
|
16
|
-
import { useReactNativeConfig,
|
|
10
|
+
import { useReactNativeConfig, createDeviceId, createFlexibleStorage } from './config';
|
|
17
11
|
import { parseOldCookies } from './cookie-migration';
|
|
18
12
|
import { CampaignTracker } from './attribution/campaign-tracker';
|
|
19
13
|
import { isNative } from './utils/platform';
|
|
14
|
+
import { IdentityEventSender } from './plugins/identity';
|
|
15
|
+
import { getAnalyticsConnector } from './utils/analytics-connector';
|
|
20
16
|
|
|
21
17
|
export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
22
18
|
async init(apiKey: string, userId?: string, options?: ReactNativeOptions & AdditionalReactNativeOptions) {
|
|
@@ -46,9 +42,19 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
46
42
|
isNewSession = true;
|
|
47
43
|
}
|
|
48
44
|
|
|
45
|
+
const connector = getAnalyticsConnector();
|
|
46
|
+
connector.eventBridge.setEventReceiver((event) => {
|
|
47
|
+
void this.track(event.eventType, event.eventProperties);
|
|
48
|
+
});
|
|
49
|
+
connector.identityStore.setIdentity({
|
|
50
|
+
userId: this.config.userId,
|
|
51
|
+
deviceId: this.config.deviceId,
|
|
52
|
+
});
|
|
53
|
+
|
|
49
54
|
// Step 4: Install plugins
|
|
50
55
|
// Do not track any events before this
|
|
51
56
|
await this.add(new Context());
|
|
57
|
+
await this.add(new IdentityEventSender());
|
|
52
58
|
await this.add(new Destination());
|
|
53
59
|
|
|
54
60
|
// Step 5: Track attributions
|
|
@@ -79,6 +85,12 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
79
85
|
|
|
80
86
|
setUserId(userId: string | undefined) {
|
|
81
87
|
this.config.userId = userId;
|
|
88
|
+
getAnalyticsConnector()
|
|
89
|
+
.identityStore.editIdentity()
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
.setUserId(userId)
|
|
93
|
+
.commit();
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
getDeviceId() {
|
|
@@ -87,6 +99,12 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
87
99
|
|
|
88
100
|
setDeviceId(deviceId: string) {
|
|
89
101
|
this.config.deviceId = deviceId;
|
|
102
|
+
getAnalyticsConnector()
|
|
103
|
+
.identityStore.editIdentity()
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
.setDeviceId(deviceId)
|
|
107
|
+
.commit();
|
|
90
108
|
}
|
|
91
109
|
|
|
92
110
|
regenerateDeviceId() {
|
|
@@ -105,42 +123,6 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
105
123
|
setOptOut(optOut: boolean) {
|
|
106
124
|
this.config.optOut = optOut;
|
|
107
125
|
}
|
|
108
|
-
|
|
109
|
-
setTransport(transport: TransportType) {
|
|
110
|
-
this.config.transportProvider = createTransport(transport);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
identify(identify: IIdentify, eventOptions?: EventOptions): Promise<Result> {
|
|
114
|
-
if (isInstanceProxy(identify)) {
|
|
115
|
-
const queue = identify._q;
|
|
116
|
-
identify._q = [];
|
|
117
|
-
identify = convertProxyObjectToRealObject(new Identify(), queue);
|
|
118
|
-
}
|
|
119
|
-
return super.identify(identify, eventOptions);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
groupIdentify(
|
|
123
|
-
groupType: string,
|
|
124
|
-
groupName: string | string[],
|
|
125
|
-
identify: IIdentify,
|
|
126
|
-
eventOptions?: EventOptions,
|
|
127
|
-
): Promise<Result> {
|
|
128
|
-
if (isInstanceProxy(identify)) {
|
|
129
|
-
const queue = identify._q;
|
|
130
|
-
identify._q = [];
|
|
131
|
-
identify = convertProxyObjectToRealObject(new Identify(), queue);
|
|
132
|
-
}
|
|
133
|
-
return super.groupIdentify(groupType, groupName, identify, eventOptions);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
revenue(revenue: IRevenue, eventOptions?: EventOptions) {
|
|
137
|
-
if (isInstanceProxy(revenue)) {
|
|
138
|
-
const queue = revenue._q;
|
|
139
|
-
revenue._q = [];
|
|
140
|
-
revenue = convertProxyObjectToRealObject(new Revenue(), queue);
|
|
141
|
-
}
|
|
142
|
-
return super.revenue(revenue, eventOptions);
|
|
143
|
-
}
|
|
144
126
|
}
|
|
145
127
|
|
|
146
128
|
const client = new AmplitudeReactNative();
|
|
@@ -336,22 +318,6 @@ export const setSessionId = client.setSessionId.bind(client);
|
|
|
336
318
|
*/
|
|
337
319
|
export const setOptOut = client.setOptOut.bind(client);
|
|
338
320
|
|
|
339
|
-
/**
|
|
340
|
-
* Sets the network transport type for events.
|
|
341
|
-
*
|
|
342
|
-
* ```typescript
|
|
343
|
-
* // Use Fetch API
|
|
344
|
-
* setTransport('fetch');
|
|
345
|
-
*
|
|
346
|
-
* // Use XMLHttpRequest API
|
|
347
|
-
* setTransport('xhr');
|
|
348
|
-
*
|
|
349
|
-
* // Use navigator.sendBeacon API
|
|
350
|
-
* setTransport('beacon');
|
|
351
|
-
* ```
|
|
352
|
-
*/
|
|
353
|
-
export const setTransport = client.setTransport.bind(client);
|
|
354
|
-
|
|
355
321
|
/**
|
|
356
322
|
* Flush and send all the events which haven't been sent.
|
|
357
323
|
*
|
package/src/storage/cookie.ts
CHANGED
|
@@ -9,11 +9,8 @@ export class CookieStorage<T> implements Storage<T> {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async isEnabled(): Promise<boolean> {
|
|
12
|
-
if (isNative()) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
12
|
/* istanbul ignore if */
|
|
16
|
-
if (typeof window === 'undefined') {
|
|
13
|
+
if (isNative() || typeof window === 'undefined') {
|
|
17
14
|
return false;
|
|
18
15
|
}
|
|
19
16
|
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { isNative } from './platform';
|
|
2
2
|
|
|
3
3
|
export const getQueryParams = (): Record<string, string | undefined> => {
|
|
4
|
-
if (isNative()) {
|
|
5
|
-
return {};
|
|
6
|
-
}
|
|
7
4
|
/* istanbul ignore if */
|
|
8
|
-
if (typeof window === 'undefined') {
|
|
5
|
+
if (isNative() || typeof window === 'undefined') {
|
|
9
6
|
return {};
|
|
10
7
|
}
|
|
11
8
|
const pairs = window.location.search.substring(1).split('&').filter(Boolean);
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.0.1-dev.
|
|
1
|
+
export const VERSION = '0.0.1-dev.9';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.UTM_TERM = exports.UTM_SOURCE = exports.UTM_MEDIUM = exports.UTM_CONTENT = exports.UTM_CAMPAIGN = exports.UTMZ_TERM = exports.UTMZ_SOURCE = exports.UTMZ_MEDIUM = exports.UTMZ_CONTENT = exports.UTMZ_CAMPAIGN = exports.GCLID = exports.FBCLID = void 0;
|
|
7
|
-
const UTM_SOURCE = 'utm_source';
|
|
8
|
-
exports.UTM_SOURCE = UTM_SOURCE;
|
|
9
|
-
const UTM_MEDIUM = 'utm_medium';
|
|
10
|
-
exports.UTM_MEDIUM = UTM_MEDIUM;
|
|
11
|
-
const UTM_CAMPAIGN = 'utm_campaign';
|
|
12
|
-
exports.UTM_CAMPAIGN = UTM_CAMPAIGN;
|
|
13
|
-
const UTM_TERM = 'utm_term';
|
|
14
|
-
exports.UTM_TERM = UTM_TERM;
|
|
15
|
-
const UTM_CONTENT = 'utm_content';
|
|
16
|
-
exports.UTM_CONTENT = UTM_CONTENT;
|
|
17
|
-
const UTMZ_SOURCE = 'utmcsr';
|
|
18
|
-
exports.UTMZ_SOURCE = UTMZ_SOURCE;
|
|
19
|
-
const UTMZ_MEDIUM = 'utmcmd';
|
|
20
|
-
exports.UTMZ_MEDIUM = UTMZ_MEDIUM;
|
|
21
|
-
const UTMZ_CAMPAIGN = 'utmccn';
|
|
22
|
-
exports.UTMZ_CAMPAIGN = UTMZ_CAMPAIGN;
|
|
23
|
-
const UTMZ_TERM = 'utmctr';
|
|
24
|
-
exports.UTMZ_TERM = UTMZ_TERM;
|
|
25
|
-
const UTMZ_CONTENT = 'utmcct';
|
|
26
|
-
exports.UTMZ_CONTENT = UTMZ_CONTENT;
|
|
27
|
-
const GCLID = 'gclid';
|
|
28
|
-
exports.GCLID = GCLID;
|
|
29
|
-
const FBCLID = 'fbclid';
|
|
30
|
-
exports.FBCLID = FBCLID;
|
|
31
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["UTM_SOURCE","UTM_MEDIUM","UTM_CAMPAIGN","UTM_TERM","UTM_CONTENT","UTMZ_SOURCE","UTMZ_MEDIUM","UTMZ_CAMPAIGN","UTMZ_TERM","UTMZ_CONTENT","GCLID","FBCLID"],"sources":["constants.ts"],"sourcesContent":["export const UTM_SOURCE = 'utm_source';\nexport const UTM_MEDIUM = 'utm_medium';\nexport const UTM_CAMPAIGN = 'utm_campaign';\nexport const UTM_TERM = 'utm_term';\nexport const UTM_CONTENT = 'utm_content';\n\nexport const UTMZ_SOURCE = 'utmcsr';\nexport const UTMZ_MEDIUM = 'utmcmd';\nexport const UTMZ_CAMPAIGN = 'utmccn';\nexport const UTMZ_TERM = 'utmctr';\nexport const UTMZ_CONTENT = 'utmcct';\n\nexport const GCLID = 'gclid';\nexport const FBCLID = 'fbclid';\n"],"mappings":";;;;;;AAAO,MAAMA,UAAU,GAAG,YAAnB;;AACA,MAAMC,UAAU,GAAG,YAAnB;;AACA,MAAMC,YAAY,GAAG,cAArB;;AACA,MAAMC,QAAQ,GAAG,UAAjB;;AACA,MAAMC,WAAW,GAAG,aAApB;;AAEA,MAAMC,WAAW,GAAG,QAApB;;AACA,MAAMC,WAAW,GAAG,QAApB;;AACA,MAAMC,aAAa,GAAG,QAAtB;;AACA,MAAMC,SAAS,GAAG,QAAlB;;AACA,MAAMC,YAAY,GAAG,QAArB;;AAEA,MAAMC,KAAK,GAAG,OAAd;;AACA,MAAMC,MAAM,GAAG,QAAf"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SendBeaconTransport = void 0;
|
|
7
|
-
|
|
8
|
-
var _analyticsCore = require("@amplitude/analytics-core");
|
|
9
|
-
|
|
10
|
-
class SendBeaconTransport extends _analyticsCore.BaseTransport {
|
|
11
|
-
async send(serverUrl, payload) {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
/* istanbul ignore if */
|
|
14
|
-
if (typeof window === 'undefined' || typeof window.navigator === 'undefined' || typeof window.navigator.sendBeacon === 'undefined') {
|
|
15
|
-
throw new Error('SendBeaconTransport is not supported');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const data = JSON.stringify(payload);
|
|
20
|
-
const success = window.navigator.sendBeacon(serverUrl, JSON.stringify(payload));
|
|
21
|
-
|
|
22
|
-
if (success) {
|
|
23
|
-
return resolve(this.buildResponse({
|
|
24
|
-
code: 200,
|
|
25
|
-
events_ingested: payload.events.length,
|
|
26
|
-
payload_size_bytes: data.length,
|
|
27
|
-
server_upload_time: Date.now()
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return resolve(this.buildResponse({
|
|
32
|
-
code: 500
|
|
33
|
-
}));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
exports.SendBeaconTransport = SendBeaconTransport;
|
|
43
|
-
//# sourceMappingURL=send-beacon.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["SendBeaconTransport","BaseTransport","send","serverUrl","payload","Promise","resolve","reject","window","navigator","sendBeacon","Error","data","JSON","stringify","success","buildResponse","code","events_ingested","events","length","payload_size_bytes","server_upload_time","Date","now","e"],"sources":["send-beacon.ts"],"sourcesContent":["import { BaseTransport } from '@amplitude/analytics-core';\nimport { Payload, Response, Transport } from '@amplitude/analytics-types';\n\nexport class SendBeaconTransport extends BaseTransport implements Transport {\n async send(serverUrl: string, payload: Payload): Promise<Response | null> {\n return new Promise((resolve, reject) => {\n /* istanbul ignore if */\n if (\n typeof window === 'undefined' ||\n typeof window.navigator === 'undefined' ||\n typeof window.navigator.sendBeacon === 'undefined'\n ) {\n throw new Error('SendBeaconTransport is not supported');\n }\n try {\n const data = JSON.stringify(payload);\n const success = window.navigator.sendBeacon(serverUrl, JSON.stringify(payload));\n if (success) {\n return resolve(\n this.buildResponse({\n code: 200,\n events_ingested: payload.events.length,\n payload_size_bytes: data.length,\n server_upload_time: Date.now(),\n }),\n );\n }\n return resolve(this.buildResponse({ code: 500 }));\n } catch (e) {\n reject(e);\n }\n });\n }\n}\n"],"mappings":";;;;;;;AAAA;;AAGO,MAAMA,mBAAN,SAAkCC,4BAAlC,CAAqE;EAChE,MAAJC,IAAI,CAACC,SAAD,EAAoBC,OAApB,EAAgE;IACxE,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MACtC;MACA,IACE,OAAOC,MAAP,KAAkB,WAAlB,IACA,OAAOA,MAAM,CAACC,SAAd,KAA4B,WAD5B,IAEA,OAAOD,MAAM,CAACC,SAAP,CAAiBC,UAAxB,KAAuC,WAHzC,EAIE;QACA,MAAM,IAAIC,KAAJ,CAAU,sCAAV,CAAN;MACD;;MACD,IAAI;QACF,MAAMC,IAAI,GAAGC,IAAI,CAACC,SAAL,CAAeV,OAAf,CAAb;QACA,MAAMW,OAAO,GAAGP,MAAM,CAACC,SAAP,CAAiBC,UAAjB,CAA4BP,SAA5B,EAAuCU,IAAI,CAACC,SAAL,CAAeV,OAAf,CAAvC,CAAhB;;QACA,IAAIW,OAAJ,EAAa;UACX,OAAOT,OAAO,CACZ,KAAKU,aAAL,CAAmB;YACjBC,IAAI,EAAE,GADW;YAEjBC,eAAe,EAAEd,OAAO,CAACe,MAAR,CAAeC,MAFf;YAGjBC,kBAAkB,EAAET,IAAI,CAACQ,MAHR;YAIjBE,kBAAkB,EAAEC,IAAI,CAACC,GAAL;UAJH,CAAnB,CADY,CAAd;QAQD;;QACD,OAAOlB,OAAO,CAAC,KAAKU,aAAL,CAAmB;UAAEC,IAAI,EAAE;QAAR,CAAnB,CAAD,CAAd;MACD,CAdD,CAcE,OAAOQ,CAAP,EAAU;QACVlB,MAAM,CAACkB,CAAD,CAAN;MACD;IACF,CA1BM,CAAP;EA2BD;;AA7ByE"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.XHRTransport = void 0;
|
|
7
|
-
|
|
8
|
-
var _analyticsCore = require("@amplitude/analytics-core");
|
|
9
|
-
|
|
10
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
-
|
|
12
|
-
class XHRTransport extends _analyticsCore.BaseTransport {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
|
|
16
|
-
_defineProperty(this, "state", {
|
|
17
|
-
done: 4
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async send(serverUrl, payload) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
/* istanbul ignore if */
|
|
24
|
-
if (typeof XMLHttpRequest === 'undefined') {
|
|
25
|
-
reject(new Error('XHRTransport is not supported.'));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const xhr = new XMLHttpRequest();
|
|
29
|
-
xhr.open('POST', serverUrl, true);
|
|
30
|
-
|
|
31
|
-
xhr.onreadystatechange = () => {
|
|
32
|
-
if (xhr.readyState === this.state.done) {
|
|
33
|
-
try {
|
|
34
|
-
const responsePayload = xhr.responseText; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
35
|
-
|
|
36
|
-
const parsedResponsePayload = JSON.parse(responsePayload);
|
|
37
|
-
const result = this.buildResponse(parsedResponsePayload);
|
|
38
|
-
resolve(result);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
reject(e);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
46
|
-
xhr.setRequestHeader('Accept', '*/*');
|
|
47
|
-
xhr.send(JSON.stringify(payload));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.XHRTransport = XHRTransport;
|
|
54
|
-
//# sourceMappingURL=xhr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["XHRTransport","BaseTransport","done","send","serverUrl","payload","Promise","resolve","reject","XMLHttpRequest","Error","xhr","open","onreadystatechange","readyState","state","responsePayload","responseText","parsedResponsePayload","JSON","parse","result","buildResponse","e","setRequestHeader","stringify"],"sources":["xhr.ts"],"sourcesContent":["import { BaseTransport } from '@amplitude/analytics-core';\nimport { Payload, Response, Transport } from '@amplitude/analytics-types';\n\nexport class XHRTransport extends BaseTransport implements Transport {\n private state = {\n done: 4,\n };\n\n async send(serverUrl: string, payload: Payload): Promise<Response | null> {\n return new Promise((resolve, reject) => {\n /* istanbul ignore if */\n if (typeof XMLHttpRequest === 'undefined') {\n reject(new Error('XHRTransport is not supported.'));\n }\n\n const xhr = new XMLHttpRequest();\n xhr.open('POST', serverUrl, true);\n xhr.onreadystatechange = () => {\n if (xhr.readyState === this.state.done) {\n try {\n const responsePayload = xhr.responseText;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n const result = this.buildResponse(parsedResponsePayload);\n resolve(result);\n } catch (e) {\n reject(e);\n }\n }\n };\n xhr.setRequestHeader('Content-Type', 'application/json');\n xhr.setRequestHeader('Accept', '*/*');\n xhr.send(JSON.stringify(payload));\n });\n }\n}\n"],"mappings":";;;;;;;AAAA;;;;AAGO,MAAMA,YAAN,SAA2BC,4BAA3B,CAA8D;EAAA;IAAA;;IAAA,+BACnD;MACdC,IAAI,EAAE;IADQ,CADmD;EAAA;;EAKzD,MAAJC,IAAI,CAACC,SAAD,EAAoBC,OAApB,EAAgE;IACxE,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MACtC;MACA,IAAI,OAAOC,cAAP,KAA0B,WAA9B,EAA2C;QACzCD,MAAM,CAAC,IAAIE,KAAJ,CAAU,gCAAV,CAAD,CAAN;MACD;;MAED,MAAMC,GAAG,GAAG,IAAIF,cAAJ,EAAZ;MACAE,GAAG,CAACC,IAAJ,CAAS,MAAT,EAAiBR,SAAjB,EAA4B,IAA5B;;MACAO,GAAG,CAACE,kBAAJ,GAAyB,MAAM;QAC7B,IAAIF,GAAG,CAACG,UAAJ,KAAmB,KAAKC,KAAL,CAAWb,IAAlC,EAAwC;UACtC,IAAI;YACF,MAAMc,eAAe,GAAGL,GAAG,CAACM,YAA5B,CADE,CAEF;;YACA,MAAMC,qBAA0C,GAAGC,IAAI,CAACC,KAAL,CAAWJ,eAAX,CAAnD;YACA,MAAMK,MAAM,GAAG,KAAKC,aAAL,CAAmBJ,qBAAnB,CAAf;YACAX,OAAO,CAACc,MAAD,CAAP;UACD,CAND,CAME,OAAOE,CAAP,EAAU;YACVf,MAAM,CAACe,CAAD,CAAN;UACD;QACF;MACF,CAZD;;MAaAZ,GAAG,CAACa,gBAAJ,CAAqB,cAArB,EAAqC,kBAArC;MACAb,GAAG,CAACa,gBAAJ,CAAqB,QAArB,EAA+B,KAA/B;MACAb,GAAG,CAACR,IAAJ,CAASgB,IAAI,CAACM,SAAL,CAAepB,OAAf,CAAT;IACD,CAxBM,CAAP;EAyBD;;AA/BkE"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.runQueuedFunctions = exports.isInstanceProxy = exports.convertProxyObjectToRealObject = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Applies the proxied functions on the proxied amplitude snippet to an instance of the real object.
|
|
10
|
-
* @ignore
|
|
11
|
-
*/
|
|
12
|
-
const runQueuedFunctions = (instance, queue) => {
|
|
13
|
-
convertProxyObjectToRealObject(instance, queue);
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Applies the proxied functions on the proxied object to an instance of the real object.
|
|
17
|
-
* Used to convert proxied Identify and Revenue objects.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exports.runQueuedFunctions = runQueuedFunctions;
|
|
22
|
-
|
|
23
|
-
const convertProxyObjectToRealObject = (instance, queue) => {
|
|
24
|
-
for (let i = 0; i < queue.length; i++) {
|
|
25
|
-
const {
|
|
26
|
-
name,
|
|
27
|
-
args,
|
|
28
|
-
resolve
|
|
29
|
-
} = queue[i];
|
|
30
|
-
const fn = instance && instance[name];
|
|
31
|
-
|
|
32
|
-
if (typeof fn === 'function') {
|
|
33
|
-
const result = fn.apply(instance, args);
|
|
34
|
-
|
|
35
|
-
if (typeof resolve === 'function') {
|
|
36
|
-
resolve(result === null || result === void 0 ? void 0 : result.promise);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return instance;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Check if the param is snippet proxy
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
exports.convertProxyObjectToRealObject = convertProxyObjectToRealObject;
|
|
49
|
-
|
|
50
|
-
const isInstanceProxy = instance => {
|
|
51
|
-
const instanceProxy = instance;
|
|
52
|
-
return instanceProxy && instanceProxy._q !== undefined;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
exports.isInstanceProxy = isInstanceProxy;
|
|
56
|
-
//# sourceMappingURL=snippet-helper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["runQueuedFunctions","instance","queue","convertProxyObjectToRealObject","i","length","name","args","resolve","fn","result","apply","promise","isInstanceProxy","instanceProxy","_q","undefined"],"sources":["snippet-helper.ts"],"sourcesContent":["import { AmplitudeReturn, InstanceProxy, QueueProxy, Result } from '@amplitude/analytics-types';\n\n/**\n * Applies the proxied functions on the proxied amplitude snippet to an instance of the real object.\n * @ignore\n */\nexport const runQueuedFunctions = (instance: object, queue: QueueProxy) => {\n convertProxyObjectToRealObject(instance, queue);\n};\n\n/**\n * Applies the proxied functions on the proxied object to an instance of the real object.\n * Used to convert proxied Identify and Revenue objects.\n */\nexport const convertProxyObjectToRealObject = <T>(instance: T, queue: QueueProxy): T => {\n for (let i = 0; i < queue.length; i++) {\n const { name, args, resolve } = queue[i];\n const fn = instance && instance[name as keyof T];\n if (typeof fn === 'function') {\n const result = fn.apply(instance, args) as AmplitudeReturn<Promise<Result>>;\n if (typeof resolve === 'function') {\n resolve(result?.promise);\n }\n }\n }\n return instance;\n};\n\n/**\n * Check if the param is snippet proxy\n */\nexport const isInstanceProxy = (instance: unknown): instance is InstanceProxy => {\n const instanceProxy = instance as InstanceProxy;\n return instanceProxy && instanceProxy._q !== undefined;\n};\n"],"mappings":";;;;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAACC,QAAD,EAAmBC,KAAnB,KAAyC;EACzEC,8BAA8B,CAACF,QAAD,EAAWC,KAAX,CAA9B;AACD,CAFM;AAIP;AACA;AACA;AACA;;;;;AACO,MAAMC,8BAA8B,GAAG,CAAIF,QAAJ,EAAiBC,KAAjB,KAA0C;EACtF,KAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,KAAK,CAACG,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;IACrC,MAAM;MAAEE,IAAF;MAAQC,IAAR;MAAcC;IAAd,IAA0BN,KAAK,CAACE,CAAD,CAArC;IACA,MAAMK,EAAE,GAAGR,QAAQ,IAAIA,QAAQ,CAACK,IAAD,CAA/B;;IACA,IAAI,OAAOG,EAAP,KAAc,UAAlB,EAA8B;MAC5B,MAAMC,MAAM,GAAGD,EAAE,CAACE,KAAH,CAASV,QAAT,EAAmBM,IAAnB,CAAf;;MACA,IAAI,OAAOC,OAAP,KAAmB,UAAvB,EAAmC;QACjCA,OAAO,CAACE,MAAD,aAACA,MAAD,uBAACA,MAAM,CAAEE,OAAT,CAAP;MACD;IACF;EACF;;EACD,OAAOX,QAAP;AACD,CAZM;AAcP;AACA;AACA;;;;;AACO,MAAMY,eAAe,GAAIZ,QAAD,IAAkD;EAC/E,MAAMa,aAAa,GAAGb,QAAtB;EACA,OAAOa,aAAa,IAAIA,aAAa,CAACC,EAAd,KAAqBC,SAA7C;AACD,CAHM"}
|
package/lib/module/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const UTM_SOURCE = 'utm_source';
|
|
2
|
-
export const UTM_MEDIUM = 'utm_medium';
|
|
3
|
-
export const UTM_CAMPAIGN = 'utm_campaign';
|
|
4
|
-
export const UTM_TERM = 'utm_term';
|
|
5
|
-
export const UTM_CONTENT = 'utm_content';
|
|
6
|
-
export const UTMZ_SOURCE = 'utmcsr';
|
|
7
|
-
export const UTMZ_MEDIUM = 'utmcmd';
|
|
8
|
-
export const UTMZ_CAMPAIGN = 'utmccn';
|
|
9
|
-
export const UTMZ_TERM = 'utmctr';
|
|
10
|
-
export const UTMZ_CONTENT = 'utmcct';
|
|
11
|
-
export const GCLID = 'gclid';
|
|
12
|
-
export const FBCLID = 'fbclid';
|
|
13
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["UTM_SOURCE","UTM_MEDIUM","UTM_CAMPAIGN","UTM_TERM","UTM_CONTENT","UTMZ_SOURCE","UTMZ_MEDIUM","UTMZ_CAMPAIGN","UTMZ_TERM","UTMZ_CONTENT","GCLID","FBCLID"],"sources":["constants.ts"],"sourcesContent":["export const UTM_SOURCE = 'utm_source';\nexport const UTM_MEDIUM = 'utm_medium';\nexport const UTM_CAMPAIGN = 'utm_campaign';\nexport const UTM_TERM = 'utm_term';\nexport const UTM_CONTENT = 'utm_content';\n\nexport const UTMZ_SOURCE = 'utmcsr';\nexport const UTMZ_MEDIUM = 'utmcmd';\nexport const UTMZ_CAMPAIGN = 'utmccn';\nexport const UTMZ_TERM = 'utmctr';\nexport const UTMZ_CONTENT = 'utmcct';\n\nexport const GCLID = 'gclid';\nexport const FBCLID = 'fbclid';\n"],"mappings":"AAAA,OAAO,MAAMA,UAAU,GAAG,YAAnB;AACP,OAAO,MAAMC,UAAU,GAAG,YAAnB;AACP,OAAO,MAAMC,YAAY,GAAG,cAArB;AACP,OAAO,MAAMC,QAAQ,GAAG,UAAjB;AACP,OAAO,MAAMC,WAAW,GAAG,aAApB;AAEP,OAAO,MAAMC,WAAW,GAAG,QAApB;AACP,OAAO,MAAMC,WAAW,GAAG,QAApB;AACP,OAAO,MAAMC,aAAa,GAAG,QAAtB;AACP,OAAO,MAAMC,SAAS,GAAG,QAAlB;AACP,OAAO,MAAMC,YAAY,GAAG,QAArB;AAEP,OAAO,MAAMC,KAAK,GAAG,OAAd;AACP,OAAO,MAAMC,MAAM,GAAG,QAAf"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BaseTransport } from '@amplitude/analytics-core';
|
|
2
|
-
export class SendBeaconTransport extends BaseTransport {
|
|
3
|
-
async send(serverUrl, payload) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
/* istanbul ignore if */
|
|
6
|
-
if (typeof window === 'undefined' || typeof window.navigator === 'undefined' || typeof window.navigator.sendBeacon === 'undefined') {
|
|
7
|
-
throw new Error('SendBeaconTransport is not supported');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const data = JSON.stringify(payload);
|
|
12
|
-
const success = window.navigator.sendBeacon(serverUrl, JSON.stringify(payload));
|
|
13
|
-
|
|
14
|
-
if (success) {
|
|
15
|
-
return resolve(this.buildResponse({
|
|
16
|
-
code: 200,
|
|
17
|
-
events_ingested: payload.events.length,
|
|
18
|
-
payload_size_bytes: data.length,
|
|
19
|
-
server_upload_time: Date.now()
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return resolve(this.buildResponse({
|
|
24
|
-
code: 500
|
|
25
|
-
}));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=send-beacon.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["BaseTransport","SendBeaconTransport","send","serverUrl","payload","Promise","resolve","reject","window","navigator","sendBeacon","Error","data","JSON","stringify","success","buildResponse","code","events_ingested","events","length","payload_size_bytes","server_upload_time","Date","now","e"],"sources":["send-beacon.ts"],"sourcesContent":["import { BaseTransport } from '@amplitude/analytics-core';\nimport { Payload, Response, Transport } from '@amplitude/analytics-types';\n\nexport class SendBeaconTransport extends BaseTransport implements Transport {\n async send(serverUrl: string, payload: Payload): Promise<Response | null> {\n return new Promise((resolve, reject) => {\n /* istanbul ignore if */\n if (\n typeof window === 'undefined' ||\n typeof window.navigator === 'undefined' ||\n typeof window.navigator.sendBeacon === 'undefined'\n ) {\n throw new Error('SendBeaconTransport is not supported');\n }\n try {\n const data = JSON.stringify(payload);\n const success = window.navigator.sendBeacon(serverUrl, JSON.stringify(payload));\n if (success) {\n return resolve(\n this.buildResponse({\n code: 200,\n events_ingested: payload.events.length,\n payload_size_bytes: data.length,\n server_upload_time: Date.now(),\n }),\n );\n }\n return resolve(this.buildResponse({ code: 500 }));\n } catch (e) {\n reject(e);\n }\n });\n }\n}\n"],"mappings":"AAAA,SAASA,aAAT,QAA8B,2BAA9B;AAGA,OAAO,MAAMC,mBAAN,SAAkCD,aAAlC,CAAqE;EAChE,MAAJE,IAAI,CAACC,SAAD,EAAoBC,OAApB,EAAgE;IACxE,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MACtC;MACA,IACE,OAAOC,MAAP,KAAkB,WAAlB,IACA,OAAOA,MAAM,CAACC,SAAd,KAA4B,WAD5B,IAEA,OAAOD,MAAM,CAACC,SAAP,CAAiBC,UAAxB,KAAuC,WAHzC,EAIE;QACA,MAAM,IAAIC,KAAJ,CAAU,sCAAV,CAAN;MACD;;MACD,IAAI;QACF,MAAMC,IAAI,GAAGC,IAAI,CAACC,SAAL,CAAeV,OAAf,CAAb;QACA,MAAMW,OAAO,GAAGP,MAAM,CAACC,SAAP,CAAiBC,UAAjB,CAA4BP,SAA5B,EAAuCU,IAAI,CAACC,SAAL,CAAeV,OAAf,CAAvC,CAAhB;;QACA,IAAIW,OAAJ,EAAa;UACX,OAAOT,OAAO,CACZ,KAAKU,aAAL,CAAmB;YACjBC,IAAI,EAAE,GADW;YAEjBC,eAAe,EAAEd,OAAO,CAACe,MAAR,CAAeC,MAFf;YAGjBC,kBAAkB,EAAET,IAAI,CAACQ,MAHR;YAIjBE,kBAAkB,EAAEC,IAAI,CAACC,GAAL;UAJH,CAAnB,CADY,CAAd;QAQD;;QACD,OAAOlB,OAAO,CAAC,KAAKU,aAAL,CAAmB;UAAEC,IAAI,EAAE;QAAR,CAAnB,CAAD,CAAd;MACD,CAdD,CAcE,OAAOQ,CAAP,EAAU;QACVlB,MAAM,CAACkB,CAAD,CAAN;MACD;IACF,CA1BM,CAAP;EA2BD;;AA7ByE"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
|
|
3
|
-
import { BaseTransport } from '@amplitude/analytics-core';
|
|
4
|
-
export class XHRTransport extends BaseTransport {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
|
|
8
|
-
_defineProperty(this, "state", {
|
|
9
|
-
done: 4
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async send(serverUrl, payload) {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
/* istanbul ignore if */
|
|
16
|
-
if (typeof XMLHttpRequest === 'undefined') {
|
|
17
|
-
reject(new Error('XHRTransport is not supported.'));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const xhr = new XMLHttpRequest();
|
|
21
|
-
xhr.open('POST', serverUrl, true);
|
|
22
|
-
|
|
23
|
-
xhr.onreadystatechange = () => {
|
|
24
|
-
if (xhr.readyState === this.state.done) {
|
|
25
|
-
try {
|
|
26
|
-
const responsePayload = xhr.responseText; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
27
|
-
|
|
28
|
-
const parsedResponsePayload = JSON.parse(responsePayload);
|
|
29
|
-
const result = this.buildResponse(parsedResponsePayload);
|
|
30
|
-
resolve(result);
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
38
|
-
xhr.setRequestHeader('Accept', '*/*');
|
|
39
|
-
xhr.send(JSON.stringify(payload));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=xhr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["BaseTransport","XHRTransport","done","send","serverUrl","payload","Promise","resolve","reject","XMLHttpRequest","Error","xhr","open","onreadystatechange","readyState","state","responsePayload","responseText","parsedResponsePayload","JSON","parse","result","buildResponse","e","setRequestHeader","stringify"],"sources":["xhr.ts"],"sourcesContent":["import { BaseTransport } from '@amplitude/analytics-core';\nimport { Payload, Response, Transport } from '@amplitude/analytics-types';\n\nexport class XHRTransport extends BaseTransport implements Transport {\n private state = {\n done: 4,\n };\n\n async send(serverUrl: string, payload: Payload): Promise<Response | null> {\n return new Promise((resolve, reject) => {\n /* istanbul ignore if */\n if (typeof XMLHttpRequest === 'undefined') {\n reject(new Error('XHRTransport is not supported.'));\n }\n\n const xhr = new XMLHttpRequest();\n xhr.open('POST', serverUrl, true);\n xhr.onreadystatechange = () => {\n if (xhr.readyState === this.state.done) {\n try {\n const responsePayload = xhr.responseText;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);\n const result = this.buildResponse(parsedResponsePayload);\n resolve(result);\n } catch (e) {\n reject(e);\n }\n }\n };\n xhr.setRequestHeader('Content-Type', 'application/json');\n xhr.setRequestHeader('Accept', '*/*');\n xhr.send(JSON.stringify(payload));\n });\n }\n}\n"],"mappings":";;AAAA,SAASA,aAAT,QAA8B,2BAA9B;AAGA,OAAO,MAAMC,YAAN,SAA2BD,aAA3B,CAA8D;EAAA;IAAA;;IAAA,+BACnD;MACdE,IAAI,EAAE;IADQ,CADmD;EAAA;;EAKzD,MAAJC,IAAI,CAACC,SAAD,EAAoBC,OAApB,EAAgE;IACxE,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MACtC;MACA,IAAI,OAAOC,cAAP,KAA0B,WAA9B,EAA2C;QACzCD,MAAM,CAAC,IAAIE,KAAJ,CAAU,gCAAV,CAAD,CAAN;MACD;;MAED,MAAMC,GAAG,GAAG,IAAIF,cAAJ,EAAZ;MACAE,GAAG,CAACC,IAAJ,CAAS,MAAT,EAAiBR,SAAjB,EAA4B,IAA5B;;MACAO,GAAG,CAACE,kBAAJ,GAAyB,MAAM;QAC7B,IAAIF,GAAG,CAACG,UAAJ,KAAmB,KAAKC,KAAL,CAAWb,IAAlC,EAAwC;UACtC,IAAI;YACF,MAAMc,eAAe,GAAGL,GAAG,CAACM,YAA5B,CADE,CAEF;;YACA,MAAMC,qBAA0C,GAAGC,IAAI,CAACC,KAAL,CAAWJ,eAAX,CAAnD;YACA,MAAMK,MAAM,GAAG,KAAKC,aAAL,CAAmBJ,qBAAnB,CAAf;YACAX,OAAO,CAACc,MAAD,CAAP;UACD,CAND,CAME,OAAOE,CAAP,EAAU;YACVf,MAAM,CAACe,CAAD,CAAN;UACD;QACF;MACF,CAZD;;MAaAZ,GAAG,CAACa,gBAAJ,CAAqB,cAArB,EAAqC,kBAArC;MACAb,GAAG,CAACa,gBAAJ,CAAqB,QAArB,EAA+B,KAA/B;MACAb,GAAG,CAACR,IAAJ,CAASgB,IAAI,CAACM,SAAL,CAAepB,OAAf,CAAT;IACD,CAxBM,CAAP;EAyBD;;AA/BkE"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Applies the proxied functions on the proxied amplitude snippet to an instance of the real object.
|
|
3
|
-
* @ignore
|
|
4
|
-
*/
|
|
5
|
-
export const runQueuedFunctions = (instance, queue) => {
|
|
6
|
-
convertProxyObjectToRealObject(instance, queue);
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Applies the proxied functions on the proxied object to an instance of the real object.
|
|
10
|
-
* Used to convert proxied Identify and Revenue objects.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export const convertProxyObjectToRealObject = (instance, queue) => {
|
|
14
|
-
for (let i = 0; i < queue.length; i++) {
|
|
15
|
-
const {
|
|
16
|
-
name,
|
|
17
|
-
args,
|
|
18
|
-
resolve
|
|
19
|
-
} = queue[i];
|
|
20
|
-
const fn = instance && instance[name];
|
|
21
|
-
|
|
22
|
-
if (typeof fn === 'function') {
|
|
23
|
-
const result = fn.apply(instance, args);
|
|
24
|
-
|
|
25
|
-
if (typeof resolve === 'function') {
|
|
26
|
-
resolve(result === null || result === void 0 ? void 0 : result.promise);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return instance;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Check if the param is snippet proxy
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
export const isInstanceProxy = instance => {
|
|
38
|
-
const instanceProxy = instance;
|
|
39
|
-
return instanceProxy && instanceProxy._q !== undefined;
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=snippet-helper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["runQueuedFunctions","instance","queue","convertProxyObjectToRealObject","i","length","name","args","resolve","fn","result","apply","promise","isInstanceProxy","instanceProxy","_q","undefined"],"sources":["snippet-helper.ts"],"sourcesContent":["import { AmplitudeReturn, InstanceProxy, QueueProxy, Result } from '@amplitude/analytics-types';\n\n/**\n * Applies the proxied functions on the proxied amplitude snippet to an instance of the real object.\n * @ignore\n */\nexport const runQueuedFunctions = (instance: object, queue: QueueProxy) => {\n convertProxyObjectToRealObject(instance, queue);\n};\n\n/**\n * Applies the proxied functions on the proxied object to an instance of the real object.\n * Used to convert proxied Identify and Revenue objects.\n */\nexport const convertProxyObjectToRealObject = <T>(instance: T, queue: QueueProxy): T => {\n for (let i = 0; i < queue.length; i++) {\n const { name, args, resolve } = queue[i];\n const fn = instance && instance[name as keyof T];\n if (typeof fn === 'function') {\n const result = fn.apply(instance, args) as AmplitudeReturn<Promise<Result>>;\n if (typeof resolve === 'function') {\n resolve(result?.promise);\n }\n }\n }\n return instance;\n};\n\n/**\n * Check if the param is snippet proxy\n */\nexport const isInstanceProxy = (instance: unknown): instance is InstanceProxy => {\n const instanceProxy = instance as InstanceProxy;\n return instanceProxy && instanceProxy._q !== undefined;\n};\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,GAAG,CAACC,QAAD,EAAmBC,KAAnB,KAAyC;EACzEC,8BAA8B,CAACF,QAAD,EAAWC,KAAX,CAA9B;AACD,CAFM;AAIP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,8BAA8B,GAAG,CAAIF,QAAJ,EAAiBC,KAAjB,KAA0C;EACtF,KAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,KAAK,CAACG,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;IACrC,MAAM;MAAEE,IAAF;MAAQC,IAAR;MAAcC;IAAd,IAA0BN,KAAK,CAACE,CAAD,CAArC;IACA,MAAMK,EAAE,GAAGR,QAAQ,IAAIA,QAAQ,CAACK,IAAD,CAA/B;;IACA,IAAI,OAAOG,EAAP,KAAc,UAAlB,EAA8B;MAC5B,MAAMC,MAAM,GAAGD,EAAE,CAACE,KAAH,CAASV,QAAT,EAAmBM,IAAnB,CAAf;;MACA,IAAI,OAAOC,OAAP,KAAmB,UAAvB,EAAmC;QACjCA,OAAO,CAACE,MAAD,aAACA,MAAD,uBAACA,MAAM,CAAEE,OAAT,CAAP;MACD;IACF;EACF;;EACD,OAAOX,QAAP;AACD,CAZM;AAcP;AACA;AACA;;AACA,OAAO,MAAMY,eAAe,GAAIZ,QAAD,IAAkD;EAC/E,MAAMa,aAAa,GAAGb,QAAtB;EACA,OAAOa,aAAa,IAAIA,aAAa,CAACC,EAAd,KAAqBC,SAA7C;AACD,CAHM"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const UTM_SOURCE = "utm_source";
|
|
2
|
-
export declare const UTM_MEDIUM = "utm_medium";
|
|
3
|
-
export declare const UTM_CAMPAIGN = "utm_campaign";
|
|
4
|
-
export declare const UTM_TERM = "utm_term";
|
|
5
|
-
export declare const UTM_CONTENT = "utm_content";
|
|
6
|
-
export declare const UTMZ_SOURCE = "utmcsr";
|
|
7
|
-
export declare const UTMZ_MEDIUM = "utmcmd";
|
|
8
|
-
export declare const UTMZ_CAMPAIGN = "utmccn";
|
|
9
|
-
export declare const UTMZ_TERM = "utmctr";
|
|
10
|
-
export declare const UTMZ_CONTENT = "utmcct";
|
|
11
|
-
export declare const GCLID = "gclid";
|
|
12
|
-
export declare const FBCLID = "fbclid";
|
|
13
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAC3C,eAAO,MAAM,QAAQ,aAAa,CAAC;AACnC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,KAAK,UAAU,CAAC;AAC7B,eAAO,MAAM,MAAM,WAAW,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BaseTransport } from '@amplitude/analytics-core';
|
|
2
|
-
import { Payload, Response, Transport } from '@amplitude/analytics-types';
|
|
3
|
-
export declare class SendBeaconTransport extends BaseTransport implements Transport {
|
|
4
|
-
send(serverUrl: string, payload: Payload): Promise<Response | null>;
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=send-beacon.d.ts.map
|