diff --git a/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/Influence/OSChannelTracker.m b/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/Influence/OSChannelTracker.m index cdade0b23..d712247aa 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/Influence/OSChannelTracker.m +++ b/iOS_SDK/OneSignalSDK/OneSignalOutcomes/Source/Influence/OSChannelTracker.m @@ -139,9 +139,13 @@ - (OSInfluence *)currentSessionInfluence { if (_influenceType == DIRECT) { if ([self isDirectSessionEnabled]) { - NSArray *ids = [NSArray arrayWithObject:_directId]; - builder.ids = ids; - builder.influenceType = DIRECT; + if (_directId) { + NSArray *ids = [NSArray arrayWithObject:_directId]; + builder.ids = ids; + builder.influenceType = DIRECT; + } else { + [OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"OSChannelTracker:currentSessionInfluence found a direct influence without a direct id."]; + } } } else if (_influenceType == INDIRECT) { if ([self isIndirectSessionEnabled]) { diff --git a/iOS_SDK/OneSignalSDK/UnitTests/ChannelTrackersTests.m b/iOS_SDK/OneSignalSDK/UnitTests/ChannelTrackersTests.m index a2a14a315..94fe34f25 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/ChannelTrackersTests.m +++ b/iOS_SDK/OneSignalSDK/UnitTests/ChannelTrackersTests.m @@ -32,6 +32,7 @@ #import "OneSignalHelper.h" #import "UnitTestCommonMethods.h" +#import "OSNotificationTracker.h" #import "CommonAsserts.h" @interface ChannelTrackersTests : XCTestCase @@ -167,4 +168,19 @@ - (void)testGetChannelToResetByEntryAction { XCTAssertEqualObjects(@"iam_id", [[[trackerFactory channelsToResetByEntryAction:NOTIFICATION_CLICK] objectAtIndex:0] idTag]); } +- (void)testDirectInfluenceWithNullId { + [self setOutcomesParamsEnabled]; + OSNotificationTracker *channelTracker = [[OSNotificationTracker alloc] initWithRepository:[OSInfluenceDataRepository sharedInfluenceDataRepository]]; + // Set the influence type to direct but do not set the direct id + channelTracker.influenceType = DIRECT; + OSInfluence *influence = [channelTracker currentSessionInfluence]; + // The current influence was invalid so the type should be disabled + XCTAssertEqual(influence.influenceType, DISABLED); + // Set the directId + channelTracker.directId = @"testid"; + influence = [channelTracker currentSessionInfluence]; + // Now that the directId is set the influence should be valid. + XCTAssertEqual(influence.influenceType, DIRECT); +} + @end