Skip to content

Commit

Permalink
Campaign opened_app analytics (#419)
Browse files Browse the repository at this point in the history
* first draft of client side changes needed for campaign analytics

* chagne to campaign name

* clean up

* going with campaigns id

* use the notification meta data instead
  • Loading branch information
KennyHuRadar authored Dec 10, 2024
1 parent 65844f2 commit b5d7635
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 26 deletions.
11 changes: 0 additions & 11 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,6 @@ + (void)logConversionWithNotification:(UNNotificationRequest *)request
deliveredAfter:(NSDate *)deliveredAfter {

NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:request.content.userInfo];
NSDictionary<NSString *, NSString *> *result = [RadarUtils
extractGeofenceIdAndTimestampFromIdentifier:request.identifier];
if (result) {
NSString *geofenceId = result[@"geofenceId"];
[metadata setValue:geofenceId forKey:@"geofenceId"];
NSString *timestamp = result[@"registeredAt"];
[metadata setValue:timestamp forKey:@"registeredAt"];
if (deliveredAfter) {
[metadata setObject:deliveredAfter forKey:@"deliveredAfter"];
}
}

if (conversionSource) {
[metadata setValue:conversionSource forKey:@"conversionSource"];
Expand Down
11 changes: 11 additions & 0 deletions RadarSDK/RadarLocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ - (void)replaceSyncedGeofences:(NSArray<RadarGeofence *> *)geofences {
NSString *notificationTitle = [geofence.metadata objectForKey:@"radar:notificationTitle"];
NSString *notificationSubtitle = [geofence.metadata objectForKey:@"radar:notificationSubtitle"];
NSString *notificationURL = [geofence.metadata objectForKey:@"radar:notificationURL"];
NSString *campaignId = [geofence.metadata objectForKey:@"radar:campaignId"];
if (notificationText) {
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
if (notificationTitle) {
Expand All @@ -569,9 +570,19 @@ - (void)replaceSyncedGeofences:(NSArray<RadarGeofence *> *)geofences {
content.body = [NSString localizedUserNotificationStringForKey:notificationText arguments:nil];

NSMutableDictionary *mutableUserInfo = [geofence.metadata mutableCopy];

mutableUserInfo[@"geofenceId"] = geofence._id;
NSDate *now = [NSDate new];
NSTimeInterval lastSyncInterval = [now timeIntervalSince1970];
mutableUserInfo[@"registeredAt"] = [NSString stringWithFormat:@"%f", lastSyncInterval];

if (notificationURL) {
mutableUserInfo[@"url"] = notificationURL;
}

if (campaignId) {
mutableUserInfo[@"campaignId"] = campaignId;
}

content.userInfo = [mutableUserInfo copy];

Expand Down
3 changes: 1 addition & 2 deletions RadarSDK/RadarNotificationHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ + (void)checkNotificationPermissionsWithCompletionHandler:(NotificationPermissio
if (completionHandler) {
completionHandler(NO);
}
}

}
}

@end
1 change: 0 additions & 1 deletion RadarSDK/RadarUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (CLLocation *)locationForDictionary:(NSDictionary *_Nonnull)dict;
+ (NSDictionary *)dictionaryForLocation:(CLLocation *)location;
+ (NSString *)dictionaryToJson:(NSDictionary *)dict;
+ (NSDictionary<NSString *, NSString *> *)extractGeofenceIdAndTimestampFromIdentifier:(NSString *)identifier;
+ (void)runOnMainThread:(dispatch_block_t)block;

@end
Expand Down
12 changes: 0 additions & 12 deletions RadarSDK/RadarUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,6 @@ + (NSString *)dictionaryToJson:(NSDictionary *)dict {
}
}

+ (NSDictionary<NSString *, NSString *> *)extractGeofenceIdAndTimestampFromIdentifier:(NSString *)identifier {
NSArray<NSString *> *components = [identifier componentsSeparatedByString:@"_"];
if (components.count != 4) {
return nil; // Invalid format
}

NSString *geofenceId = components[2];
NSString *registeredAt = components[3];

return @{@"geofenceId": geofenceId, @"registeredAt": registeredAt};
}

#pragma mark - threading

+ (void)runOnMainThread:(dispatch_block_t)block {
Expand Down

0 comments on commit b5d7635

Please sign in to comment.