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 74cc051
Showing 1 changed file with 4 additions and 11 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,6 +134,10 @@ + (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];

if (!notificationId || !campaign) {
return;
}

[self logEventWithName:@"os_notification_influence_open"
parameters:@{
@"source": @"OneSignal",
Expand Down

0 comments on commit 74cc051

Please sign in to comment.