Skip to content

Commit

Permalink
Update trackReceivedEvent to allow Firebase influence
Browse files Browse the repository at this point in the history
Cherry pick of #1241

Also adding crash protection against a nil notificaiton id and campaign
  • Loading branch information
emawby committed Aug 10, 2023
1 parent 9ef9c26 commit 10f3472
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,11 @@ + (void)trackOpenEvent:(OSNotificationClickEvent*)event {
}

+ (void)trackReceivedEvent:(OSNotification*)notification {
if (!trackingEnabled)
return;

NSString *campaign = [self getCampaignNameFromNotification:notification];
OneSignalUserDefaults *sharedUserDefaults = OneSignalUserDefaults.initShared;
[sharedUserDefaults saveStringForKey:ONESIGNAL_FB_LAST_NOTIFICATION_ID_RECEIVED withValue:notification.notificationId];
[sharedUserDefaults saveStringForKey:ONESIGNAL_FB_LAST_GAF_CAMPAIGN_RECEIVED withValue:campaign];
[sharedUserDefaults saveDoubleForKey:ONESIGNAL_FB_LAST_TIME_RECEIVED withValue:[[NSDate date] timeIntervalSince1970]];

[self logEventWithName:@"os_notification_received"
parameters:@{
@"source": @"OneSignal",
@"medium": @"notification",
@"notification_id": notification.notificationId,
@"campaign": campaign
}];
}

+ (void)trackInfluenceOpenEvent {
Expand All @@ -145,13 +134,19 @@ + (void)trackInfluenceOpenEvent {
NSString *notificationId = [sharedUserDefaults getSavedStringForKey:ONESIGNAL_FB_LAST_NOTIFICATION_ID_RECEIVED defaultValue:nil];
NSString *campaign = [sharedUserDefaults getSavedStringForKey:ONESIGNAL_FB_LAST_GAF_CAMPAIGN_RECEIVED defaultValue:nil];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{
@"source": @"OneSignal",
@"medium": @"notification"
}];

if (notificationId) {
params[@"notification_id"] = notificationId;
}
if (campaign) {
params[@"campaign"] = campaign;
}
[self logEventWithName:@"os_notification_influence_open"
parameters:@{
@"source": @"OneSignal",
@"medium": @"notification",
@"notification_id": notificationId,
@"campaign": campaign
}];
parameters:params];
}

@end

0 comments on commit 10f3472

Please sign in to comment.