@metarouter/react-native-sdk 1.5.1 → 1.8.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 +190 -60
- package/android/build.gradle +41 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/metarouter/reactnative/MetaRouterNetworkMonitorModule.kt +119 -0
- package/android/src/main/java/com/metarouter/reactnative/MetaRouterPackage.kt +23 -0
- package/android/src/main/java/com/metarouter/reactnative/MetaRouterQueueStorageModule.kt +124 -0
- package/ios/MetaRouterNetworkMonitor.m +76 -0
- package/ios/MetaRouterQueueStorage.m +127 -0
- package/lib/analytics/MetaRouterAnalyticsClient.d.ts +71 -4
- package/lib/analytics/MetaRouterAnalyticsClient.d.ts.map +1 -1
- package/lib/analytics/MetaRouterAnalyticsClient.js +396 -112
- package/lib/analytics/dispatcher.d.ts +57 -1
- package/lib/analytics/dispatcher.d.ts.map +1 -1
- package/lib/analytics/dispatcher.js +231 -32
- package/lib/analytics/init.d.ts +8 -1
- package/lib/analytics/init.d.ts.map +1 -1
- package/lib/analytics/init.js +198 -37
- package/lib/analytics/lifecycle/lifecycleEvents.d.ts +52 -0
- package/lib/analytics/lifecycle/lifecycleEvents.d.ts.map +1 -0
- package/lib/analytics/lifecycle/lifecycleEvents.js +66 -0
- package/lib/analytics/persistence/NativeQueueStorage.d.ts +5 -0
- package/lib/analytics/persistence/NativeQueueStorage.d.ts.map +1 -0
- package/lib/analytics/persistence/NativeQueueStorage.js +59 -0
- package/lib/analytics/persistence/PersistentEventQueue.d.ts +96 -0
- package/lib/analytics/persistence/PersistentEventQueue.d.ts.map +1 -0
- package/lib/analytics/persistence/PersistentEventQueue.js +401 -0
- package/lib/analytics/persistence/types.d.ts +20 -0
- package/lib/analytics/persistence/types.d.ts.map +1 -0
- package/lib/analytics/persistence/types.js +10 -0
- package/lib/analytics/proxy/proxyClient.d.ts +30 -1
- package/lib/analytics/proxy/proxyClient.d.ts.map +1 -1
- package/lib/analytics/proxy/proxyClient.js +145 -23
- package/lib/analytics/types.d.ts +61 -4
- package/lib/analytics/types.d.ts.map +1 -1
- package/lib/analytics/utils/appContext.d.ts +20 -0
- package/lib/analytics/utils/appContext.d.ts.map +1 -0
- package/lib/analytics/utils/appContext.js +22 -0
- package/lib/analytics/utils/circuitBreaker.d.ts +4 -1
- package/lib/analytics/utils/circuitBreaker.d.ts.map +1 -1
- package/lib/analytics/utils/circuitBreaker.js +23 -14
- package/lib/analytics/utils/contextInfo.d.ts +8 -4
- package/lib/analytics/utils/contextInfo.d.ts.map +1 -1
- package/lib/analytics/utils/contextInfo.js +34 -27
- package/lib/analytics/utils/debouncedNetworkMonitor.d.ts +25 -0
- package/lib/analytics/utils/debouncedNetworkMonitor.d.ts.map +1 -0
- package/lib/analytics/utils/debouncedNetworkMonitor.js +68 -0
- package/lib/analytics/utils/initOptions.d.ts +22 -0
- package/lib/analytics/utils/initOptions.d.ts.map +1 -0
- package/lib/analytics/utils/initOptions.js +100 -0
- package/lib/analytics/utils/lifecycleStorage.d.ts +13 -0
- package/lib/analytics/utils/lifecycleStorage.d.ts.map +1 -0
- package/lib/analytics/utils/lifecycleStorage.js +35 -0
- package/lib/analytics/utils/networkMonitor.d.ts +30 -0
- package/lib/analytics/utils/networkMonitor.d.ts.map +1 -0
- package/lib/analytics/utils/networkMonitor.js +90 -0
- package/lib/analytics/utils/responseCategory.d.ts +14 -0
- package/lib/analytics/utils/responseCategory.d.ts.map +1 -0
- package/lib/analytics/utils/responseCategory.js +26 -0
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -3
- package/metarouter-react-native-sdk.podspec +19 -0
- package/package.json +6 -3
- package/react-native.config.js +15 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
package com.metarouter.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import java.io.File
|
|
8
|
+
|
|
9
|
+
class MetaRouterQueueStorageModule(
|
|
10
|
+
private val reactContext: ReactApplicationContext
|
|
11
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
12
|
+
|
|
13
|
+
override fun getName(): String = "MetaRouterQueueStorage"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns the path to the queue snapshot file.
|
|
17
|
+
* Location: Context.noBackupFilesDir/metarouter/disk-queue/queue.v1.json
|
|
18
|
+
*/
|
|
19
|
+
private fun snapshotFile(): File {
|
|
20
|
+
val noBackupDir = reactContext.noBackupFilesDir
|
|
21
|
+
return File(noBackupDir, "metarouter/disk-queue/queue.v1.json")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private fun ensureParentDirectory(file: File) {
|
|
25
|
+
val parent = file.parentFile
|
|
26
|
+
?: throw IllegalStateException("Snapshot file has no parent directory")
|
|
27
|
+
|
|
28
|
+
if (!parent.exists() && !parent.mkdirs()) {
|
|
29
|
+
throw IllegalStateException("Failed to create snapshot directory")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!parent.isDirectory) {
|
|
33
|
+
throw IllegalStateException("Snapshot parent path is not a directory")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private fun deleteIfExists(file: File, errorMessage: String) {
|
|
38
|
+
if (file.exists() && !file.delete()) {
|
|
39
|
+
throw IllegalStateException(errorMessage)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Cheap existence check — does not read the file contents.
|
|
45
|
+
* Used on boot so a large snapshot doesn't get fully parsed just to
|
|
46
|
+
* discover whether there's anything to drain.
|
|
47
|
+
*/
|
|
48
|
+
@ReactMethod
|
|
49
|
+
fun exists(promise: Promise) {
|
|
50
|
+
try {
|
|
51
|
+
promise.resolve(snapshotFile().exists())
|
|
52
|
+
} catch (e: Exception) {
|
|
53
|
+
promise.reject("EXISTS_ERROR", "Failed to check snapshot existence", e)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@ReactMethod
|
|
58
|
+
fun readSnapshot(promise: Promise) {
|
|
59
|
+
try {
|
|
60
|
+
val file = snapshotFile()
|
|
61
|
+
if (!file.exists()) {
|
|
62
|
+
promise.resolve(null)
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
val contents = file.readText(Charsets.UTF_8)
|
|
66
|
+
promise.resolve(contents)
|
|
67
|
+
} catch (e: Exception) {
|
|
68
|
+
promise.reject("READ_ERROR", "Failed to read queue snapshot", e)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@ReactMethod
|
|
73
|
+
fun writeSnapshot(data: String, promise: Promise) {
|
|
74
|
+
try {
|
|
75
|
+
val file = snapshotFile()
|
|
76
|
+
ensureParentDirectory(file)
|
|
77
|
+
|
|
78
|
+
val parent = file.parentFile
|
|
79
|
+
?: throw IllegalStateException("Snapshot file has no parent directory")
|
|
80
|
+
val tempFile = File(parent, "${file.name}.tmp")
|
|
81
|
+
val backupFile = File(parent, "${file.name}.bak")
|
|
82
|
+
|
|
83
|
+
deleteIfExists(tempFile, "Failed to clear stale temp snapshot")
|
|
84
|
+
tempFile.writeText(data, Charsets.UTF_8)
|
|
85
|
+
|
|
86
|
+
val hadExistingSnapshot = file.exists()
|
|
87
|
+
if (hadExistingSnapshot) {
|
|
88
|
+
deleteIfExists(backupFile, "Failed to clear stale backup snapshot")
|
|
89
|
+
if (!file.renameTo(backupFile)) {
|
|
90
|
+
deleteIfExists(tempFile, "Failed to clean up temp snapshot")
|
|
91
|
+
throw IllegalStateException("Failed to back up existing snapshot")
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!tempFile.renameTo(file)) {
|
|
96
|
+
deleteIfExists(tempFile, "Failed to clean up temp snapshot")
|
|
97
|
+
|
|
98
|
+
if (hadExistingSnapshot && backupFile.exists() && !backupFile.renameTo(file)) {
|
|
99
|
+
throw IllegalStateException(
|
|
100
|
+
"Failed to write queue snapshot and restore previous snapshot"
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw IllegalStateException("Failed to move temp snapshot into place")
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
deleteIfExists(backupFile, "Failed to delete snapshot backup")
|
|
108
|
+
promise.resolve(null)
|
|
109
|
+
} catch (e: Exception) {
|
|
110
|
+
promise.reject("WRITE_ERROR", "Failed to write queue snapshot", e)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@ReactMethod
|
|
115
|
+
fun deleteSnapshot(promise: Promise) {
|
|
116
|
+
try {
|
|
117
|
+
val file = snapshotFile()
|
|
118
|
+
deleteIfExists(file, "Failed to delete queue snapshot")
|
|
119
|
+
promise.resolve(null)
|
|
120
|
+
} catch (e: Exception) {
|
|
121
|
+
promise.reject("DELETE_ERROR", "Failed to delete queue snapshot", e)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
3
|
+
#import <Network/Network.h>
|
|
4
|
+
|
|
5
|
+
@interface MetaRouterNetworkMonitor : RCTEventEmitter <RCTBridgeModule>
|
|
6
|
+
@end
|
|
7
|
+
|
|
8
|
+
@implementation MetaRouterNetworkMonitor {
|
|
9
|
+
nw_path_monitor_t _monitor;
|
|
10
|
+
dispatch_queue_t _monitorQueue;
|
|
11
|
+
BOOL _isConnected;
|
|
12
|
+
BOOL _hasListeners;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
RCT_EXPORT_MODULE()
|
|
16
|
+
|
|
17
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
18
|
+
return NO;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (instancetype)init {
|
|
22
|
+
self = [super init];
|
|
23
|
+
if (self) {
|
|
24
|
+
_isConnected = YES; // optimistic default
|
|
25
|
+
_hasListeners = NO;
|
|
26
|
+
_monitorQueue = dispatch_queue_create("com.metarouter.network.monitor", DISPATCH_QUEUE_SERIAL);
|
|
27
|
+
_monitor = nw_path_monitor_create();
|
|
28
|
+
|
|
29
|
+
__weak typeof(self) weakSelf = self;
|
|
30
|
+
nw_path_monitor_set_update_handler(_monitor, ^(nw_path_t path) {
|
|
31
|
+
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
32
|
+
if (!strongSelf) return;
|
|
33
|
+
|
|
34
|
+
BOOL connected = (nw_path_get_status(path) == nw_path_status_satisfied);
|
|
35
|
+
BOOL changed = (connected != strongSelf->_isConnected);
|
|
36
|
+
strongSelf->_isConnected = connected;
|
|
37
|
+
|
|
38
|
+
if (changed && strongSelf->_hasListeners) {
|
|
39
|
+
[strongSelf sendEventWithName:@"onConnectivityChange"
|
|
40
|
+
body:@{@"isConnected": @(connected)}];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
nw_path_monitor_set_queue(_monitor, _monitorQueue);
|
|
45
|
+
nw_path_monitor_start(_monitor);
|
|
46
|
+
}
|
|
47
|
+
return self;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
51
|
+
return @[@"onConnectivityChange"];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (void)startObserving {
|
|
55
|
+
_hasListeners = YES;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (void)stopObserving {
|
|
59
|
+
_hasListeners = NO;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
RCT_EXPORT_METHOD(getCurrentStatus:(RCTPromiseResolveBlock)resolve
|
|
63
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
64
|
+
{
|
|
65
|
+
dispatch_async(_monitorQueue, ^{
|
|
66
|
+
resolve(@(self->_isConnected));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
- (void)dealloc {
|
|
71
|
+
if (_monitor) {
|
|
72
|
+
nw_path_monitor_cancel(_monitor);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTLog.h>
|
|
3
|
+
|
|
4
|
+
@interface MetaRouterQueueStorage : NSObject <RCTBridgeModule>
|
|
5
|
+
@end
|
|
6
|
+
|
|
7
|
+
@implementation MetaRouterQueueStorage
|
|
8
|
+
|
|
9
|
+
RCT_EXPORT_MODULE()
|
|
10
|
+
|
|
11
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
12
|
+
return NO;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns the path to the queue snapshot file.
|
|
17
|
+
* Location: Application Support/metarouter/disk-queue/queue.v1.json
|
|
18
|
+
* The directory is created on first write and marked as excluded from backup.
|
|
19
|
+
*/
|
|
20
|
+
- (NSString *)snapshotPath {
|
|
21
|
+
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
|
22
|
+
NSApplicationSupportDirectory, NSUserDomainMask, YES
|
|
23
|
+
);
|
|
24
|
+
NSString *appSupport = paths.firstObject;
|
|
25
|
+
return [appSupport stringByAppendingPathComponent:@"metarouter/disk-queue/queue.v1.json"];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Ensures the queue directory exists and is excluded from backup.
|
|
30
|
+
*/
|
|
31
|
+
- (BOOL)ensureDirectoryExists:(NSError **)error {
|
|
32
|
+
NSString *dir = [[self snapshotPath] stringByDeletingLastPathComponent];
|
|
33
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
34
|
+
|
|
35
|
+
if (![fm fileExistsAtPath:dir]) {
|
|
36
|
+
if (![fm createDirectoryAtPath:dir
|
|
37
|
+
withIntermediateDirectories:YES
|
|
38
|
+
attributes:nil
|
|
39
|
+
error:error]) {
|
|
40
|
+
return NO;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Mark directory as excluded from backup
|
|
45
|
+
NSURL *dirURL = [NSURL fileURLWithPath:dir];
|
|
46
|
+
return [dirURL setResourceValue:@YES
|
|
47
|
+
forKey:NSURLIsExcludedFromBackupKey
|
|
48
|
+
error:error];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Cheap existence check — does not read the file contents.
|
|
53
|
+
* Used on boot so a large snapshot doesn't get fully parsed just to
|
|
54
|
+
* discover whether there's anything to drain.
|
|
55
|
+
*/
|
|
56
|
+
RCT_EXPORT_METHOD(exists:(RCTPromiseResolveBlock)resolve
|
|
57
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
58
|
+
{
|
|
59
|
+
NSString *path = [self snapshotPath];
|
|
60
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
61
|
+
resolve(@([fm fileExistsAtPath:path]));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
RCT_EXPORT_METHOD(readSnapshot:(RCTPromiseResolveBlock)resolve
|
|
65
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
66
|
+
{
|
|
67
|
+
NSString *path = [self snapshotPath];
|
|
68
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
69
|
+
|
|
70
|
+
if (![fm fileExistsAtPath:path]) {
|
|
71
|
+
resolve([NSNull null]);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
NSError *error = nil;
|
|
76
|
+
NSString *contents = [NSString stringWithContentsOfFile:path
|
|
77
|
+
encoding:NSUTF8StringEncoding
|
|
78
|
+
error:&error];
|
|
79
|
+
if (error) {
|
|
80
|
+
reject(@"READ_ERROR", @"Failed to read queue snapshot", error);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
resolve(contents);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
RCT_EXPORT_METHOD(writeSnapshot:(NSString *)data
|
|
88
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
89
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
90
|
+
{
|
|
91
|
+
NSError *error = nil;
|
|
92
|
+
|
|
93
|
+
if (![self ensureDirectoryExists:&error]) {
|
|
94
|
+
reject(@"DIR_ERROR", @"Failed to create queue directory", error);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
NSString *path = [self snapshotPath];
|
|
99
|
+
if (![data writeToFile:path
|
|
100
|
+
atomically:YES
|
|
101
|
+
encoding:NSUTF8StringEncoding
|
|
102
|
+
error:&error]) {
|
|
103
|
+
reject(@"WRITE_ERROR", @"Failed to write queue snapshot", error);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
resolve([NSNull null]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
RCT_EXPORT_METHOD(deleteSnapshot:(RCTPromiseResolveBlock)resolve
|
|
111
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
112
|
+
{
|
|
113
|
+
NSString *path = [self snapshotPath];
|
|
114
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
115
|
+
|
|
116
|
+
if ([fm fileExistsAtPath:path]) {
|
|
117
|
+
NSError *error = nil;
|
|
118
|
+
if (![fm removeItemAtPath:path error:&error]) {
|
|
119
|
+
reject(@"DELETE_ERROR", @"Failed to delete queue snapshot", error);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
resolve([NSNull null]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { InitOptions, Lifecycle } from
|
|
1
|
+
import { InitOptions, Lifecycle } from './types';
|
|
2
|
+
import { type NetworkReachability, type NetworkStatus } from './utils/networkMonitor';
|
|
2
3
|
/**
|
|
3
4
|
* Analytics client for MetaRouter.
|
|
4
5
|
* - Handles event queueing, batching, and delivery with retries.
|
|
@@ -14,18 +15,31 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
14
15
|
private ingestionHost;
|
|
15
16
|
private writeKey;
|
|
16
17
|
private context;
|
|
18
|
+
private appContext;
|
|
17
19
|
private appState;
|
|
18
20
|
private appStateSubscription;
|
|
19
21
|
private identityManager;
|
|
20
|
-
private static readonly
|
|
21
|
-
private
|
|
22
|
+
private static readonly AUTO_FLUSH_THRESHOLD;
|
|
23
|
+
private static readonly MAX_QUEUE_BYTES;
|
|
24
|
+
private maxDiskEvents;
|
|
22
25
|
private dispatcher;
|
|
26
|
+
private persistentQueue;
|
|
23
27
|
private tracingEnabled;
|
|
28
|
+
private networkMonitor;
|
|
29
|
+
private networkStatus;
|
|
30
|
+
private unsubscribeNetwork;
|
|
31
|
+
private lifecycleEmitter;
|
|
32
|
+
private trackLifecycleEvents;
|
|
33
|
+
private pendingDeepLink;
|
|
34
|
+
private coldLaunchOpenDeferred;
|
|
35
|
+
private wasBackgrounded;
|
|
24
36
|
/**
|
|
25
37
|
* Initializes the analytics client with the provided options.
|
|
26
38
|
* @param options - The initialization options.
|
|
27
39
|
*/
|
|
28
|
-
constructor(options: InitOptions
|
|
40
|
+
constructor(options: InitOptions, deps?: {
|
|
41
|
+
networkMonitor?: NetworkReachability;
|
|
42
|
+
});
|
|
29
43
|
/**
|
|
30
44
|
* Initializes the analytics client.
|
|
31
45
|
* @returns A promise that resolves when the client is initialized.
|
|
@@ -50,6 +64,12 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
50
64
|
* @returns The current timestamp in ISO format.
|
|
51
65
|
*/
|
|
52
66
|
private now;
|
|
67
|
+
/**
|
|
68
|
+
* Adds identity, writeKey, context and messageId to a raw event. Shared by
|
|
69
|
+
* enqueue() and the lifecycle emitter so both paths produce identical
|
|
70
|
+
* payloads.
|
|
71
|
+
*/
|
|
72
|
+
private buildEnrichedEvent;
|
|
53
73
|
/**
|
|
54
74
|
* Enqueues an event for processing.
|
|
55
75
|
* @param event - The event to enqueue.
|
|
@@ -62,11 +82,49 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
62
82
|
* Sets up the app state listener.
|
|
63
83
|
*/
|
|
64
84
|
private setupAppStateListener;
|
|
85
|
+
/**
|
|
86
|
+
* Runs the cold-launch lifecycle sequence: detect install vs update vs
|
|
87
|
+
* neither, persist the current version/build, capture any cold-launch
|
|
88
|
+
* deep link, and (when the process is foregrounded) emit Application
|
|
89
|
+
* Opened with from_background=false.
|
|
90
|
+
*
|
|
91
|
+
* No-ops when trackLifecycleEvents is false.
|
|
92
|
+
*
|
|
93
|
+
* @param hadIdentityBeforeInit - Whether identity existed in storage before
|
|
94
|
+
* IdentityManager.init() ran on this launch (see init()).
|
|
95
|
+
*/
|
|
96
|
+
private runColdLaunchLifecycle;
|
|
97
|
+
/**
|
|
98
|
+
* True if any identity field is present in storage. Used to distinguish a
|
|
99
|
+
* fresh install from an existing user upgrading from a pre-lifecycle SDK
|
|
100
|
+
* build. Best-effort: failures are treated as "no identity state".
|
|
101
|
+
*/
|
|
102
|
+
private hasIdentityState;
|
|
103
|
+
private consumePendingDeepLink;
|
|
65
104
|
/**
|
|
66
105
|
* Handles the app state change event.
|
|
67
106
|
* @param nextState - The new app state.
|
|
68
107
|
*/
|
|
69
108
|
private handleAppStateChange;
|
|
109
|
+
/**
|
|
110
|
+
* Forward a URL the host received (e.g. from `Linking.getInitialURL`,
|
|
111
|
+
* `Linking.addEventListener('url', ...)`, a UIScene URL handler, or an
|
|
112
|
+
* Android Intent) so it is attached to the next `Application Opened`
|
|
113
|
+
* event as `url` (and `referring_application` if `sourceApplication`
|
|
114
|
+
* is provided). One-shot — the buffer is cleared on the next Opened
|
|
115
|
+
* emit. Last-write-wins if called multiple times before the next Opened.
|
|
116
|
+
*
|
|
117
|
+
* The SDK never reads `Linking` itself: deep links routinely carry auth
|
|
118
|
+
* tokens and OTPs, and an automatic capture would race the host's own
|
|
119
|
+
* sanitized forward for the same one-slot buffer. Only what the host
|
|
120
|
+
* passes here reaches the event (parity with iOS recordOpenedURL and
|
|
121
|
+
* Android recordOpenedUrl).
|
|
122
|
+
*
|
|
123
|
+
* No-op with an always-on warning when `trackLifecycleEvents` is
|
|
124
|
+
* disabled — silent no-ops are bad DX, hosts wiring this up should know
|
|
125
|
+
* they have the feature flag off.
|
|
126
|
+
*/
|
|
127
|
+
recordOpenedURL(url: string, sourceApplication?: string): void;
|
|
70
128
|
/**
|
|
71
129
|
* Tracks an event.
|
|
72
130
|
* @param event - The event to track.
|
|
@@ -139,6 +197,12 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
139
197
|
* Enable debug logging for troubleshooting
|
|
140
198
|
*/
|
|
141
199
|
enableDebugLogging(): void;
|
|
200
|
+
/**
|
|
201
|
+
* Returns the current anonymous ID managed by the JS identity layer.
|
|
202
|
+
* Awaits init() if it is still in-flight. Throws only if the client was
|
|
203
|
+
* never initialized or a reset() races with this call.
|
|
204
|
+
*/
|
|
205
|
+
getAnonymousId(): Promise<string>;
|
|
142
206
|
/**
|
|
143
207
|
* Get current state for debugging
|
|
144
208
|
*/
|
|
@@ -156,7 +220,10 @@ export declare class MetaRouterAnalyticsClient {
|
|
|
156
220
|
circuitState: import("./utils/circuitBreaker").CircuitState;
|
|
157
221
|
circuitRemainingMs: number;
|
|
158
222
|
maxQueueEvents: number;
|
|
223
|
+
maxDiskEvents: number;
|
|
159
224
|
tracingEnabled: boolean;
|
|
225
|
+
hasDiskData: boolean;
|
|
226
|
+
networkStatus: NetworkStatus;
|
|
160
227
|
}>;
|
|
161
228
|
/**
|
|
162
229
|
* Flushes the event queue to the ingestion endpoint in chunks.
|
|
@@ -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":"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"}
|