@metarouter/react-native-sdk 0.1.22 → 0.1.24
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/lib/MetaRouter.d.ts +11 -0
- package/lib/MetaRouter.d.ts.map +1 -1
- package/lib/MetaRouter.js +11 -0
- package/lib/analytics/IdentityManager.d.ts +40 -0
- package/lib/analytics/IdentityManager.d.ts.map +1 -1
- package/lib/analytics/IdentityManager.js +40 -0
- package/lib/analytics/MetaRouterAnalyticsClient.d.ts +73 -0
- package/lib/analytics/MetaRouterAnalyticsClient.d.ts.map +1 -1
- package/lib/analytics/MetaRouterAnalyticsClient.js +77 -12
- package/lib/analytics/init.d.ts +17 -0
- package/lib/analytics/init.d.ts.map +1 -1
- package/lib/analytics/init.js +17 -0
- package/lib/analytics/proxy/proxyClient.d.ts +13 -0
- package/lib/analytics/proxy/proxyClient.d.ts.map +1 -1
- package/lib/analytics/proxy/proxyClient.js +13 -0
- package/lib/analytics/utils/anonymousId.d.ts +6 -0
- package/lib/analytics/utils/anonymousId.d.ts.map +1 -1
- package/lib/analytics/utils/anonymousId.js +6 -0
- package/lib/analytics/utils/contextInfo.d.ts +12 -32
- package/lib/analytics/utils/contextInfo.d.ts.map +1 -1
- package/lib/analytics/utils/contextInfo.js +38 -24
- package/lib/analytics/utils/enrichEvent.d.ts +15 -0
- package/lib/analytics/utils/enrichEvent.d.ts.map +1 -0
- package/lib/analytics/utils/enrichEvent.js +22 -0
- package/lib/analytics/utils/logger.d.ts +23 -0
- package/lib/analytics/utils/logger.d.ts.map +1 -1
- package/lib/analytics/utils/logger.js +23 -2
- package/lib/analytics/utils/retry.d.ts +14 -0
- package/lib/analytics/utils/retry.d.ts.map +1 -1
- package/lib/analytics/utils/retry.js +14 -0
- package/lib/analytics/utils/timezone.d.ts +5 -0
- package/lib/analytics/utils/timezone.d.ts.map +1 -1
- package/lib/analytics/utils/timezone.js +5 -0
- package/lib/react/context.d.ts +9 -0
- package/lib/react/context.d.ts.map +1 -1
- package/lib/react/context.js +9 -0
- package/lib/react/useMetaRouter.d.ts +4 -0
- package/lib/react/useMetaRouter.d.ts.map +1 -1
- package/lib/react/useMetaRouter.js +4 -0
- package/package.json +2 -2
- package/lib/analytics/enrichEvent.d.ts +0 -3
- package/lib/analytics/enrichEvent.d.ts.map +0 -1
- package/lib/analytics/enrichEvent.js +0 -11
package/lib/MetaRouter.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { MetaRouterInterface } from './types';
|
|
2
2
|
import 'react-native-get-random-values';
|
|
3
|
+
/**
|
|
4
|
+
* Top-level MetaRouter SDK interface.
|
|
5
|
+
*
|
|
6
|
+
* Provides access to analytics methods for initialization, client retrieval, and reset.
|
|
7
|
+
* Designed for use in React Native applications.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import MetaRouter from '@metarouter/react-native-sdk';
|
|
11
|
+
* await MetaRouter.analytics.init({ ... });
|
|
12
|
+
* MetaRouter.analytics.track(...);
|
|
13
|
+
*/
|
|
3
14
|
export declare const MetaRouter: MetaRouterInterface;
|
|
4
15
|
//# sourceMappingURL=MetaRouter.d.ts.map
|
package/lib/MetaRouter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaRouter.d.ts","sourceRoot":"","sources":["../src/MetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,gCAAgC,CAAC;AAExC,eAAO,MAAM,UAAU,EAAE,mBAMxB,CAAC"}
|
|
1
|
+
{"version":3,"file":"MetaRouter.d.ts","sourceRoot":"","sources":["../src/MetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,gCAAgC,CAAC;AAExC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAE,mBAMxB,CAAC"}
|
package/lib/MetaRouter.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { initAnalytics, getAnalyticsClient, resetAnalytics } from './analytics/init';
|
|
2
2
|
import 'react-native-get-random-values';
|
|
3
|
+
/**
|
|
4
|
+
* Top-level MetaRouter SDK interface.
|
|
5
|
+
*
|
|
6
|
+
* Provides access to analytics methods for initialization, client retrieval, and reset.
|
|
7
|
+
* Designed for use in React Native applications.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import MetaRouter from '@metarouter/react-native-sdk';
|
|
11
|
+
* await MetaRouter.analytics.init({ ... });
|
|
12
|
+
* MetaRouter.analytics.track(...);
|
|
13
|
+
*/
|
|
3
14
|
export const MetaRouter = {
|
|
4
15
|
analytics: {
|
|
5
16
|
init: (opts) => initAnalytics(opts),
|
|
@@ -1,15 +1,55 @@
|
|
|
1
1
|
import { EventPayload, EventWithIdentity } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Manages user, group, and anonymous identity for analytics events.
|
|
4
|
+
* - Loads or generates a persistent anonymous ID.
|
|
5
|
+
* - Tracks current user and group IDs.
|
|
6
|
+
* - Can enrich events with identity information.
|
|
7
|
+
* - Supports reset for logout/testing scenarios.
|
|
8
|
+
*/
|
|
2
9
|
export declare class IdentityManager {
|
|
3
10
|
private anonymousId;
|
|
4
11
|
private userId?;
|
|
5
12
|
private groupId?;
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the manager by loading or generating an anonymous ID.
|
|
15
|
+
* Should be called before using other methods.
|
|
16
|
+
*/
|
|
6
17
|
init(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the current anonymous ID.
|
|
20
|
+
* @returns The anonymous ID or null if not initialized.
|
|
21
|
+
*/
|
|
7
22
|
getAnonymousId(): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the user ID for the current session.
|
|
25
|
+
* @param userId - The user ID to set.
|
|
26
|
+
*/
|
|
8
27
|
identify(userId: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the group ID for the current session.
|
|
30
|
+
* @param groupId - The group ID to set.
|
|
31
|
+
*/
|
|
9
32
|
group(groupId: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves the current user ID.
|
|
35
|
+
* @returns The user ID or undefined if not set.
|
|
36
|
+
*/
|
|
10
37
|
getUserId(): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the current group ID.
|
|
40
|
+
* @returns The group ID or undefined if not set.
|
|
41
|
+
*/
|
|
11
42
|
getGroupId(): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Adds identity information to an event payload.
|
|
45
|
+
* @param event - The event payload to enrich.
|
|
46
|
+
* @returns The enriched event payload with identity information.
|
|
47
|
+
*/
|
|
12
48
|
addIdentityInfo<T extends EventPayload>(event: T): EventWithIdentity;
|
|
49
|
+
/**
|
|
50
|
+
* Resets the identity manager to its initial state.
|
|
51
|
+
* Clears all user and group IDs, and sets the anonymous ID to null.
|
|
52
|
+
*/
|
|
13
53
|
reset(): void;
|
|
14
54
|
}
|
|
15
55
|
//# sourceMappingURL=IdentityManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityManager.d.ts","sourceRoot":"","sources":["../../src/analytics/IdentityManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE1D,qBAAa,eAAe;IACxB,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;
|
|
1
|
+
{"version":3,"file":"IdentityManager.d.ts","sourceRoot":"","sources":["../../src/analytics/IdentityManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;GAMG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB;;;KAGC;IACK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B;;;OAGG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM;IAKvB;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAKrB;;;OAGG;IACH,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B;;;OAGG;IACH,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC;;;;OAIG;IACH,eAAe,CAAC,CAAC,SAAS,YAAY,EAAE,KAAK,EAAE,CAAC,GAAG,iBAAiB;IASpE;;;OAGG;IACH,KAAK;CAMN"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { getAnonymousId } from "./utils/anonymousId";
|
|
2
2
|
import { log, warn } from "./utils/logger";
|
|
3
|
+
/**
|
|
4
|
+
* Manages user, group, and anonymous identity for analytics events.
|
|
5
|
+
* - Loads or generates a persistent anonymous ID.
|
|
6
|
+
* - Tracks current user and group IDs.
|
|
7
|
+
* - Can enrich events with identity information.
|
|
8
|
+
* - Supports reset for logout/testing scenarios.
|
|
9
|
+
*/
|
|
3
10
|
export class IdentityManager {
|
|
4
11
|
constructor() {
|
|
5
12
|
this.anonymousId = null;
|
|
6
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Initializes the manager by loading or generating an anonymous ID.
|
|
16
|
+
* Should be called before using other methods.
|
|
17
|
+
*/
|
|
7
18
|
async init() {
|
|
8
19
|
try {
|
|
9
20
|
this.anonymousId = await getAnonymousId(); // load or generate
|
|
@@ -16,23 +27,48 @@ export class IdentityManager {
|
|
|
16
27
|
log('Using fallback anonymous ID:', this.anonymousId);
|
|
17
28
|
}
|
|
18
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the current anonymous ID.
|
|
32
|
+
* @returns The anonymous ID or null if not initialized.
|
|
33
|
+
*/
|
|
19
34
|
getAnonymousId() {
|
|
20
35
|
return this.anonymousId;
|
|
21
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Sets the user ID for the current session.
|
|
39
|
+
* @param userId - The user ID to set.
|
|
40
|
+
*/
|
|
22
41
|
identify(userId) {
|
|
23
42
|
this.userId = userId;
|
|
24
43
|
log('User identified:', userId);
|
|
25
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Sets the group ID for the current session.
|
|
47
|
+
* @param groupId - The group ID to set.
|
|
48
|
+
*/
|
|
26
49
|
group(groupId) {
|
|
27
50
|
this.groupId = groupId;
|
|
28
51
|
log('User grouped:', groupId);
|
|
29
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the current user ID.
|
|
55
|
+
* @returns The user ID or undefined if not set.
|
|
56
|
+
*/
|
|
30
57
|
getUserId() {
|
|
31
58
|
return this.userId;
|
|
32
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the current group ID.
|
|
62
|
+
* @returns The group ID or undefined if not set.
|
|
63
|
+
*/
|
|
33
64
|
getGroupId() {
|
|
34
65
|
return this.groupId;
|
|
35
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Adds identity information to an event payload.
|
|
69
|
+
* @param event - The event payload to enrich.
|
|
70
|
+
* @returns The enriched event payload with identity information.
|
|
71
|
+
*/
|
|
36
72
|
addIdentityInfo(event) {
|
|
37
73
|
var _a, _b, _c;
|
|
38
74
|
return {
|
|
@@ -42,6 +78,10 @@ export class IdentityManager {
|
|
|
42
78
|
groupId: (_c = event.groupId) !== null && _c !== void 0 ? _c : this.groupId,
|
|
43
79
|
};
|
|
44
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Resets the identity manager to its initial state.
|
|
83
|
+
* Clears all user and group IDs, and sets the anonymous ID to null.
|
|
84
|
+
*/
|
|
45
85
|
reset() {
|
|
46
86
|
this.anonymousId = null;
|
|
47
87
|
this.userId = undefined;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { InitOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Analytics client for MetaRouter.
|
|
4
|
+
* - Handles event queueing, batching, and delivery with retries.
|
|
5
|
+
* - Manages user, group, and anonymous identity.
|
|
6
|
+
* - Supports periodic and on-demand flushing.
|
|
7
|
+
* - Provides debug and cleanup utilities.
|
|
8
|
+
*/
|
|
2
9
|
export declare class MetaRouterAnalyticsClient {
|
|
3
10
|
private initialized;
|
|
4
11
|
private initPromise;
|
|
@@ -7,25 +14,82 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
7
14
|
private flushTimer;
|
|
8
15
|
private endpoint;
|
|
9
16
|
private writeKey;
|
|
17
|
+
private context;
|
|
10
18
|
private appState;
|
|
11
19
|
private appStateSubscription;
|
|
12
20
|
private identityManager;
|
|
21
|
+
/**
|
|
22
|
+
* Initializes the analytics client with the provided options.
|
|
23
|
+
* @param options - The initialization options.
|
|
24
|
+
*/
|
|
13
25
|
constructor(options: InitOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Initializes the analytics client.
|
|
28
|
+
* @returns A promise that resolves when the client is initialized.
|
|
29
|
+
*/
|
|
14
30
|
private init;
|
|
31
|
+
/**
|
|
32
|
+
* Waits for the analytics client to be initialized.
|
|
33
|
+
* @returns A promise that resolves when the client is initialized.
|
|
34
|
+
*/
|
|
15
35
|
waitForInitialization(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Starts the flush loop.
|
|
38
|
+
*/
|
|
16
39
|
private startFlushLoop;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the current timestamp in ISO format.
|
|
42
|
+
* @returns The current timestamp in ISO format.
|
|
43
|
+
*/
|
|
17
44
|
private now;
|
|
45
|
+
/**
|
|
46
|
+
* Enqueues an event for processing.
|
|
47
|
+
* @param event - The event to enqueue.
|
|
48
|
+
*/
|
|
18
49
|
private enqueue;
|
|
50
|
+
/**
|
|
51
|
+
* Sets up the app state listener.
|
|
52
|
+
*/
|
|
19
53
|
private setupAppStateListener;
|
|
54
|
+
/**
|
|
55
|
+
* Handles the app state change event.
|
|
56
|
+
* @param nextState - The new app state.
|
|
57
|
+
*/
|
|
20
58
|
private handleAppStateChange;
|
|
59
|
+
/**
|
|
60
|
+
* Tracks an event.
|
|
61
|
+
* @param event - The event to track.
|
|
62
|
+
* @param properties - The properties to track.
|
|
63
|
+
*/
|
|
21
64
|
track(event: string, properties?: Record<string, any>): void;
|
|
65
|
+
/**
|
|
66
|
+
* Identifies a user.
|
|
67
|
+
* @param userId - The user ID to identify.
|
|
68
|
+
* @param traits - The traits to identify the user with.
|
|
69
|
+
*/
|
|
22
70
|
identify(userId: string, traits?: Record<string, any>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Tracks a page view.
|
|
73
|
+
* @param name - The name of the page.
|
|
74
|
+
* @param properties - The properties to track.
|
|
75
|
+
*/
|
|
23
76
|
page(name: string, properties?: Record<string, any>): void;
|
|
77
|
+
/**
|
|
78
|
+
* Groups a user.
|
|
79
|
+
* @param groupId - The group ID to group.
|
|
80
|
+
* @param traits - The traits to group the user with.
|
|
81
|
+
*/
|
|
24
82
|
group(groupId: string, traits?: Record<string, any>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Tracks a screen view.
|
|
85
|
+
* @param name - The name of the screen.
|
|
86
|
+
* @param properties - The properties to track.
|
|
87
|
+
*/
|
|
25
88
|
screen(name: string, properties?: Record<string, any>): void;
|
|
26
89
|
/**
|
|
27
90
|
* Alias an anonymous user to a known user ID.
|
|
28
91
|
* This updates internal identity state and enqueues an alias event.
|
|
92
|
+
* @param newUserId - The new user ID to alias to.
|
|
29
93
|
*/
|
|
30
94
|
alias(newUserId: string): void;
|
|
31
95
|
/**
|
|
@@ -45,6 +109,9 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
45
109
|
userId: string | undefined;
|
|
46
110
|
groupId: string | undefined;
|
|
47
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* Flushes the event queue to the ingestion endpoint.
|
|
114
|
+
*/
|
|
48
115
|
flush(): Promise<{
|
|
49
116
|
sentAt: string;
|
|
50
117
|
type: import("./types").EventType;
|
|
@@ -55,7 +122,13 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
55
122
|
properties?: Record<string, any>;
|
|
56
123
|
timestamp?: string;
|
|
57
124
|
}[] | undefined>;
|
|
125
|
+
/**
|
|
126
|
+
* Resets the analytics client.
|
|
127
|
+
*/
|
|
58
128
|
reset(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Cleans up the analytics client.
|
|
131
|
+
*/
|
|
59
132
|
cleanup(): void;
|
|
60
133
|
}
|
|
61
134
|
//# sourceMappingURL=MetaRouterAnalyticsClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaRouterAnalyticsClient.d.ts","sourceRoot":"","sources":["../../src/analytics/MetaRouterAnalyticsClient.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"MetaRouterAnalyticsClient.d.ts","sourceRoot":"","sources":["../../src/analytics/MetaRouterAnalyticsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,WAAW,EAAE,MAAM,SAAS,CAAC;AAQrF;;;;;;GAMG;AACD,qBAAa,yBAAyB;IACpC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,oBAAoB,CAAwC;IACpE,OAAO,CAAC,eAAe,CAAkB;IAEzC;;;OAGG;gBACS,OAAO,EAAE,WAAW;IAahC;;;OAGG;YACW,IAAI;IA8BlB;;;OAGG;IACG,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;;OAGG;IACH,OAAO,CAAC,GAAG;IAIX;;;OAGG;IACH,OAAO,CAAC,OAAO;IAOf;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;;OAGG;IACH,OAAO,CAAC,oBAAoB,CAK1B;IAGF;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMrD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOrD;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMnD;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOnD;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMrD;;;;MAIE;IACF,KAAK,CAAC,SAAS,EAAE,MAAM;IAOvB;;OAEG;IACH,kBAAkB;IAKlB;;OAEG;IACH,YAAY;;;;;;;;;;IAaZ;;OAEG;IACG,KAAK;;;;;;;;;;IAkDX;;OAEG;IACH,KAAK;IAML;;OAEG;IACH,OAAO;CAQR"}
|
|
@@ -2,8 +2,20 @@ import { AppState } from 'react-native';
|
|
|
2
2
|
import { retryWithBackoff } from "./utils/retry";
|
|
3
3
|
import { error, log, setDebugLogging, warn } from "./utils/logger";
|
|
4
4
|
import { IdentityManager } from "./IdentityManager";
|
|
5
|
-
import { enrichEvent } from "./enrichEvent";
|
|
5
|
+
import { enrichEvent } from "./utils/enrichEvent";
|
|
6
|
+
import { getContextInfo } from "./utils/contextInfo";
|
|
7
|
+
/**
|
|
8
|
+
* Analytics client for MetaRouter.
|
|
9
|
+
* - Handles event queueing, batching, and delivery with retries.
|
|
10
|
+
* - Manages user, group, and anonymous identity.
|
|
11
|
+
* - Supports periodic and on-demand flushing.
|
|
12
|
+
* - Provides debug and cleanup utilities.
|
|
13
|
+
*/
|
|
6
14
|
export class MetaRouterAnalyticsClient {
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the analytics client with the provided options.
|
|
17
|
+
* @param options - The initialization options.
|
|
18
|
+
*/
|
|
7
19
|
constructor(options) {
|
|
8
20
|
var _a;
|
|
9
21
|
this.initialized = false;
|
|
@@ -12,6 +24,10 @@ export class MetaRouterAnalyticsClient {
|
|
|
12
24
|
this.flushTimer = null;
|
|
13
25
|
this.appState = AppState.currentState;
|
|
14
26
|
this.appStateSubscription = null;
|
|
27
|
+
/**
|
|
28
|
+
* Handles the app state change event.
|
|
29
|
+
* @param nextState - The new app state.
|
|
30
|
+
*/
|
|
15
31
|
this.handleAppStateChange = (nextState) => {
|
|
16
32
|
if (this.appState === 'active' && nextState.match(/inactive|background/)) {
|
|
17
33
|
this.flush();
|
|
@@ -28,6 +44,10 @@ export class MetaRouterAnalyticsClient {
|
|
|
28
44
|
this.initPromise = this.init();
|
|
29
45
|
log('Analytics client constructor completed, initialization in progress...');
|
|
30
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Initializes the analytics client.
|
|
49
|
+
* @returns A promise that resolves when the client is initialized.
|
|
50
|
+
*/
|
|
31
51
|
async init() {
|
|
32
52
|
if (this.initialized) {
|
|
33
53
|
log('Analytics client already initialized');
|
|
@@ -41,6 +61,7 @@ export class MetaRouterAnalyticsClient {
|
|
|
41
61
|
log('Flush loop started with interval:', this.flushIntervalMs, 'ms');
|
|
42
62
|
this.setupAppStateListener();
|
|
43
63
|
log('App state listener setup completed');
|
|
64
|
+
this.context = await getContextInfo();
|
|
44
65
|
this.initialized = true;
|
|
45
66
|
log('Analytics client initialization completed successfully');
|
|
46
67
|
}
|
|
@@ -51,46 +72,89 @@ export class MetaRouterAnalyticsClient {
|
|
|
51
72
|
throw error;
|
|
52
73
|
}
|
|
53
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Waits for the analytics client to be initialized.
|
|
77
|
+
* @returns A promise that resolves when the client is initialized.
|
|
78
|
+
*/
|
|
54
79
|
async waitForInitialization() {
|
|
55
80
|
await this.initPromise;
|
|
56
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Starts the flush loop.
|
|
84
|
+
*/
|
|
57
85
|
startFlushLoop() {
|
|
58
86
|
this.flushTimer = setInterval(() => this.flush(), this.flushIntervalMs);
|
|
59
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the current timestamp in ISO format.
|
|
90
|
+
* @returns The current timestamp in ISO format.
|
|
91
|
+
*/
|
|
60
92
|
now() {
|
|
61
93
|
return new Date().toISOString();
|
|
62
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Enqueues an event for processing.
|
|
97
|
+
* @param event - The event to enqueue.
|
|
98
|
+
*/
|
|
63
99
|
enqueue(event) {
|
|
64
100
|
const eventWithIdentity = this.identityManager.addIdentityInfo(event);
|
|
65
|
-
const enrichedEvent = enrichEvent(eventWithIdentity, this.writeKey);
|
|
101
|
+
const enrichedEvent = enrichEvent(eventWithIdentity, this.writeKey, this.context);
|
|
66
102
|
log('Enqueuing event', enrichedEvent);
|
|
67
103
|
this.queue.push(enrichedEvent);
|
|
68
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Sets up the app state listener.
|
|
107
|
+
*/
|
|
69
108
|
setupAppStateListener() {
|
|
70
109
|
this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
|
|
71
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Tracks an event.
|
|
113
|
+
* @param event - The event to track.
|
|
114
|
+
* @param properties - The properties to track.
|
|
115
|
+
*/
|
|
72
116
|
track(event, properties) {
|
|
73
117
|
log('Tracking event:', event, 'with properties:', properties);
|
|
74
118
|
this.enqueue({ type: 'track', event, properties, timestamp: this.now() });
|
|
75
119
|
log('Event enqueued, queue length:', this.queue.length);
|
|
76
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Identifies a user.
|
|
123
|
+
* @param userId - The user ID to identify.
|
|
124
|
+
* @param traits - The traits to identify the user with.
|
|
125
|
+
*/
|
|
77
126
|
identify(userId, traits) {
|
|
78
127
|
log('Identifying user:', userId, 'with traits:', traits);
|
|
79
128
|
this.identityManager.identify(userId);
|
|
80
129
|
this.enqueue({ type: 'identify', userId, traits, timestamp: this.now() });
|
|
81
130
|
log('Identify event enqueued, queue length:', this.queue.length);
|
|
82
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Tracks a page view.
|
|
134
|
+
* @param name - The name of the page.
|
|
135
|
+
* @param properties - The properties to track.
|
|
136
|
+
*/
|
|
83
137
|
page(name, properties) {
|
|
84
138
|
log('Tracking page:', name, 'with properties:', properties);
|
|
85
139
|
this.enqueue({ type: 'page', event: name, properties, timestamp: this.now() });
|
|
86
140
|
log('Page event enqueued, queue length:', this.queue.length);
|
|
87
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Groups a user.
|
|
144
|
+
* @param groupId - The group ID to group.
|
|
145
|
+
* @param traits - The traits to group the user with.
|
|
146
|
+
*/
|
|
88
147
|
group(groupId, traits) {
|
|
89
148
|
log('Grouping user:', groupId, 'with traits:', traits);
|
|
90
149
|
this.identityManager.group(groupId);
|
|
91
150
|
this.enqueue({ type: 'group', groupId, traits, timestamp: this.now() });
|
|
92
151
|
log('Group event enqueued, queue length:', this.queue.length);
|
|
93
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Tracks a screen view.
|
|
155
|
+
* @param name - The name of the screen.
|
|
156
|
+
* @param properties - The properties to track.
|
|
157
|
+
*/
|
|
94
158
|
screen(name, properties) {
|
|
95
159
|
log('Tracking screen:', name, 'with properties:', properties);
|
|
96
160
|
this.enqueue({ type: 'screen', event: name, properties, timestamp: this.now() });
|
|
@@ -99,6 +163,7 @@ export class MetaRouterAnalyticsClient {
|
|
|
99
163
|
/**
|
|
100
164
|
* Alias an anonymous user to a known user ID.
|
|
101
165
|
* This updates internal identity state and enqueues an alias event.
|
|
166
|
+
* @param newUserId - The new user ID to alias to.
|
|
102
167
|
*/
|
|
103
168
|
alias(newUserId) {
|
|
104
169
|
log('Aliasing user to:', newUserId);
|
|
@@ -128,6 +193,9 @@ export class MetaRouterAnalyticsClient {
|
|
|
128
193
|
groupId: this.identityManager.getGroupId(),
|
|
129
194
|
};
|
|
130
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Flushes the event queue to the ingestion endpoint.
|
|
198
|
+
*/
|
|
131
199
|
async flush() {
|
|
132
200
|
const anonId = this.identityManager.getAnonymousId();
|
|
133
201
|
if (!anonId) {
|
|
@@ -167,23 +235,20 @@ export class MetaRouterAnalyticsClient {
|
|
|
167
235
|
}
|
|
168
236
|
catch (err) {
|
|
169
237
|
warn('Flush failed, re-queueing events', err);
|
|
170
|
-
|
|
171
|
-
this.queue.unshift(...this.queue.splice(0, 0, ...batch.map(event => ({
|
|
172
|
-
type: event.type,
|
|
173
|
-
event: event.event,
|
|
174
|
-
properties: event.properties,
|
|
175
|
-
userId: event.userId,
|
|
176
|
-
traits: event.traits,
|
|
177
|
-
groupId: event.groupId,
|
|
178
|
-
timestamp: event.timestamp,
|
|
179
|
-
}))));
|
|
238
|
+
this.queue.unshift(...batch);
|
|
180
239
|
}
|
|
181
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Resets the analytics client.
|
|
243
|
+
*/
|
|
182
244
|
reset() {
|
|
183
245
|
this.identityManager.reset();
|
|
184
246
|
this.queue = [];
|
|
185
247
|
log('Analytics client reset');
|
|
186
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Cleans up the analytics client.
|
|
251
|
+
*/
|
|
187
252
|
cleanup() {
|
|
188
253
|
var _a, _b;
|
|
189
254
|
log('Cleaning up analytics client');
|
package/lib/analytics/init.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { InitOptions, AnalyticsInterface } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the analytics client singleton.
|
|
4
|
+
* Waits for async setup (e.g., identity loading) before returning the interface.
|
|
5
|
+
* Returns the same instance on subsequent calls.
|
|
6
|
+
* @param options Analytics initialization options.
|
|
7
|
+
* @returns The analytics interface.
|
|
8
|
+
*/
|
|
2
9
|
export declare function initAnalytics(options: InitOptions): Promise<AnalyticsInterface>;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the analytics client singleton.
|
|
12
|
+
* Returns the proxy client before initialization, and the real client after.
|
|
13
|
+
* @returns The analytics interface.
|
|
14
|
+
*/
|
|
3
15
|
export declare function getAnalyticsClient(): AnalyticsInterface;
|
|
16
|
+
/**
|
|
17
|
+
* Resets the analytics client singleton.
|
|
18
|
+
* Cleans up the client and sets it to null.
|
|
19
|
+
* @returns A promise that resolves when the client is reset.
|
|
20
|
+
*/
|
|
4
21
|
export declare function resetAnalytics(): Promise<void>;
|
|
5
22
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/analytics/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM/D,wBAAsB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAuBrF;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAMpD"}
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/analytics/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM/D;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAuBrF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED;;;;GAIG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAMpD"}
|
package/lib/analytics/init.js
CHANGED
|
@@ -3,6 +3,13 @@ import { proxyClient, setRealClient } from './proxy/proxyClient';
|
|
|
3
3
|
let initialized = false;
|
|
4
4
|
let client = null;
|
|
5
5
|
let analyticsInterface = null;
|
|
6
|
+
/**
|
|
7
|
+
* Initializes the analytics client singleton.
|
|
8
|
+
* Waits for async setup (e.g., identity loading) before returning the interface.
|
|
9
|
+
* Returns the same instance on subsequent calls.
|
|
10
|
+
* @param options Analytics initialization options.
|
|
11
|
+
* @returns The analytics interface.
|
|
12
|
+
*/
|
|
6
13
|
export async function initAnalytics(options) {
|
|
7
14
|
if (initialized)
|
|
8
15
|
return analyticsInterface;
|
|
@@ -24,9 +31,19 @@ export async function initAnalytics(options) {
|
|
|
24
31
|
setRealClient(analyticsInterface);
|
|
25
32
|
return analyticsInterface;
|
|
26
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the analytics client singleton.
|
|
36
|
+
* Returns the proxy client before initialization, and the real client after.
|
|
37
|
+
* @returns The analytics interface.
|
|
38
|
+
*/
|
|
27
39
|
export function getAnalyticsClient() {
|
|
28
40
|
return initialized ? analyticsInterface : proxyClient;
|
|
29
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Resets the analytics client singleton.
|
|
44
|
+
* Cleans up the client and sets it to null.
|
|
45
|
+
* @returns A promise that resolves when the client is reset.
|
|
46
|
+
*/
|
|
30
47
|
export async function resetAnalytics() {
|
|
31
48
|
await (client === null || client === void 0 ? void 0 : client.cleanup());
|
|
32
49
|
client = null;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { AnalyticsInterface } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* proxyClient implements a proxy pattern for the AnalyticsInterface.
|
|
4
|
+
*
|
|
5
|
+
* It allows analytics method calls (track, identify, etc.) to be made before the real analytics client
|
|
6
|
+
* is fully initialized. Calls are queued and replayed once the real client is set via setRealClient.
|
|
7
|
+
* This ensures that analytics events are not lost if called early in the app lifecycle.
|
|
8
|
+
*
|
|
9
|
+
* The proxy also provides a fallback for getDebugInfo, returning proxy state if the real client is not ready.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* - Use proxyClient as the default analytics client before initialization.
|
|
13
|
+
* - Call setRealClient(realClientInstance) once the real client is ready.
|
|
14
|
+
*/
|
|
2
15
|
export declare const proxyClient: AnalyticsInterface;
|
|
3
16
|
export declare function setRealClient(client: AnalyticsInterface | null): void;
|
|
4
17
|
//# sourceMappingURL=proxyClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyClient.d.ts","sourceRoot":"","sources":["../../../src/analytics/proxy/proxyClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAwBnD,eAAO,MAAM,WAAW,EAAE,kBAWzB,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,QAO9D"}
|
|
1
|
+
{"version":3,"file":"proxyClient.d.ts","sourceRoot":"","sources":["../../../src/analytics/proxy/proxyClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAwBnD;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,WAAW,EAAE,kBAWzB,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,QAO9D"}
|
|
@@ -13,6 +13,19 @@ function handleMethodCall(methodName, ...args) {
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* proxyClient implements a proxy pattern for the AnalyticsInterface.
|
|
18
|
+
*
|
|
19
|
+
* It allows analytics method calls (track, identify, etc.) to be made before the real analytics client
|
|
20
|
+
* is fully initialized. Calls are queued and replayed once the real client is set via setRealClient.
|
|
21
|
+
* This ensures that analytics events are not lost if called early in the app lifecycle.
|
|
22
|
+
*
|
|
23
|
+
* The proxy also provides a fallback for getDebugInfo, returning proxy state if the real client is not ready.
|
|
24
|
+
*
|
|
25
|
+
* Usage:
|
|
26
|
+
* - Use proxyClient as the default analytics client before initialization.
|
|
27
|
+
* - Call setRealClient(realClientInstance) once the real client is ready.
|
|
28
|
+
*/
|
|
16
29
|
export const proxyClient = {
|
|
17
30
|
track: (event, props) => handleMethodCall('track', event, props),
|
|
18
31
|
identify: (userId, traits) => handleMethodCall('identify', userId, traits),
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves or generates a persistent anonymous ID for the user/device.
|
|
3
|
+
* - Attempts to load from AsyncStorage.
|
|
4
|
+
* - If not found or storage fails, generates a new UUIDv4.
|
|
5
|
+
* - Always returns a valid string.
|
|
6
|
+
*/
|
|
1
7
|
export declare function getAnonymousId(): Promise<string>;
|
|
2
8
|
//# sourceMappingURL=anonymousId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anonymousId.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/anonymousId.ts"],"names":[],"mappings":"AAMA,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAsBtD"}
|
|
1
|
+
{"version":3,"file":"anonymousId.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/anonymousId.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAsBtD"}
|
|
@@ -2,6 +2,12 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import { log, warn } from './logger';
|
|
4
4
|
const STORAGE_KEY = 'metarouter:anonymous_id';
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves or generates a persistent anonymous ID for the user/device.
|
|
7
|
+
* - Attempts to load from AsyncStorage.
|
|
8
|
+
* - If not found or storage fails, generates a new UUIDv4.
|
|
9
|
+
* - Always returns a valid string.
|
|
10
|
+
*/
|
|
5
11
|
export async function getAnonymousId() {
|
|
6
12
|
try {
|
|
7
13
|
const existing = await AsyncStorage.getItem(STORAGE_KEY);
|
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
library: {
|
|
15
|
-
name: string;
|
|
16
|
-
version: string;
|
|
17
|
-
};
|
|
18
|
-
os: {
|
|
19
|
-
name: any;
|
|
20
|
-
version: any;
|
|
21
|
-
};
|
|
22
|
-
screen: {
|
|
23
|
-
density: any;
|
|
24
|
-
width: any;
|
|
25
|
-
height: any;
|
|
26
|
-
};
|
|
27
|
-
network: {
|
|
28
|
-
wifi: any;
|
|
29
|
-
};
|
|
30
|
-
locale: string;
|
|
31
|
-
timezone: string;
|
|
32
|
-
};
|
|
1
|
+
import { EventContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Gathers and caches device, app, and environment context information for analytics events.
|
|
4
|
+
*
|
|
5
|
+
* - Collects details such as app name/version, device model/type, OS, screen size, locale, timezone, and network status.
|
|
6
|
+
* - Uses `react-native-device-info` and the current environment to populate fields.
|
|
7
|
+
* - Caches the result for the lifetime of the app to avoid redundant async calls.
|
|
8
|
+
* - Returns a context object suitable for event enrichment.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Promise<EventContext>} A promise that resolves to the context information object.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getContextInfo(): Promise<EventContext>;
|
|
33
13
|
//# sourceMappingURL=contextInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWxC;;;;;;;;;GASG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,YAAY,CAAC,CA2C5D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getTimeZone } from './timezone';
|
|
2
2
|
import pkg from '../../../package.json';
|
|
3
|
+
let cachedContext = null;
|
|
3
4
|
let DeviceInfo = null;
|
|
4
5
|
try {
|
|
5
6
|
DeviceInfo = require('react-native-device-info');
|
|
@@ -7,43 +8,56 @@ try {
|
|
|
7
8
|
catch {
|
|
8
9
|
DeviceInfo = null;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Gathers and caches device, app, and environment context information for analytics events.
|
|
13
|
+
*
|
|
14
|
+
* - Collects details such as app name/version, device model/type, OS, screen size, locale, timezone, and network status.
|
|
15
|
+
* - Uses `react-native-device-info` and the current environment to populate fields.
|
|
16
|
+
* - Caches the result for the lifetime of the app to avoid redundant async calls.
|
|
17
|
+
* - Returns a context object suitable for event enrichment.
|
|
18
|
+
*
|
|
19
|
+
* @returns {Promise<EventContext>} A promise that resolves to the context information object.
|
|
20
|
+
*/
|
|
21
|
+
export async function getContextInfo() {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
|
|
23
|
+
if (cachedContext)
|
|
24
|
+
return cachedContext;
|
|
12
25
|
let locale = 'en-US';
|
|
13
26
|
if (typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function') {
|
|
14
27
|
const resolved = Intl.DateTimeFormat().resolvedOptions();
|
|
15
28
|
locale = (_a = resolved.locale) !== null && _a !== void 0 ? _a : locale;
|
|
16
29
|
}
|
|
17
|
-
|
|
18
|
-
app: {
|
|
19
|
-
name: (_c = (_b = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _b === void 0 ? void 0 : _b.call(DeviceInfo)) !== null && _c !== void 0 ? _c : 'metarouter-react-native',
|
|
20
|
-
version: (_f = (_e = (_d = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _d === void 0 ? void 0 : _d.call(DeviceInfo)) !== null && _e !== void 0 ? _e : pkg.version) !== null && _f !== void 0 ? _f : 'unknown',
|
|
21
|
-
build: (_h = (_g = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _g === void 0 ? void 0 : _g.call(DeviceInfo)) !== null && _h !== void 0 ? _h : 'unknown',
|
|
22
|
-
namespace: (_k = (_j = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _j === void 0 ? void 0 : _j.call(DeviceInfo)) !== null && _k !== void 0 ? _k : 'unknown',
|
|
23
|
-
},
|
|
24
|
-
device: {
|
|
25
|
-
manufacturer: (_m = (_l = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getManufacturer) === null || _l === void 0 ? void 0 : _l.call(DeviceInfo)) !== null && _m !== void 0 ? _m : 'unknown',
|
|
26
|
-
model: (_p = (_o = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getModel) === null || _o === void 0 ? void 0 : _o.call(DeviceInfo)) !== null && _p !== void 0 ? _p : 'unknown',
|
|
27
|
-
name: (_r = (_q = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDeviceName) === null || _q === void 0 ? void 0 : _q.call(DeviceInfo)) !== null && _r !== void 0 ? _r : 'unknown',
|
|
28
|
-
type: ((_t = (_s = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _s === void 0 ? void 0 : _s.call(DeviceInfo)) === null || _t === void 0 ? void 0 : _t.toLowerCase()) === 'android' ? 'android' : 'ios',
|
|
29
|
-
},
|
|
30
|
+
cachedContext = {
|
|
30
31
|
library: {
|
|
31
32
|
name: 'metarouter-react-native-sdk',
|
|
32
|
-
version: (
|
|
33
|
+
version: (_b = pkg.version) !== null && _b !== void 0 ? _b : '0.0.0',
|
|
34
|
+
},
|
|
35
|
+
locale,
|
|
36
|
+
timezone: getTimeZone(),
|
|
37
|
+
device: {
|
|
38
|
+
manufacturer: (_d = await ((_c = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getManufacturer) === null || _c === void 0 ? void 0 : _c.call(DeviceInfo))) !== null && _d !== void 0 ? _d : 'unknown',
|
|
39
|
+
model: (_f = (_e = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getModel) === null || _e === void 0 ? void 0 : _e.call(DeviceInfo)) !== null && _f !== void 0 ? _f : 'unknown',
|
|
40
|
+
name: (_h = await ((_g = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDeviceName) === null || _g === void 0 ? void 0 : _g.call(DeviceInfo))) !== null && _h !== void 0 ? _h : 'unknown',
|
|
41
|
+
type: ((_j = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _j === void 0 ? void 0 : _j.call(DeviceInfo)) === 'Android' ? 'android' : 'ios',
|
|
33
42
|
},
|
|
34
43
|
os: {
|
|
35
|
-
name: (
|
|
36
|
-
version: (
|
|
44
|
+
name: (_l = (_k = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _k === void 0 ? void 0 : _k.call(DeviceInfo)) !== null && _l !== void 0 ? _l : 'unknown',
|
|
45
|
+
version: (_o = (_m = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemVersion) === null || _m === void 0 ? void 0 : _m.call(DeviceInfo)) !== null && _o !== void 0 ? _o : 'unknown',
|
|
46
|
+
},
|
|
47
|
+
app: {
|
|
48
|
+
name: (_q = (_p = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _p === void 0 ? void 0 : _p.call(DeviceInfo)) !== null && _q !== void 0 ? _q : 'unknown',
|
|
49
|
+
version: (_t = (_s = (_r = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _r === void 0 ? void 0 : _r.call(DeviceInfo)) !== null && _s !== void 0 ? _s : pkg.version) !== null && _t !== void 0 ? _t : 'unknown',
|
|
50
|
+
build: (_v = (_u = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _u === void 0 ? void 0 : _u.call(DeviceInfo)) !== null && _v !== void 0 ? _v : 'unknown',
|
|
51
|
+
namespace: (_x = (_w = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _w === void 0 ? void 0 : _w.call(DeviceInfo)) !== null && _x !== void 0 ? _x : 'unknown',
|
|
37
52
|
},
|
|
38
53
|
screen: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
width: (_z = (_y = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getScreenWidth) === null || _y === void 0 ? void 0 : _y.call(DeviceInfo)) !== null && _z !== void 0 ? _z : 0,
|
|
55
|
+
height: (_1 = (_0 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getScreenHeight) === null || _0 === void 0 ? void 0 : _0.call(DeviceInfo)) !== null && _1 !== void 0 ? _1 : 0,
|
|
56
|
+
density: (_3 = (_2 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDensity) === null || _2 === void 0 ? void 0 : _2.call(DeviceInfo)) !== null && _3 !== void 0 ? _3 : 1,
|
|
42
57
|
},
|
|
43
58
|
network: {
|
|
44
|
-
wifi: (
|
|
59
|
+
wifi: (_5 = await ((_4 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.isWifiEnabled) === null || _4 === void 0 ? void 0 : _4.call(DeviceInfo))) !== null && _5 !== void 0 ? _5 : false,
|
|
45
60
|
},
|
|
46
|
-
locale,
|
|
47
|
-
timezone: getTimeZone(),
|
|
48
61
|
};
|
|
62
|
+
return cachedContext;
|
|
49
63
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EnrichedEventPayload, EventContext, EventWithIdentity } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Enriches an analytics event with additional metadata required for ingestion.
|
|
4
|
+
*
|
|
5
|
+
* - Adds a unique messageId and the current sentAt timestamp.
|
|
6
|
+
* - Injects the provided writeKey and context information into the event.
|
|
7
|
+
* - Returns a new EnrichedEventPayload object, suitable for sending to the ingestion endpoint.
|
|
8
|
+
*
|
|
9
|
+
* @param event The base event with identity information.
|
|
10
|
+
* @param writeKey The write key for the analytics project.
|
|
11
|
+
* @param context The context information (device, app, environment, etc.).
|
|
12
|
+
* @returns The enriched event payload.
|
|
13
|
+
*/
|
|
14
|
+
export declare function enrichEvent(event: EventWithIdentity, writeKey: string, context: EventContext): EnrichedEventPayload;
|
|
15
|
+
//# sourceMappingURL=enrichEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrichEvent.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/enrichEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAI,oBAAoB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEnF;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,GACpB,oBAAoB,CAUtB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enriches an analytics event with additional metadata required for ingestion.
|
|
3
|
+
*
|
|
4
|
+
* - Adds a unique messageId and the current sentAt timestamp.
|
|
5
|
+
* - Injects the provided writeKey and context information into the event.
|
|
6
|
+
* - Returns a new EnrichedEventPayload object, suitable for sending to the ingestion endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @param event The base event with identity information.
|
|
9
|
+
* @param writeKey The write key for the analytics project.
|
|
10
|
+
* @param context The context information (device, app, environment, etc.).
|
|
11
|
+
* @returns The enriched event payload.
|
|
12
|
+
*/
|
|
13
|
+
export function enrichEvent(event, writeKey, context) {
|
|
14
|
+
const enriched = {
|
|
15
|
+
...event,
|
|
16
|
+
writeKey,
|
|
17
|
+
messageId: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
|
|
18
|
+
sentAt: new Date().toISOString(),
|
|
19
|
+
context,
|
|
20
|
+
};
|
|
21
|
+
return enriched;
|
|
22
|
+
}
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple logger utility for MetaRouter SDK.
|
|
3
|
+
*
|
|
4
|
+
* - Allows toggling debug logging for development and troubleshooting.
|
|
5
|
+
* - Always logs warnings and errors, regardless of debug setting.
|
|
6
|
+
* - Prepends all logs with a [MetaRouter] tag for easy identification.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Enables or disables debug logging.
|
|
10
|
+
* @param value If true, enables debug logging; if false, disables it.
|
|
11
|
+
*/
|
|
1
12
|
export declare function setDebugLogging(value: boolean): void;
|
|
13
|
+
/**
|
|
14
|
+
* Logs a message to the console if debug logging is enabled.
|
|
15
|
+
* @param args Arguments to log.
|
|
16
|
+
*/
|
|
2
17
|
export declare function log(...args: any[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* Logs a warning to the console (always, regardless of debug setting).
|
|
20
|
+
* @param args Arguments to log as a warning.
|
|
21
|
+
*/
|
|
3
22
|
export declare function warn(...args: any[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Logs an error to the console (always, regardless of debug setting).
|
|
25
|
+
* @param args Arguments to log as an error.
|
|
26
|
+
*/
|
|
4
27
|
export declare function error(...args: any[]): void;
|
|
5
28
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,QAE7C;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAEjC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAElC;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAEnC"}
|
|
@@ -1,16 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple logger utility for MetaRouter SDK.
|
|
3
|
+
*
|
|
4
|
+
* - Allows toggling debug logging for development and troubleshooting.
|
|
5
|
+
* - Always logs warnings and errors, regardless of debug setting.
|
|
6
|
+
* - Prepends all logs with a [MetaRouter] tag for easy identification.
|
|
7
|
+
*/
|
|
1
8
|
let enabled = false;
|
|
9
|
+
/**
|
|
10
|
+
* Enables or disables debug logging.
|
|
11
|
+
* @param value If true, enables debug logging; if false, disables it.
|
|
12
|
+
*/
|
|
2
13
|
export function setDebugLogging(value) {
|
|
3
14
|
enabled = value;
|
|
4
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Logs a message to the console if debug logging is enabled.
|
|
18
|
+
* @param args Arguments to log.
|
|
19
|
+
*/
|
|
5
20
|
export function log(...args) {
|
|
6
21
|
if (enabled)
|
|
7
22
|
console.log('[MetaRouter]', ...args);
|
|
8
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Logs a warning to the console (always, regardless of debug setting).
|
|
26
|
+
* @param args Arguments to log as a warning.
|
|
27
|
+
*/
|
|
9
28
|
export function warn(...args) {
|
|
10
|
-
// Always log warnings, even when debug is disabled
|
|
11
29
|
console.warn('[MetaRouter]', ...args);
|
|
12
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Logs an error to the console (always, regardless of debug setting).
|
|
33
|
+
* @param args Arguments to log as an error.
|
|
34
|
+
*/
|
|
13
35
|
export function error(...args) {
|
|
14
|
-
// Always log errors, even when debug is disabled
|
|
15
36
|
console.error('[MetaRouter]', ...args);
|
|
16
37
|
}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retries an asynchronous operation with exponential backoff and optional jitter.
|
|
3
|
+
*
|
|
4
|
+
* - Attempts to execute the provided async function up to `retries` times.
|
|
5
|
+
* - Waits an exponentially increasing delay (with random jitter) between attempts.
|
|
6
|
+
* - If all attempts fail, the last error is thrown.
|
|
7
|
+
*
|
|
8
|
+
* @template T The return type of the async function.
|
|
9
|
+
* @param fn The asynchronous function to retry.
|
|
10
|
+
* @param retries The maximum number of attempts (default: 5).
|
|
11
|
+
* @param baseDelayMs The base delay in milliseconds for backoff (default: 1000).
|
|
12
|
+
* @param sleep Optional custom sleep function (default: setTimeout-based Promise).
|
|
13
|
+
* @returns A promise that resolves with the result of `fn`, or rejects after all retries fail.
|
|
14
|
+
*/
|
|
1
15
|
export declare function retryWithBackoff<T>(fn: () => Promise<T>, retries?: number, baseDelayMs?: number, sleep?: (ms: number) => Promise<unknown>): Promise<T>;
|
|
2
16
|
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/retry.ts"],"names":[],"mappings":"AAAA,wBAAsB,gBAAgB,CAAC,CAAC,EACpC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,SAAI,EACX,WAAW,SAAO,EAClB,KAAK,IAAI,IAAI,MAAM,qBAA8C,GAChE,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACpC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,SAAI,EACX,WAAW,SAAO,EAClB,KAAK,IAAI,IAAI,MAAM,qBAA8C,GAChE,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retries an asynchronous operation with exponential backoff and optional jitter.
|
|
3
|
+
*
|
|
4
|
+
* - Attempts to execute the provided async function up to `retries` times.
|
|
5
|
+
* - Waits an exponentially increasing delay (with random jitter) between attempts.
|
|
6
|
+
* - If all attempts fail, the last error is thrown.
|
|
7
|
+
*
|
|
8
|
+
* @template T The return type of the async function.
|
|
9
|
+
* @param fn The asynchronous function to retry.
|
|
10
|
+
* @param retries The maximum number of attempts (default: 5).
|
|
11
|
+
* @param baseDelayMs The base delay in milliseconds for backoff (default: 1000).
|
|
12
|
+
* @param sleep Optional custom sleep function (default: setTimeout-based Promise).
|
|
13
|
+
* @returns A promise that resolves with the result of `fn`, or rejects after all retries fail.
|
|
14
|
+
*/
|
|
1
15
|
export async function retryWithBackoff(fn, retries = 5, baseDelayMs = 1000, sleep = (ms) => new Promise((res) => setTimeout(res, ms))) {
|
|
2
16
|
let attempt = 0;
|
|
3
17
|
while (attempt < retries) {
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current IANA time zone string for the environment.
|
|
3
|
+
* Falls back to 'UTC' if unavailable.
|
|
4
|
+
* @returns {string} The IANA time zone (e.g., 'America/New_York') or 'UTC'.
|
|
5
|
+
*/
|
|
1
6
|
export declare function getTimeZone(): string;
|
|
2
7
|
//# sourceMappingURL=timezone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/timezone.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/timezone.ts"],"names":[],"mappings":"AAAG;;;;GAIG;AACN,wBAAgB,WAAW,IAAI,MAAM,CAMlC"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current IANA time zone string for the environment.
|
|
3
|
+
* Falls back to 'UTC' if unavailable.
|
|
4
|
+
* @returns {string} The IANA time zone (e.g., 'America/New_York') or 'UTC'.
|
|
5
|
+
*/
|
|
1
6
|
export function getTimeZone() {
|
|
2
7
|
try {
|
|
3
8
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
package/lib/react/context.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
2
|
import type { MetaRouterInterface } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Context for the MetaRouter analytics client.
|
|
5
|
+
* @param instance - The analytics client instance.
|
|
6
|
+
*/
|
|
3
7
|
export declare const MetaRouterContext: React.Context<MetaRouterInterface | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Provider for the MetaRouter analytics client.
|
|
10
|
+
* @param children - The children to render.
|
|
11
|
+
* @param instance - The analytics client instance.
|
|
12
|
+
*/
|
|
4
13
|
export declare const MetaRouterProvider: ({ children, instance, }: {
|
|
5
14
|
children: ReactNode;
|
|
6
15
|
instance: MetaRouterInterface;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,eAAO,MAAM,iBAAiB,2CAE7B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,yBAGhC;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,sBAMA,CAAC"}
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,2CAE7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,yBAGhC;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,sBAMA,CAAC"}
|
package/lib/react/context.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import React, { createContext } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Context for the MetaRouter analytics client.
|
|
4
|
+
* @param instance - The analytics client instance.
|
|
5
|
+
*/
|
|
2
6
|
export const MetaRouterContext = createContext(null);
|
|
7
|
+
/**
|
|
8
|
+
* Provider for the MetaRouter analytics client.
|
|
9
|
+
* @param children - The children to render.
|
|
10
|
+
* @param instance - The analytics client instance.
|
|
11
|
+
*/
|
|
3
12
|
export const MetaRouterProvider = ({ children, instance, }) => {
|
|
4
13
|
return (React.createElement(MetaRouterContext.Provider, { value: instance }, children));
|
|
5
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMetaRouter.d.ts","sourceRoot":"","sources":["../../src/react/useMetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,aAAa,QAAO;IAAE,SAAS,EAAE,kBAAkB,CAAA;CAQ7D,CAAC"}
|
|
1
|
+
{"version":3,"file":"useMetaRouter.d.ts","sourceRoot":"","sources":["../../src/react/useMetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAO;IAAE,SAAS,EAAE,kBAAkB,CAAA;CAQ7D,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { MetaRouterContext } from "./context";
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook to access the MetaRouter analytics client.
|
|
5
|
+
* @returns The analytics client instance.
|
|
6
|
+
*/
|
|
3
7
|
export const useMetaRouter = () => {
|
|
4
8
|
const ctx = useContext(MetaRouterContext);
|
|
5
9
|
if (!ctx)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metarouter/react-native-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"clean": "rm -rf lib",
|
|
19
19
|
"build": "tsc --project tsconfig.build.json",
|
|
20
20
|
"prepare": "npm run build",
|
|
21
|
-
"
|
|
21
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
22
22
|
"test": "jest"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enrichEvent.d.ts","sourceRoot":"","sources":["../../src/analytics/enrichEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAI,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAIpE,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,GACf,oBAAoB,CAUtB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getContextInfo } from "./utils/contextInfo";
|
|
2
|
-
export function enrichEvent(event, writeKey) {
|
|
3
|
-
const enriched = {
|
|
4
|
-
...event,
|
|
5
|
-
writeKey,
|
|
6
|
-
messageId: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
|
|
7
|
-
sentAt: new Date().toISOString(),
|
|
8
|
-
context: getContextInfo(),
|
|
9
|
-
};
|
|
10
|
-
return enriched;
|
|
11
|
-
}
|