Skip to content

Commit ee8ec19

Browse files
committed
Extract first open time from analytics user properties
1 parent caac2ce commit ee8ec19

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

FirebaseRemoteConfig/Sources/RCNConfigSettings.m

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
static NSString *const kRCNGroupPrefix = @"frc.group.";
2929
static NSString *const kRCNUserDefaultsKeyNamelastETag = @"lastETag";
3030
static NSString *const kRCNUserDefaultsKeyNameLastSuccessfulFetchTime = @"lastSuccessfulFetchTime";
31+
static NSString *const kRCNAnlyticsFirstOpenTimePropertyName = @"_fot";
3132
static const int kRCNExponentialBackoffMinimumInterval = 60 * 2; // 2 mins.
3233
static const int kRCNExponentialBackoffMaximumInterval = 60 * 60 * 4; // 4 hours.
3334

@@ -359,16 +360,32 @@ - (NSString *)nextRequestWithUserProperties:(NSDictionary *)userProperties {
359360

360361
if (userProperties && userProperties.count > 0) {
361362
NSError *error;
362-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userProperties
363-
options:0
364-
error:&error];
365-
if (!error) {
366-
ret = [ret
367-
stringByAppendingString:[NSString
368-
stringWithFormat:@", analytics_user_properties:%@",
369-
[[NSString alloc]
370-
initWithData:jsonData
371-
encoding:NSUTF8StringEncoding]]];
363+
364+
// Extract first open time from user properties and send as a separate field
365+
NSNumber *firstOpenTime = [userProperties valueForKey:kRCNAnlyticsFirstOpenTimePropertyName];
366+
if (firstOpenTime) {
367+
NSDate *date = [NSDate dateWithTimeIntervalSince1970:([firstOpenTime longValue] / 1000)];
368+
NSISO8601DateFormatter *formatter = [[NSISO8601DateFormatter alloc] init];
369+
NSString *firstOpenTimeISOString = [formatter stringFromDate:date];
370+
ret = [ret stringByAppendingString:[NSString stringWithFormat:@", first_open_time:'%@'",
371+
firstOpenTimeISOString]];
372+
373+
NSMutableDictionary *userPropertiesCopy = [userProperties mutableCopy];
374+
[userPropertiesCopy removeObjectForKey:kRCNAnlyticsFirstOpenTimePropertyName];
375+
userProperties = userPropertiesCopy;
376+
}
377+
if (userProperties.count > 0) {
378+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userProperties
379+
options:0
380+
error:&error];
381+
if (!error) {
382+
ret = [ret
383+
stringByAppendingString:[NSString
384+
stringWithFormat:@", analytics_user_properties:%@",
385+
[[NSString alloc]
386+
initWithData:jsonData
387+
encoding:NSUTF8StringEncoding]]];
388+
}
372389
}
373390
}
374391
ret = [ret stringByAppendingString:@"}"];

0 commit comments

Comments
 (0)