diff --git a/Scripts/check_coverage.sh b/Scripts/check_coverage.sh index 4a640e879..94b696b26 100755 --- a/Scripts/check_coverage.sh +++ b/Scripts/check_coverage.sh @@ -1,3 +1,6 @@ +python3 -m venv venv +source venv/bin/activate + SCHEME="mParticle-Apple-SDK" DESTINATION="platform=iOS Simulator,name=iPhone 16 Pro,OS=latest" RESULT_BUNDLE_PATH="./build/TestResults.xcresult" @@ -13,4 +16,8 @@ xcodebuild test \ xcrun xccov view --report --json "$RESULT_BUNDLE_PATH" > ./build/coverage.json -python3 check_coverage.py +python check_coverage.py + +deactivate + +rm -rf venv diff --git a/UnitTests/MParticle+PrivateMethods.h b/UnitTests/MParticle+PrivateMethods.h index c7e8804f7..9de64415e 100644 --- a/UnitTests/MParticle+PrivateMethods.h +++ b/UnitTests/MParticle+PrivateMethods.h @@ -1,5 +1,6 @@ #import "SettingsProvider.h" #import "MParticleSwift.h" +#import "MPDataPlanFilter.h" @interface MParticle (Tests) - (void)setOptOutCompletion:(MPExecStatus)execStatus optOut:(BOOL)optOut; @@ -8,7 +9,12 @@ options:(MParticleOptions * _Nonnull)options; - (void)configureWithOptions:(MParticleOptions * _Nonnull)options; - (void)startWithKeyCallback:(BOOL)firstRun options:(MParticleOptions * _Nonnull)options userDefaults:(id)userDefaults; +- (void)beginTimedEventCompletionHandler:(MPEvent *)event execStatus:(MPExecStatus)execStatus; +- (void)logEventCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus; +- (void)logScreenCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus; @property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @property (nonatomic, strong) id settingsProvider; +@property (nonatomic, strong, nullable) id dataPlanFilter; @end + diff --git a/UnitTests/MParticleTestsSwift.swift b/UnitTests/MParticleTestsSwift.swift index a4e0e17a3..7f402331e 100644 --- a/UnitTests/MParticleTestsSwift.swift +++ b/UnitTests/MParticleTestsSwift.swift @@ -24,6 +24,7 @@ class MParticleTestsSwift: XCTestCase { override func tearDown() { super.tearDown() receivedMessage = nil + mparticle.dataPlanFilter = nil } func testSetOptOutCompletionSuccess() { @@ -140,4 +141,94 @@ class MParticleTestsSwift: XCTestCase { XCTAssertFalse(userDefaults.setMPObjectCalled) XCTAssertFalse(userDefaults.synchronizeCalled) } + + func testBeginTimedEventCompletionHandlerDataFilterNotSet() { + XCTAssertNil(mparticle.dataPlanFilter) + + mparticle.beginTimedEventCompletionHandler(MPEvent(), execStatus: .success) + XCTAssertEqual(receivedMessage, """ + mParticle -> Began timed event: Event:{ + Name: <> + Type: Other + Duration: 0 + } + """ + ) + } + + func testBeginTimedEventCompletionHandlerDataFilterSetDataFilterReturnNil() { + let dataPlanFilter = MPDataPlanFilterMock() + mparticle.dataPlanFilter = dataPlanFilter + let expectedEvent = MPEvent() + + mparticle.beginTimedEventCompletionHandler(expectedEvent, execStatus: .success) + XCTAssertTrue(dataPlanFilter.transformEventCalled) + XCTAssertTrue(dataPlanFilter.transformEventEventParam === expectedEvent) + XCTAssertEqual(receivedMessage, """ + mParticle -> Blocked timed event begin from kits: Event:{ + Name: <> + Type: Other\n Duration: 0 + } + """ + ) + } + + func testLogEventCallbackDataFilterNotSet() { + XCTAssertNil(mparticle.dataPlanFilter) + mparticle.logEventCallback(MPEvent(), execStatus: .success) + + XCTAssertNil(receivedMessage) + } + + func testLogEventCallbackDataFilterSetDataFilterReturnNil() { + let dataPlanFilter = MPDataPlanFilterMock() + mparticle.dataPlanFilter = dataPlanFilter + let expectedEvent = MPEvent() + mparticle.logEventCallback(expectedEvent, execStatus: .success) + + XCTAssertTrue(dataPlanFilter.transformEventCalled) + XCTAssertTrue(dataPlanFilter.transformEventEventParam === expectedEvent) + + XCTAssertEqual(receivedMessage, """ + mParticle -> Blocked timed event end from kits: Event:{ + Name: <> + Type: Other + Duration: 0 + } + """ + ) + } + + func testLogScreenCallbackDataFilterNotSet() { + XCTAssertNil(mparticle.dataPlanFilter) + mparticle.logScreenCallback(MPEvent(), execStatus: .success) + + XCTAssertEqual(receivedMessage, """ + mParticle -> Logged screen event: Event:{ + Name: <> + Type: Other + Duration: 0 + } + """ + ) + } + + func testLogScreenCallbackDataFilterSetDataFilterReturnNil() { + let dataPlanFilter = MPDataPlanFilterMock() + mparticle.dataPlanFilter = dataPlanFilter + let expectedEvent = MPEvent() + mparticle.logScreenCallback(expectedEvent, execStatus: .success) + + XCTAssertTrue(dataPlanFilter.transformEventForScreenEventCalled) + XCTAssertTrue(dataPlanFilter.transformEventForScreenEventScreenEventParam === expectedEvent) + + XCTAssertEqual(receivedMessage, """ + mParticle -> Blocked screen event from kits: Event:{ + Name: <> + Type: Other + Duration: 0 + } + """ + ) + } } diff --git a/UnitTests/Mocks/MPDataPlanFilterMock.swift b/UnitTests/Mocks/MPDataPlanFilterMock.swift new file mode 100644 index 000000000..60767b6db --- /dev/null +++ b/UnitTests/Mocks/MPDataPlanFilterMock.swift @@ -0,0 +1,48 @@ +import XCTest +#if MPARTICLE_LOCATION_DISABLE +import mParticle_Apple_SDK_NoLocation +#else +import mParticle_Apple_SDK +#endif + +class MPDataPlanFilterMock: NSObject, MPDataPlanFilterProtocol { + var isBlockedUserIdentityTypeCalled = false + var isBlockedUserIdentityTypeUserIdentityTypeParam: MPIdentity? + var isBlockedUserIdentityTypeReturnValue: Bool = false + + func isBlockedUserIdentityType(_ userIdentityType: MPIdentity) -> Bool { + isBlockedUserIdentityTypeCalled = true + isBlockedUserIdentityTypeUserIdentityTypeParam = userIdentityType + return isBlockedUserIdentityTypeReturnValue + } + + var isBlockedUserAttributeKeyCalled = false + var isBlockedUserAttributeKeyUserAttributeKeyParam: String? + var isBlockedUserAttributeKeyReturnValue: Bool = false + + func isBlockedUserAttributeKey(_ userAttributeKey: String) -> Bool { + isBlockedUserAttributeKeyCalled = true + isBlockedUserAttributeKeyUserAttributeKeyParam = userAttributeKey + return isBlockedUserAttributeKeyReturnValue + } + + var transformEventCalled = false + var transformEventEventParam: MPEvent? + var transformEventReturnValue: MPEvent? + + func transformEvent(for event: MPEvent) -> MPEvent? { + transformEventCalled = true + transformEventEventParam = event + return transformEventReturnValue + } + + var transformEventForScreenEventCalled = false + var transformEventForScreenEventScreenEventParam: MPEvent? + var transformEventForScreenEventReturnValue: MPEvent? + + func transformEvent(forScreenEvent screenEvent: MPEvent) -> MPEvent? { + transformEventForScreenEventCalled = true + transformEventForScreenEventScreenEventParam = screenEvent + return transformEventForScreenEventReturnValue + } +} diff --git a/UnitTests/MPUserDefaultsMock.swift b/UnitTests/Mocks/MPUserDefaultsMock.swift similarity index 99% rename from UnitTests/MPUserDefaultsMock.swift rename to UnitTests/Mocks/MPUserDefaultsMock.swift index 2497698ae..821d61b49 100644 --- a/UnitTests/MPUserDefaultsMock.swift +++ b/UnitTests/Mocks/MPUserDefaultsMock.swift @@ -25,3 +25,5 @@ class MPUserDefaultsMock: MPUserDefaultsProtocol { synchronizeCalled = true } } + + diff --git a/UnitTests/Mocks/SettingsProviderMock.swift b/UnitTests/Mocks/SettingsProviderMock.swift new file mode 100644 index 000000000..4cbcedcea --- /dev/null +++ b/UnitTests/Mocks/SettingsProviderMock.swift @@ -0,0 +1,10 @@ +import XCTest +#if MPARTICLE_LOCATION_DISABLE +import mParticle_Apple_SDK_NoLocation +#else +import mParticle_Apple_SDK +#endif + +class SettingsProviderMock: NSObject, SettingsProviderProtocol { + var configSettings: NSMutableDictionary? +} diff --git a/UnitTests/SettingsProviderMock.h b/UnitTests/SettingsProviderMock.h deleted file mode 100644 index 0150eec57..000000000 --- a/UnitTests/SettingsProviderMock.h +++ /dev/null @@ -1,5 +0,0 @@ -#import "SettingsProvider.h" - -@interface SettingsProviderMock : NSObject -@property (nonatomic, strong, nullable) NSMutableDictionary *configSettings; -@end diff --git a/UnitTests/SettingsProviderMock.m b/UnitTests/SettingsProviderMock.m deleted file mode 100644 index 01782e375..000000000 --- a/UnitTests/SettingsProviderMock.m +++ /dev/null @@ -1,4 +0,0 @@ -#import "SettingsProviderMock.h" - -@implementation SettingsProviderMock -@end diff --git a/UnitTests/mParticle_iOS_SDKTests-Bridging-Header.h b/UnitTests/mParticle_iOS_SDKTests-Bridging-Header.h index 79c4925d7..e05148bcc 100644 --- a/UnitTests/mParticle_iOS_SDKTests-Bridging-Header.h +++ b/UnitTests/mParticle_iOS_SDKTests-Bridging-Header.h @@ -6,4 +6,3 @@ #import "MParticleOptions+MParticlePrivate.h" #import "MParticle+PrivateMethods.h" #import "SettingsProvider.h" -#import "SettingsProviderMock.h" diff --git a/mParticle-Apple-SDK.xcodeproj/project.pbxproj b/mParticle-Apple-SDK.xcodeproj/project.pbxproj index b4df1cd6f..9f0b4f59e 100644 --- a/mParticle-Apple-SDK.xcodeproj/project.pbxproj +++ b/mParticle-Apple-SDK.xcodeproj/project.pbxproj @@ -17,6 +17,10 @@ 35329FF32E54CA78009AC4FD /* MParticleOptions+MParticlePrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = 35329FF12E54CA78009AC4FD /* MParticleOptions+MParticlePrivate.m */; }; 35329FF52E54CB8C009AC4FD /* MParticleOptions+MParticlePrivateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */; }; 35329FF62E54CB8C009AC4FD /* MParticleOptions+MParticlePrivateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */; }; + 356D4A592E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */; }; + 356D4A5A2E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */; }; + 356D4A5C2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */; }; + 356D4A5D2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */; }; 359BAFE82E55ED8900A8A704 /* MParticleTestsSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */; }; 359BAFE92E55ED8900A8A704 /* MParticleTestsSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */; }; 359BAFF92E56330200A8A704 /* SettingsProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 359BAFF82E56330200A8A704 /* SettingsProvider.h */; }; @@ -25,8 +29,6 @@ 359BAFFD2E56335300A8A704 /* SettingsProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFFB2E56335300A8A704 /* SettingsProvider.m */; }; 359BAFFF2E575B0300A8A704 /* SettingsProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */; }; 359BB0002E575B0300A8A704 /* SettingsProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */; }; - 359BB0032E57769E00A8A704 /* SettingsProviderMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0022E57769E00A8A704 /* SettingsProviderMock.m */; }; - 359BB0042E57769E00A8A704 /* SettingsProviderMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0022E57769E00A8A704 /* SettingsProviderMock.m */; }; 359BB0062E57A56800A8A704 /* MPUserDefaultsMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */; }; 359BB0072E57A56800A8A704 /* MPUserDefaultsMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */; }; 35E3FCC02E53B55900DB5B18 /* MPAttributionResult+MParticlePrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = 35E3FCBF2E53B55900DB5B18 /* MPAttributionResult+MParticlePrivate.m */; }; @@ -562,13 +564,13 @@ 35329FEE2E54CA49009AC4FD /* MParticleOptions+MParticlePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MParticleOptions+MParticlePrivate.h"; sourceTree = ""; }; 35329FF12E54CA78009AC4FD /* MParticleOptions+MParticlePrivate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MParticleOptions+MParticlePrivate.m"; sourceTree = ""; }; 35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MParticleOptions+MParticlePrivateTests.swift"; sourceTree = ""; }; + 356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsProviderMock.swift; sourceTree = ""; }; + 356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDataPlanFilterMock.swift; sourceTree = ""; }; 359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MParticleTestsSwift.swift; sourceTree = ""; }; 359BAFEA2E55EE0C00A8A704 /* MParticle+PrivateMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MParticle+PrivateMethods.h"; sourceTree = ""; }; 359BAFF82E56330200A8A704 /* SettingsProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsProvider.h; sourceTree = ""; }; 359BAFFB2E56335300A8A704 /* SettingsProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsProvider.m; sourceTree = ""; }; 359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsProviderTests.swift; sourceTree = ""; }; - 359BB0012E57769600A8A704 /* SettingsProviderMock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsProviderMock.h; sourceTree = ""; }; - 359BB0022E57769E00A8A704 /* SettingsProviderMock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsProviderMock.m; sourceTree = ""; }; 359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPUserDefaultsMock.swift; sourceTree = ""; }; 35E3FCBF2E53B55900DB5B18 /* MPAttributionResult+MParticlePrivate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MPAttributionResult+MParticlePrivate.m"; sourceTree = ""; }; 35E3FCC22E53B5C200DB5B18 /* MPAttributionResult+MParticlePrivateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MPAttributionResult+MParticlePrivateTests.swift"; sourceTree = ""; }; @@ -878,6 +880,16 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 356D4A572E58B01100CB69FE /* Mocks */ = { + isa = PBXGroup; + children = ( + 356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */, + 359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */, + 356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */, + ); + path = Mocks; + sourceTree = ""; + }; 53A79A6F29CCCD6400E7489F = { isa = PBXGroup; children = ( @@ -1243,11 +1255,9 @@ 53A79C6729CE019E00E7489F /* UnitTests */ = { isa = PBXGroup; children = ( - 359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */, + 356D4A572E58B01100CB69FE /* Mocks */, 359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */, 359BAFEA2E55EE0C00A8A704 /* MParticle+PrivateMethods.h */, - 359BB0022E57769E00A8A704 /* SettingsProviderMock.m */, - 359BB0012E57769600A8A704 /* SettingsProviderMock.h */, 359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */, 35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */, 35329FEB2E54C480009AC4FD /* MPNetworkOptions+MParticlePrivateTests.swift */, @@ -1710,12 +1720,13 @@ 534CD26629CE2CE1008452B3 /* MPUserIdentityChangeTests.m in Sources */, 534CD26729CE2CE1008452B3 /* MPConsentKitFilterTests.m in Sources */, 359BAFFF2E575B0300A8A704 /* SettingsProviderTests.swift in Sources */, + 356D4A5D2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */, 534CD26829CE2CE1008452B3 /* MPConnectorTests.m in Sources */, 534CD26929CE2CE1008452B3 /* MPSurrogateAppDelegateTests.m in Sources */, 534CD26A29CE2CE1008452B3 /* MPGDPRConsentTests.m in Sources */, + 356D4A5A2E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */, 534CD26B29CE2CE1008452B3 /* MPBackendControllerTests.m in Sources */, 534CD26C29CE2CE1008452B3 /* MPKitConfigurationTests.mm in Sources */, - 359BB0042E57769E00A8A704 /* SettingsProviderMock.m in Sources */, 534CD26E29CE2CE1008452B3 /* MPNetworkCommunicationTests.m in Sources */, 534CD26F29CE2CE1008452B3 /* MPAliasRequestTests.m in Sources */, 534CD27029CE2CE1008452B3 /* MPAliasResponseTests.m in Sources */, @@ -1896,12 +1907,13 @@ 53A79CC229CE019F00E7489F /* MPUserIdentityChangeTests.m in Sources */, 53A79CC129CE019F00E7489F /* MPConsentKitFilterTests.m in Sources */, 359BB0002E575B0300A8A704 /* SettingsProviderTests.swift in Sources */, + 356D4A5C2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */, 53A79CD029CE019F00E7489F /* MPConnectorTests.m in Sources */, 53A79CD129CE019F00E7489F /* MPSurrogateAppDelegateTests.m in Sources */, 53A79CE729CE019F00E7489F /* MPGDPRConsentTests.m in Sources */, + 356D4A592E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */, 53A79CD229CE019F00E7489F /* MPBackendControllerTests.m in Sources */, 53A79CF329CE019F00E7489F /* MPKitConfigurationTests.mm in Sources */, - 359BB0032E57769E00A8A704 /* SettingsProviderMock.m in Sources */, 53A79CDC29CE019F00E7489F /* MPSwiftTests.swift in Sources */, 53A79CBE29CE019F00E7489F /* MPNetworkCommunicationTests.m in Sources */, 53A79CF429CE019F00E7489F /* MPAliasRequestTests.m in Sources */, diff --git a/mParticle-Apple-SDK.xcodeproj/xcshareddata/xcschemes/mParticle-Apple-SDK.xcscheme b/mParticle-Apple-SDK.xcodeproj/xcshareddata/xcschemes/mParticle-Apple-SDK.xcscheme index 590dcf9e3..56911eca3 100644 --- a/mParticle-Apple-SDK.xcodeproj/xcshareddata/xcschemes/mParticle-Apple-SDK.xcscheme +++ b/mParticle-Apple-SDK.xcodeproj/xcshareddata/xcschemes/mParticle-Apple-SDK.xcscheme @@ -26,7 +26,25 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES" + onlyGenerateCoverageForSpecifiedTargets = "YES"> + + + + + + diff --git a/mParticle-Apple-SDK/Identity/FilteredMParticleUser.m b/mParticle-Apple-SDK/Identity/FilteredMParticleUser.m index 570933e51..4e5b93200 100644 --- a/mParticle-Apple-SDK/Identity/FilteredMParticleUser.m +++ b/mParticle-Apple-SDK/Identity/FilteredMParticleUser.m @@ -7,7 +7,7 @@ @interface MParticle () -@property (nonatomic, strong) MPDataPlanFilter *dataPlanFilter; +@property (nonatomic, strong) id dataPlanFilter; @end diff --git a/mParticle-Apple-SDK/Kits/MPDataPlanFilter.h b/mParticle-Apple-SDK/Kits/MPDataPlanFilter.h index a13b8fa29..eb182e5f8 100644 --- a/mParticle-Apple-SDK/Kits/MPDataPlanFilter.h +++ b/mParticle-Apple-SDK/Kits/MPDataPlanFilter.h @@ -5,7 +5,16 @@ NS_ASSUME_NONNULL_BEGIN -@interface MPDataPlanFilter: NSObject +@protocol MPDataPlanFilterProtocol + +- (BOOL)isBlockedUserIdentityType:(MPIdentity)userIdentityType; +- (BOOL)isBlockedUserAttributeKey:(NSString *)userAttributeKey; +- (MPEvent * _Nullable)transformEventForEvent:(MPEvent *)event; +- (MPEvent * _Nullable)transformEventForScreenEvent:(MPEvent *)screenEvent; + +@end + +@interface MPDataPlanFilter: NSObject - (NSMutableDictionary *> *)getPointInfo; diff --git a/mParticle-Apple-SDK/mParticle.m b/mParticle-Apple-SDK/mParticle.m index 34aeabe53..3d967bd84 100644 --- a/mParticle-Apple-SDK/mParticle.m +++ b/mParticle-Apple-SDK/mParticle.m @@ -715,33 +715,62 @@ - (nullable NSSet *)activeTimedEvents { return self.backendController.eventSet; } +- (void)beginTimedEventCompletionHandler:(MPEvent *)event execStatus:(MPExecStatus)execStatus { + if (execStatus == MPExecStatusSuccess) { + MPILogDebug(@"Began timed event: %@", event); + + MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForEvent:event] : event; + if (kitEvent) { + // Forwarding calls to kits + dispatch_async(dispatch_get_main_queue(), ^{ + [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(beginTimedEvent:) + event:kitEvent + parameters:nil + messageType:MPMessageTypeEvent + userInfo:nil + ]; + }); + } else { + MPILogDebug(@"Blocked timed event begin from kits: %@", event); + } + } +} + - (void)beginTimedEvent:(MPEvent *)event { [MPListenerController.sharedInstance onAPICalled:_cmd parameter1:event]; [self.backendController beginTimedEvent:event completionHandler:^(MPEvent *event, MPExecStatus execStatus) { - - if (execStatus == MPExecStatusSuccess) { - MPILogDebug(@"Began timed event: %@", event); - - MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForEvent:event] : event; - if (kitEvent) { - // Forwarding calls to kits - dispatch_async(dispatch_get_main_queue(), ^{ - [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(beginTimedEvent:) - event:kitEvent - parameters:nil - messageType:MPMessageTypeEvent - userInfo:nil - ]; - }); - } else { - MPILogDebug(@"Blocked timed event begin from kits: %@", event); - } - } + [self beginTimedEventCompletionHandler:event execStatus:execStatus]; }]; } +- (void)logEventCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus { + if (execStatus == MPExecStatusSuccess) { + MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForEvent:event] : event; + if (kitEvent) { + dispatch_async(dispatch_get_main_queue(), ^{ + // Forwarding calls to kits + [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(endTimedEvent:) + event:kitEvent + parameters:nil + messageType:MPMessageTypeEvent + userInfo:nil + ]; + + [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(logEvent:) + event:kitEvent + parameters:nil + messageType:MPMessageTypeEvent + userInfo:nil + ]; + }); + } else { + MPILogDebug(@"Blocked timed event end from kits: %@", event); + } + } +} + - (void)endTimedEvent:(MPEvent *)event { [event endTiming]; dispatch_async([MParticle messageQueue], ^{ @@ -749,29 +778,7 @@ - (void)endTimedEvent:(MPEvent *)event { [self.backendController logEvent:event completionHandler:^(MPEvent *event, MPExecStatus execStatus) { - if (execStatus == MPExecStatusSuccess) { - MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForEvent:event] : event; - if (kitEvent) { - dispatch_async(dispatch_get_main_queue(), ^{ - // Forwarding calls to kits - [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(endTimedEvent:) - event:kitEvent - parameters:nil - messageType:MPMessageTypeEvent - userInfo:nil - ]; - - [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(logEvent:) - event:kitEvent - parameters:nil - messageType:MPMessageTypeEvent - userInfo:nil - ]; - }); - } else { - MPILogDebug(@"Blocked timed event end from kits: %@", event); - } - } + [self logEventCallback:event execStatus:execStatus]; }]; }); } @@ -799,15 +806,15 @@ - (void)logEvent:(MPBaseEvent *)event { }]; MPBaseEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForBaseEvent:event] : event; if (kitEvent) { - // Forwarding calls to kits - dispatch_async(dispatch_get_main_queue(), ^{ - [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(logBaseEvent:) - event:kitEvent - parameters:nil - messageType:kitEvent.messageType - userInfo:nil - ]; - }); + // Forwarding calls to kits + dispatch_async(dispatch_get_main_queue(), ^{ + [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(logBaseEvent:) + event:kitEvent + parameters:nil + messageType:kitEvent.messageType + userInfo:nil + ]; + }); } else { MPILogDebug(@"Blocked base event from kits: %@", event); } @@ -904,6 +911,26 @@ - (void)logEvent:(NSString *)eventName eventType:(MPEventType)eventType eventInf [self logEvent:event]; } +- (void)logScreenCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus { + if (execStatus == MPExecStatusSuccess) { + MPILogDebug(@"Logged screen event: %@", event); + MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForScreenEvent:event] : event; + if (kitEvent) { + dispatch_async(dispatch_get_main_queue(), ^{ + // Forwarding calls to kits + [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(logScreen:) + event:kitEvent + parameters:nil + messageType:MPMessageTypeScreenView + userInfo:nil + ]; + }); + } else { + MPILogDebug(@"Blocked screen event from kits: %@", event); + } + } +} + - (void)logScreenEvent:(MPEvent *)event { if (event == nil) { MPILogError(@"Cannot log nil screen event!"); @@ -917,23 +944,7 @@ - (void)logScreenEvent:(MPEvent *)event { [self.backendController logScreen:event completionHandler:^(MPEvent *event, MPExecStatus execStatus) { - if (execStatus == MPExecStatusSuccess) { - MPILogDebug(@"Logged screen event: %@", event); - MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForScreenEvent:event] : event; - if (kitEvent) { - dispatch_async(dispatch_get_main_queue(), ^{ - // Forwarding calls to kits - [[MParticle sharedInstance].kitContainer_PRIVATE forwardSDKCall:@selector(logScreen:) - event:kitEvent - parameters:nil - messageType:MPMessageTypeScreenView - userInfo:nil - ]; - }); - } else { - MPILogDebug(@"Blocked screen event from kits: %@", event); - } - } + [self logScreenCallback:event execStatus:execStatus]; }]; }); }