8
8
#import " RNAnalytics.h"
9
9
10
10
#import < Analytics/SEGAnalytics.h>
11
+ #import < React/RCTBridge.h>
11
12
12
13
static NSMutableSet * RNAnalyticsIntegrations = nil ;
13
14
static NSLock * RNAnalyticsIntegrationsLock = nil ;
@@ -29,9 +30,11 @@ +(void)initialize {
29
30
30
31
RCT_EXPORT_MODULE ()
31
32
33
+ @synthesize bridge = _bridge;
34
+
32
35
RCT_EXPORT_METHOD (setup:(NSDictionary *)options) {
33
36
SEGAnalyticsConfiguration* config = [SEGAnalyticsConfiguration configurationWithWriteKey: options[@" ios" ][@" writeKey" ]];
34
-
37
+
35
38
config.recordScreenViews = [options[@" recordScreenViews" ] boolValue ];
36
39
config.trackApplicationLifecycleEvents = [options[@" trackAppLifecycleEvents" ] boolValue ];
37
40
config.trackAttributionData = [options[@" trackAttributionData" ] boolValue ];
@@ -44,6 +47,19 @@ +(void)initialize {
44
47
45
48
[SEGAnalytics debug: [options[@" debug" ] boolValue ]];
46
49
[SEGAnalytics setupWithConfiguration: config];
50
+
51
+ // On iOS we use method swizzling to intercept lifecycle events
52
+ // However, React-Native calls our library after applicationDidFinishLaunchingWithOptions: is called
53
+ // We fix this by manually calling this method at setup-time
54
+ // TODO(fathyb): We should probably implement a dedicated API on the native part
55
+ if (config.trackApplicationLifecycleEvents ) {
56
+ SEL selector = @selector (_applicationDidFinishLaunchingWithOptions: );
57
+
58
+ if ([SEGAnalytics.sharedAnalytics respondsToSelector: selector]) {
59
+ [SEGAnalytics.sharedAnalytics performSelector: selector
60
+ withObject: _bridge.launchOptions];
61
+ }
62
+ }
47
63
}
48
64
49
65
#define withContext (context ) @{@" context" : context}
0 commit comments