@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.
Files changed (97) hide show
  1. package/README.md +150 -0
  2. package/android/src/main/java/com/amplitude/reactnative/AmplitudeReactNativeModule.kt +5 -5
  3. package/ios/AmplitudeReactNative.swift +4 -4
  4. package/lib/commonjs/attribution/campaign-tracker.js +1 -1
  5. package/lib/commonjs/attribution/campaign-tracker.js.map +1 -1
  6. package/lib/commonjs/config.js +2 -22
  7. package/lib/commonjs/config.js.map +1 -1
  8. package/lib/commonjs/index.js +2 -16
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/plugins/context.js +4 -4
  11. package/lib/commonjs/plugins/context.js.map +1 -1
  12. package/lib/commonjs/plugins/identity.js +40 -0
  13. package/lib/commonjs/plugins/identity.js.map +1 -0
  14. package/lib/commonjs/react-native-client.js +23 -57
  15. package/lib/commonjs/react-native-client.js.map +1 -1
  16. package/lib/commonjs/storage/cookie.js +1 -6
  17. package/lib/commonjs/storage/cookie.js.map +1 -1
  18. package/lib/commonjs/utils/analytics-connector.js +15 -0
  19. package/lib/commonjs/utils/analytics-connector.js.map +1 -0
  20. package/lib/commonjs/utils/query-params.js +1 -6
  21. package/lib/commonjs/utils/query-params.js.map +1 -1
  22. package/lib/commonjs/version.js +1 -1
  23. package/lib/commonjs/version.js.map +1 -1
  24. package/lib/module/attribution/campaign-tracker.js +1 -1
  25. package/lib/module/attribution/campaign-tracker.js.map +1 -1
  26. package/lib/module/config.js +1 -15
  27. package/lib/module/config.js.map +1 -1
  28. package/lib/module/index.js +3 -4
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/plugins/context.js +4 -4
  31. package/lib/module/plugins/context.js.map +1 -1
  32. package/lib/module/plugins/identity.js +29 -0
  33. package/lib/module/plugins/identity.js.map +1 -0
  34. package/lib/module/react-native-client.js +21 -55
  35. package/lib/module/react-native-client.js.map +1 -1
  36. package/lib/module/storage/cookie.js +1 -6
  37. package/lib/module/storage/cookie.js.map +1 -1
  38. package/lib/module/utils/analytics-connector.js +5 -0
  39. package/lib/module/utils/analytics-connector.js.map +1 -0
  40. package/lib/module/utils/query-params.js +1 -6
  41. package/lib/module/utils/query-params.js.map +1 -1
  42. package/lib/module/version.js +1 -1
  43. package/lib/module/version.js.map +1 -1
  44. package/lib/typescript/config.d.ts +1 -4
  45. package/lib/typescript/config.d.ts.map +1 -1
  46. package/lib/typescript/index.d.ts +2 -4
  47. package/lib/typescript/index.d.ts.map +1 -1
  48. package/lib/typescript/plugins/context.d.ts +5 -5
  49. package/lib/typescript/plugins/context.d.ts.map +1 -1
  50. package/lib/typescript/plugins/identity.d.ts +9 -0
  51. package/lib/typescript/plugins/identity.d.ts.map +1 -0
  52. package/lib/typescript/react-native-client.d.ts +7 -26
  53. package/lib/typescript/react-native-client.d.ts.map +1 -1
  54. package/lib/typescript/storage/cookie.d.ts.map +1 -1
  55. package/lib/typescript/utils/analytics-connector.d.ts +3 -0
  56. package/lib/typescript/utils/analytics-connector.d.ts.map +1 -0
  57. package/lib/typescript/utils/query-params.d.ts.map +1 -1
  58. package/lib/typescript/version.d.ts +1 -1
  59. package/package.json +1 -2
  60. package/src/attribution/campaign-tracker.ts +1 -1
  61. package/src/config.ts +1 -14
  62. package/src/index.ts +1 -4
  63. package/src/plugins/context.ts +9 -9
  64. package/src/plugins/identity.ts +21 -0
  65. package/src/react-native-client.ts +26 -60
  66. package/src/storage/cookie.ts +1 -4
  67. package/src/utils/analytics-connector.ts +5 -0
  68. package/src/utils/query-params.ts +1 -4
  69. package/src/version.ts +1 -1
  70. package/lib/commonjs/constants.js +0 -31
  71. package/lib/commonjs/constants.js.map +0 -1
  72. package/lib/commonjs/transports/send-beacon.js +0 -43
  73. package/lib/commonjs/transports/send-beacon.js.map +0 -1
  74. package/lib/commonjs/transports/xhr.js +0 -54
  75. package/lib/commonjs/transports/xhr.js.map +0 -1
  76. package/lib/commonjs/utils/snippet-helper.js +0 -56
  77. package/lib/commonjs/utils/snippet-helper.js.map +0 -1
  78. package/lib/module/constants.js +0 -13
  79. package/lib/module/constants.js.map +0 -1
  80. package/lib/module/transports/send-beacon.js +0 -33
  81. package/lib/module/transports/send-beacon.js.map +0 -1
  82. package/lib/module/transports/xhr.js +0 -44
  83. package/lib/module/transports/xhr.js.map +0 -1
  84. package/lib/module/utils/snippet-helper.js +0 -41
  85. package/lib/module/utils/snippet-helper.js.map +0 -1
  86. package/lib/typescript/constants.d.ts +0 -13
  87. package/lib/typescript/constants.d.ts.map +0 -1
  88. package/lib/typescript/transports/send-beacon.d.ts +0 -6
  89. package/lib/typescript/transports/send-beacon.d.ts.map +0 -1
  90. package/lib/typescript/transports/xhr.d.ts +0 -7
  91. package/lib/typescript/transports/xhr.d.ts.map +0 -1
  92. package/lib/typescript/utils/snippet-helper.d.ts +0 -16
  93. package/lib/typescript/utils/snippet-helper.d.ts.map +0 -1
  94. package/src/constants.ts +0 -14
  95. package/src/transports/send-beacon.ts +0 -34
  96. package/src/transports/xhr.ts +0 -36
  97. package/src/utils/snippet-helper.ts +0 -35
@@ -1 +0,0 @@
1
- {"version":3,"file":"send-beacon.d.ts","sourceRoot":"","sources":["../../../src/transports/send-beacon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,qBAAa,mBAAoB,SAAQ,aAAc,YAAW,SAAS;IACnE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CA6B1E"}
@@ -1,7 +0,0 @@
1
- import { BaseTransport } from '@amplitude/analytics-core';
2
- import { Payload, Response, Transport } from '@amplitude/analytics-types';
3
- export declare class XHRTransport extends BaseTransport implements Transport {
4
- private state;
5
- send(serverUrl: string, payload: Payload): Promise<Response | null>;
6
- }
7
- //# sourceMappingURL=xhr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"xhr.d.ts","sourceRoot":"","sources":["../../../src/transports/xhr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,qBAAa,YAAa,SAAQ,aAAc,YAAW,SAAS;IAClE,OAAO,CAAC,KAAK,CAEX;IAEI,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CA2B1E"}
@@ -1,16 +0,0 @@
1
- import { InstanceProxy, QueueProxy } from '@amplitude/analytics-types';
2
- /**
3
- * Applies the proxied functions on the proxied amplitude snippet to an instance of the real object.
4
- * @ignore
5
- */
6
- export declare const runQueuedFunctions: (instance: object, queue: QueueProxy) => void;
7
- /**
8
- * Applies the proxied functions on the proxied object to an instance of the real object.
9
- * Used to convert proxied Identify and Revenue objects.
10
- */
11
- export declare const convertProxyObjectToRealObject: <T>(instance: T, queue: QueueProxy) => T;
12
- /**
13
- * Check if the param is snippet proxy
14
- */
15
- export declare const isInstanceProxy: (instance: unknown) => instance is InstanceProxy;
16
- //# sourceMappingURL=snippet-helper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snippet-helper.d.ts","sourceRoot":"","sources":["../../../src/utils/snippet-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,aAAa,EAAE,UAAU,EAAU,MAAM,4BAA4B,CAAC;AAEhG;;;GAGG;AACH,eAAO,MAAM,kBAAkB,aAAc,MAAM,4BAElD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,8BAA8B,0CAY1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,aAAc,OAAO,8BAGhD,CAAC"}
package/src/constants.ts DELETED
@@ -1,14 +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
-
7
- export const UTMZ_SOURCE = 'utmcsr';
8
- export const UTMZ_MEDIUM = 'utmcmd';
9
- export const UTMZ_CAMPAIGN = 'utmccn';
10
- export const UTMZ_TERM = 'utmctr';
11
- export const UTMZ_CONTENT = 'utmcct';
12
-
13
- export const GCLID = 'gclid';
14
- export const FBCLID = 'fbclid';
@@ -1,34 +0,0 @@
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
- }
@@ -1,36 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
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<Promise<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
- };