@amplitude/analytics-react-native 0.0.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/amplitude-react-native.podspec +21 -0
- package/android/build.gradle +61 -0
- package/android/gradle.properties +3 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/amplitude/reactnative/AmplitudeReactNativeModule.kt +36 -0
- package/android/src/main/java/com/amplitude/reactnative/AmplitudeReactNativePackage.java +28 -0
- package/android/src/main/java/com/amplitude/reactnative/AndroidContextProvider.kt +415 -0
- package/android/src/main/java/com/amplitude/reactnative/AndroidLogger.kt +56 -0
- package/android/src/main/java/com/amplitude/reactnative/Utils.kt +34 -0
- package/ios/AmplitudeReactNative-Bridging-Header.h +5 -0
- package/ios/AmplitudeReactNative.m +7 -0
- package/ios/AmplitudeReactNative.swift +29 -0
- package/ios/AmplitudeReactNative.xcodeproj/project.pbxproj +293 -0
- package/ios/AppleContextProvider.swift +219 -0
- package/lib/commonjs/attribution/campaign-parser.js +74 -0
- package/lib/commonjs/attribution/campaign-parser.js.map +1 -0
- package/lib/commonjs/attribution/campaign-tracker.js +133 -0
- package/lib/commonjs/attribution/campaign-tracker.js.map +1 -0
- package/lib/commonjs/attribution/constants.js +47 -0
- package/lib/commonjs/attribution/constants.js.map +1 -0
- package/lib/commonjs/config.js +257 -0
- package/lib/commonjs/config.js.map +1 -0
- package/lib/commonjs/constants.js +31 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/cookie-migration/index.js +74 -0
- package/lib/commonjs/cookie-migration/index.js.map +1 -0
- package/lib/commonjs/index.js +141 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/plugins/context.js +136 -0
- package/lib/commonjs/plugins/context.js.map +1 -0
- package/lib/commonjs/react-native-client.js +362 -0
- package/lib/commonjs/react-native-client.js.map +1 -0
- package/lib/commonjs/session-manager.js +114 -0
- package/lib/commonjs/session-manager.js.map +1 -0
- package/lib/commonjs/storage/cookie.js +124 -0
- package/lib/commonjs/storage/cookie.js.map +1 -0
- package/lib/commonjs/storage/local-storage.js +79 -0
- package/lib/commonjs/storage/local-storage.js.map +1 -0
- package/lib/commonjs/storage/utm-cookie.js +42 -0
- package/lib/commonjs/storage/utm-cookie.js.map +1 -0
- package/lib/commonjs/transports/fetch.js +34 -0
- package/lib/commonjs/transports/fetch.js.map +1 -0
- package/lib/commonjs/transports/send-beacon.js +43 -0
- package/lib/commonjs/transports/send-beacon.js.map +1 -0
- package/lib/commonjs/transports/xhr.js +54 -0
- package/lib/commonjs/transports/xhr.js.map +1 -0
- package/lib/commonjs/typings/browser-snippet.d.js +6 -0
- package/lib/commonjs/typings/browser-snippet.d.js.map +1 -0
- package/lib/commonjs/typings/ua-parser.d.js +2 -0
- package/lib/commonjs/typings/ua-parser.d.js.map +1 -0
- package/lib/commonjs/utils/cookie-name.js +23 -0
- package/lib/commonjs/utils/cookie-name.js.map +1 -0
- package/lib/commonjs/utils/language.js +18 -0
- package/lib/commonjs/utils/language.js.map +1 -0
- package/lib/commonjs/utils/platform.js +21 -0
- package/lib/commonjs/utils/platform.js.map +1 -0
- package/lib/commonjs/utils/query-params.js +36 -0
- package/lib/commonjs/utils/query-params.js.map +1 -0
- package/lib/commonjs/utils/snippet-helper.js +56 -0
- package/lib/commonjs/utils/snippet-helper.js.map +1 -0
- package/lib/commonjs/version.js +9 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/attribution/campaign-parser.js +62 -0
- package/lib/module/attribution/campaign-parser.js.map +1 -0
- package/lib/module/attribution/campaign-tracker.js +120 -0
- package/lib/module/attribution/campaign-tracker.js.map +1 -0
- package/lib/module/attribution/constants.js +26 -0
- package/lib/module/attribution/constants.js.map +1 -0
- package/lib/module/config.js +217 -0
- package/lib/module/config.js.map +1 -0
- package/lib/module/constants.js +13 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/cookie-migration/index.js +56 -0
- package/lib/module/cookie-migration/index.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/plugins/context.js +118 -0
- package/lib/module/plugins/context.js.map +1 -0
- package/lib/module/react-native-client.js +329 -0
- package/lib/module/react-native-client.js.map +1 -0
- package/lib/module/session-manager.js +104 -0
- package/lib/module/session-manager.js.map +1 -0
- package/lib/module/storage/cookie.js +114 -0
- package/lib/module/storage/cookie.js.map +1 -0
- package/lib/module/storage/local-storage.js +67 -0
- package/lib/module/storage/local-storage.js.map +1 -0
- package/lib/module/storage/utm-cookie.js +32 -0
- package/lib/module/storage/utm-cookie.js.map +1 -0
- package/lib/module/transports/fetch.js +24 -0
- package/lib/module/transports/fetch.js.map +1 -0
- package/lib/module/transports/send-beacon.js +33 -0
- package/lib/module/transports/send-beacon.js.map +1 -0
- package/lib/module/transports/xhr.js +44 -0
- package/lib/module/transports/xhr.js.map +1 -0
- package/lib/module/typings/browser-snippet.d.js +2 -0
- package/lib/module/typings/browser-snippet.d.js.map +1 -0
- package/lib/module/typings/ua-parser.d.js +2 -0
- package/lib/module/typings/ua-parser.d.js.map +1 -0
- package/lib/module/utils/cookie-name.js +10 -0
- package/lib/module/utils/cookie-name.js.map +1 -0
- package/lib/module/utils/language.js +9 -0
- package/lib/module/utils/language.js.map +1 -0
- package/lib/module/utils/platform.js +8 -0
- package/lib/module/utils/platform.js.map +1 -0
- package/lib/module/utils/query-params.js +26 -0
- package/lib/module/utils/query-params.js.map +1 -0
- package/lib/module/utils/snippet-helper.js +41 -0
- package/lib/module/utils/snippet-helper.js.map +1 -0
- package/lib/module/version.js +2 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/attribution/campaign-parser.d.ts +10 -0
- package/lib/typescript/attribution/campaign-parser.d.ts.map +1 -0
- package/lib/typescript/attribution/campaign-tracker.d.ts +72 -0
- package/lib/typescript/attribution/campaign-tracker.d.ts.map +1 -0
- package/lib/typescript/attribution/constants.d.ts +17 -0
- package/lib/typescript/attribution/constants.d.ts.map +1 -0
- package/lib/typescript/config.d.ts +90 -0
- package/lib/typescript/config.d.ts.map +1 -0
- package/lib/typescript/constants.d.ts +13 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/cookie-migration/index.d.ts +5 -0
- package/lib/typescript/cookie-migration/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/plugins/context.d.ts +31 -0
- package/lib/typescript/plugins/context.d.ts.map +1 -0
- package/lib/typescript/react-native-client.d.ts +209 -0
- package/lib/typescript/react-native-client.d.ts.map +1 -0
- package/lib/typescript/session-manager.d.ts +28 -0
- package/lib/typescript/session-manager.d.ts.map +1 -0
- package/lib/typescript/storage/cookie.d.ts +12 -0
- package/lib/typescript/storage/cookie.d.ts.map +1 -0
- package/lib/typescript/storage/local-storage.d.ts +10 -0
- package/lib/typescript/storage/local-storage.d.ts.map +1 -0
- package/lib/typescript/storage/utm-cookie.d.ts +6 -0
- package/lib/typescript/storage/utm-cookie.d.ts.map +1 -0
- package/lib/typescript/transports/fetch.d.ts +6 -0
- package/lib/typescript/transports/fetch.d.ts.map +1 -0
- package/lib/typescript/transports/send-beacon.d.ts +6 -0
- package/lib/typescript/transports/send-beacon.d.ts.map +1 -0
- package/lib/typescript/transports/xhr.d.ts +7 -0
- package/lib/typescript/transports/xhr.d.ts.map +1 -0
- package/lib/typescript/utils/cookie-name.d.ts +3 -0
- package/lib/typescript/utils/cookie-name.d.ts.map +1 -0
- package/lib/typescript/utils/language.d.ts +2 -0
- package/lib/typescript/utils/language.d.ts.map +1 -0
- package/lib/typescript/utils/platform.d.ts +3 -0
- package/lib/typescript/utils/platform.d.ts.map +1 -0
- package/lib/typescript/utils/query-params.d.ts +2 -0
- package/lib/typescript/utils/query-params.d.ts.map +1 -0
- package/lib/typescript/utils/snippet-helper.d.ts +16 -0
- package/lib/typescript/utils/snippet-helper.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +2 -0
- package/lib/typescript/version.d.ts.map +1 -0
- package/package.json +93 -0
- package/src/attribution/campaign-parser.ts +78 -0
- package/src/attribution/campaign-tracker.ts +112 -0
- package/src/attribution/constants.ts +32 -0
- package/src/config.ts +210 -0
- package/src/constants.ts +14 -0
- package/src/cookie-migration/index.ts +54 -0
- package/src/index.ts +23 -0
- package/src/plugins/context.ts +106 -0
- package/src/react-native-client.ts +349 -0
- package/src/session-manager.ts +81 -0
- package/src/storage/cookie.ts +95 -0
- package/src/storage/local-storage.ts +67 -0
- package/src/storage/utm-cookie.ts +27 -0
- package/src/transports/fetch.ts +23 -0
- package/src/transports/send-beacon.ts +34 -0
- package/src/transports/xhr.ts +36 -0
- package/src/typings/browser-snippet.d.ts +7 -0
- package/src/typings/ua-parser.d.ts +4 -0
- package/src/utils/cookie-name.ts +9 -0
- package/src/utils/language.ts +7 -0
- package/src/utils/platform.ts +9 -0
- package/src/utils/query-params.ts +21 -0
- package/src/utils/snippet-helper.ts +35 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CookieStorage } from './cookie';
|
|
2
|
+
|
|
3
|
+
export class UTMCookie extends CookieStorage<Record<string, string | undefined>> {
|
|
4
|
+
async get(key: string): Promise<Record<string, string | undefined> | undefined> {
|
|
5
|
+
try {
|
|
6
|
+
const value = await this.getRaw(key);
|
|
7
|
+
if (!value) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const entries = value.split('.').splice(-1)[0].split('|');
|
|
11
|
+
return entries.reduce<Record<string, string | undefined>>((acc, curr) => {
|
|
12
|
+
const [key, value = ''] = curr.split('=', 2);
|
|
13
|
+
if (!value) {
|
|
14
|
+
return acc;
|
|
15
|
+
}
|
|
16
|
+
acc[key] = decodeURIComponent(value);
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
} catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async set(): Promise<void> {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
2
|
+
import { Payload, Response, Transport } from '@amplitude/analytics-types';
|
|
3
|
+
|
|
4
|
+
export class FetchTransport extends BaseTransport implements Transport {
|
|
5
|
+
async send(serverUrl: string, payload: Payload): Promise<Response | null> {
|
|
6
|
+
/* istanbul ignore if */
|
|
7
|
+
if (typeof fetch === 'undefined') {
|
|
8
|
+
throw new Error('FetchTransport is not supported');
|
|
9
|
+
}
|
|
10
|
+
const options: RequestInit = {
|
|
11
|
+
headers: {
|
|
12
|
+
'Content-Type': 'application/json',
|
|
13
|
+
Accept: '*/*',
|
|
14
|
+
},
|
|
15
|
+
body: JSON.stringify(payload),
|
|
16
|
+
method: 'POST',
|
|
17
|
+
};
|
|
18
|
+
const response = await fetch(serverUrl, options);
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
20
|
+
const responsePayload: Record<string, any> = await response.json();
|
|
21
|
+
return this.buildResponse(responsePayload);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
2
|
+
import { Payload, Response, Transport } from '@amplitude/analytics-types';
|
|
3
|
+
|
|
4
|
+
export class SendBeaconTransport extends BaseTransport implements Transport {
|
|
5
|
+
async send(serverUrl: string, payload: Payload): Promise<Response | null> {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
/* istanbul ignore if */
|
|
8
|
+
if (
|
|
9
|
+
typeof window === 'undefined' ||
|
|
10
|
+
typeof window.navigator === 'undefined' ||
|
|
11
|
+
typeof window.navigator.sendBeacon === 'undefined'
|
|
12
|
+
) {
|
|
13
|
+
throw new Error('SendBeaconTransport is not supported');
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const data = JSON.stringify(payload);
|
|
17
|
+
const success = window.navigator.sendBeacon(serverUrl, JSON.stringify(payload));
|
|
18
|
+
if (success) {
|
|
19
|
+
return resolve(
|
|
20
|
+
this.buildResponse({
|
|
21
|
+
code: 200,
|
|
22
|
+
events_ingested: payload.events.length,
|
|
23
|
+
payload_size_bytes: data.length,
|
|
24
|
+
server_upload_time: Date.now(),
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return resolve(this.buildResponse({ code: 500 }));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
2
|
+
import { Payload, Response, Transport } from '@amplitude/analytics-types';
|
|
3
|
+
|
|
4
|
+
export class XHRTransport extends BaseTransport implements Transport {
|
|
5
|
+
private state = {
|
|
6
|
+
done: 4,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
async send(serverUrl: string, payload: Payload): Promise<Response | null> {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
/* istanbul ignore if */
|
|
12
|
+
if (typeof XMLHttpRequest === 'undefined') {
|
|
13
|
+
reject(new Error('XHRTransport is not supported.'));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const xhr = new XMLHttpRequest();
|
|
17
|
+
xhr.open('POST', serverUrl, true);
|
|
18
|
+
xhr.onreadystatechange = () => {
|
|
19
|
+
if (xhr.readyState === this.state.done) {
|
|
20
|
+
try {
|
|
21
|
+
const responsePayload = xhr.responseText;
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
23
|
+
const parsedResponsePayload: Record<string, any> = JSON.parse(responsePayload);
|
|
24
|
+
const result = this.buildResponse(parsedResponsePayload);
|
|
25
|
+
resolve(result);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
32
|
+
xhr.setRequestHeader('Accept', '*/*');
|
|
33
|
+
xhr.send(JSON.stringify(payload));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AMPLITUDE_PREFIX } from '@amplitude/analytics-core';
|
|
2
|
+
|
|
3
|
+
export const getCookieName = (apiKey: string, postKey = '', limit = 10) => {
|
|
4
|
+
return [AMPLITUDE_PREFIX, postKey, apiKey.substring(0, limit)].filter(Boolean).join('_');
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const getOldCookieName = (apiKey: string) => {
|
|
8
|
+
return `${AMPLITUDE_PREFIX.toLowerCase()}_${apiKey.substring(0, 6)}`;
|
|
9
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const getLanguage = (): string => {
|
|
2
|
+
if (typeof navigator === 'undefined') return '';
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
4
|
+
const userLanguage = (navigator as any).userLanguage as string | undefined;
|
|
5
|
+
|
|
6
|
+
return navigator.languages?.[0] ?? navigator.language ?? userLanguage ?? '';
|
|
7
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isNative } from './platform';
|
|
2
|
+
|
|
3
|
+
export const getQueryParams = (): Record<string, string | undefined> => {
|
|
4
|
+
if (isNative()) {
|
|
5
|
+
return {};
|
|
6
|
+
}
|
|
7
|
+
/* istanbul ignore if */
|
|
8
|
+
if (typeof window === 'undefined') {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
const pairs = window.location.search.substring(1).split('&').filter(Boolean);
|
|
12
|
+
const params = pairs.reduce<Record<string, string | undefined>>((acc, curr) => {
|
|
13
|
+
const [key, value = ''] = curr.split('=', 2);
|
|
14
|
+
if (!value) {
|
|
15
|
+
return acc;
|
|
16
|
+
}
|
|
17
|
+
acc[decodeURIComponent(key)] = decodeURIComponent(value);
|
|
18
|
+
return acc;
|
|
19
|
+
}, {});
|
|
20
|
+
return params;
|
|
21
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AmplitudeReturn, InstanceProxy, QueueProxy, Result } from '@amplitude/analytics-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applies the proxied functions on the proxied amplitude snippet to an instance of the real object.
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export const runQueuedFunctions = (instance: object, queue: QueueProxy) => {
|
|
8
|
+
convertProxyObjectToRealObject(instance, queue);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Applies the proxied functions on the proxied object to an instance of the real object.
|
|
13
|
+
* Used to convert proxied Identify and Revenue objects.
|
|
14
|
+
*/
|
|
15
|
+
export const convertProxyObjectToRealObject = <T>(instance: T, queue: QueueProxy): T => {
|
|
16
|
+
for (let i = 0; i < queue.length; i++) {
|
|
17
|
+
const { name, args, resolve } = queue[i];
|
|
18
|
+
const fn = instance && instance[name as keyof T];
|
|
19
|
+
if (typeof fn === 'function') {
|
|
20
|
+
const result = fn.apply(instance, args) as AmplitudeReturn<Result>;
|
|
21
|
+
if (typeof resolve === 'function') {
|
|
22
|
+
resolve(result?.promise);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return instance;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if the param is snippet proxy
|
|
31
|
+
*/
|
|
32
|
+
export const isInstanceProxy = (instance: unknown): instance is InstanceProxy => {
|
|
33
|
+
const instanceProxy = instance as InstanceProxy;
|
|
34
|
+
return instanceProxy && instanceProxy._q !== undefined;
|
|
35
|
+
};
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = '0.0.1-dev.0';
|