Skip to content

Commit d863d68

Browse files
committed
WIP: analytics
1 parent b4ec99b commit d863d68

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ firestack.database
564564
});
565565
```
566566

567+
#### DatabaseRef
568+
569+
Firestack attempts to provide the same API as the JS Firebase library for both Android and iOS platforms.
570+
571+
// TODO: Finish documenting
572+
567573
### ServerValue
568574

569575
Firebase provides some static values based upon the server. We can use the `ServerValue` constant to retrieve these. For instance, to grab the TIMESTAMP on the server, use the `TIMESTAMP` value:
@@ -590,6 +596,11 @@ To unsubscribe to events fired by Firebase, we can call the `off()` method with
590596
firestack.off('listenForAuth');
591597
```
592598

599+
## FirestackModule
600+
601+
Firestack provides a built-in way to connect your Redux app using the `FirestackModule` export from Firestack.
602+
603+
593604
## Contributing
594605

595606
This is _open-source_ software and we can make it rock for everyone through contributions.

ios/Firestack/Firestack.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ @implementation Firestack
6868
} else if ([opts valueForKey:@"appId"]) {
6969
[props setValue:[opts valueForKey:@"appId"] forKey:@"googleAppID"];
7070
}
71+
72+
// If we have an app id but no tracking id
73+
if (![opts valueForKey:@"trackingID"] && [opts valueForKey:@"googleAppID"]) {
74+
[props setValue:[opts valueForKey:@"googleAppID"] forKey:@"trackingID"];
75+
}
7176

7277
@try {
7378
FIROptions *finalOptions = [[FIROptions alloc]
@@ -91,10 +96,10 @@ @implementation Firestack
9196
NSDictionary *cfg = [self getConfig];
9297
[cfg setValuesForKeysWithDictionary:props];
9398

94-
if (!self.configured) {
99+
// if (!self.configured) {
95100
[FIRApp configureWithOptions:finalOptions];
96-
self->_configured = YES;
97-
}
101+
// self->_configured = YES;
102+
// }
98103
callback(@[[NSNull null]]);
99104
}
100105
@catch (NSException *exception) {

ios/Firestack/FirestackAnalytics.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ @implementation FirestackAnalytics
1414

1515
RCT_EXPORT_MODULE(FirestackAnalytics);
1616

17+
- (void)dealloc
18+
{
19+
[[NSNotificationCenter defaultCenter] removeObserver:self];
20+
}
21+
1722
RCT_EXPORT_METHOD(logEventWithName:(NSString *)name
1823
props:(NSDictionary *)props
1924
callback:(RCTResponseSenderBlock) callback)
@@ -23,4 +28,25 @@ @implementation FirestackAnalytics
2328
callback(@[[NSNull null], @YES]);
2429
}
2530

31+
RCT_EXPORT_METHOD(setEnabled:(BOOL) enabled
32+
callback:(RCTResponseSenderBlock) callback)
33+
{
34+
[[FIRAnalyticsConfiguration sharedInstance] setAnalyticsCollectionEnabled:enabled];
35+
callback(@[[NSNull null], @YES]);
36+
}
37+
38+
RCT_EXPORT_METHOD(setUser: (NSString *) id
39+
props:(NSDictionary *) props
40+
callback:(RCTResponseSenderBlock) callback)
41+
{
42+
[FIRAnalytics setUserID:id];
43+
NSMutableArray *allKeys = [[props allKeys] mutableCopy];
44+
for (NSString *key in allKeys) {
45+
NSString *val = [props valueForKey:key];
46+
[FIRAnalytics setUserPropertyString:val forName:key];
47+
}
48+
49+
callback(@[[NSNull null], @YES]);
50+
}
51+
2652
@end

lib/modules/analytics.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ export class Analytics extends Base {
2323
return promisify('logEventWithName', FirestackAnalytics)(name, props);
2424
}
2525

26+
enable() {
27+
return promisify('setEnabled', FirestackAnalytics)(true);
28+
}
29+
30+
disable() {
31+
return promisify('setEnabled', FirestackAnalytics)(false);
32+
}
33+
34+
setUser(id, properties={}) {
35+
return promisify('setUserId', FirestackAnalytics)(id, properties);
36+
}
37+
2638
get namespace() {
2739
return 'firestack:analytics'
2840
}

0 commit comments

Comments
 (0)