diff --git a/Amplitude-Swift.xcodeproj/project.pbxproj b/Amplitude-Swift.xcodeproj/project.pbxproj index 1deb68ff..455f23ac 100644 --- a/Amplitude-Swift.xcodeproj/project.pbxproj +++ b/Amplitude-Swift.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXAggregateTarget section */ diff --git a/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample.xcodeproj/project.pbxproj b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample.xcodeproj/project.pbxproj index 216f6b12..5b4bcf4c 100644 --- a/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample.xcodeproj/project.pbxproj +++ b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 19C9CC222937F5A600C1E660 /* AmplitudeSwiftUIExample.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 19C9CC202937F5A600C1E660 /* AmplitudeSwiftUIExample.xcdatamodeld */; }; 19C9CC2D2937F5D000C1E660 /* AmplitudeSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 19C9CC2C2937F5D000C1E660 /* AmplitudeSwift */; }; 3A3036482A4B45780004CF0B /* TroubleShootingPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A3036472A4B45780004CF0B /* TroubleShootingPlugin.swift */; }; + 3A42EB922B87CDE30044FD45 /* FilterPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A42EB912B87CDE30044FD45 /* FilterPlugin.swift */; }; 3A4E19BD2941D885002EA8BC /* IDFACollectionPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A4E19BC2941D86E002EA8BC /* IDFACollectionPlugin.swift */; }; 58324F75294BF7CF00C71E2E /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 58324F74294BF7CF00C71E2E /* WidgetKit.framework */; }; 58324F77294BF7CF00C71E2E /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 58324F76294BF7CF00C71E2E /* SwiftUI.framework */; }; @@ -88,6 +89,7 @@ 19C9CC292937F5B200C1E660 /* AmplitudeSwift */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = AmplitudeSwift; path = ../..; sourceTree = ""; }; 19C9CC2A2937F5C900C1E660 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 3A3036472A4B45780004CF0B /* TroubleShootingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TroubleShootingPlugin.swift; sourceTree = ""; }; + 3A42EB912B87CDE30044FD45 /* FilterPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterPlugin.swift; sourceTree = ""; }; 3A4E19BC2941D86E002EA8BC /* IDFACollectionPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IDFACollectionPlugin.swift; sourceTree = ""; }; 58324F73294BF7CF00C71E2E /* iOSWidgetExampleExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = iOSWidgetExampleExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 58324F74294BF7CF00C71E2E /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; }; @@ -206,6 +208,7 @@ BA541E9A2A8B587E0088D841 /* LocationPlugin.swift */, 3A4E19BC2941D86E002EA8BC /* IDFACollectionPlugin.swift */, 3A3036472A4B45780004CF0B /* TroubleShootingPlugin.swift */, + 3A42EB912B87CDE30044FD45 /* FilterPlugin.swift */, ); path = ExamplePlugins; sourceTree = ""; @@ -394,6 +397,7 @@ 3A4E19BD2941D885002EA8BC /* IDFACollectionPlugin.swift in Sources */, 58324F84294BF7CF00C71E2E /* iOSWidgetExample.intentdefinition in Sources */, 3A3036482A4B45780004CF0B /* TroubleShootingPlugin.swift in Sources */, + 3A42EB922B87CDE30044FD45 /* FilterPlugin.swift in Sources */, BA541E9B2A8B587E0088D841 /* LocationPlugin.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/AmplitudeSwiftUIExampleApp.swift b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/AmplitudeSwiftUIExampleApp.swift index 9e8f6202..97dc3a44 100644 --- a/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/AmplitudeSwiftUIExampleApp.swift +++ b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/AmplitudeSwiftUIExampleApp.swift @@ -20,6 +20,7 @@ struct AmplitudeSwiftUIExampleApp: App { Amplitude.testInstance.add(plugin: LocationPlugin()) // add the trouble shooting plugin for debugging Amplitude.testInstance.add(plugin: TroubleShootingPlugin()) + Amplitude.testInstance.add(plugin: FilterPlugin()) Amplitude.experimentClient.fetch(user: nil, completion: nil) } diff --git a/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/ContentView.swift b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/ContentView.swift index 1382b0be..c0084ba7 100644 --- a/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/ContentView.swift +++ b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/ContentView.swift @@ -88,6 +88,17 @@ struct ContentView: View { Text("Send Revenue Event") }.buttonStyle(AmplitudeButton()) } + Section(header: Text("FILTERED EVENT")) { + HStack { + Button(action: { + print("Send event") + Amplitude.testInstance.track(eventType: "Filtered Event") + }) { + Text("Event Should Be Filtered") + }.buttonStyle(AmplitudeButton()) + + } + } Section(header: Text("IDENTIFY")) { HStack { TextField("User Property Key", text: $userPropertyKey) diff --git a/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/ExamplePlugins/FilterPlugin.swift b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/ExamplePlugins/FilterPlugin.swift new file mode 100644 index 00000000..c9276884 --- /dev/null +++ b/Examples/AmplitudeSwiftUIExample/AmplitudeSwiftUIExample/ExamplePlugins/FilterPlugin.swift @@ -0,0 +1,18 @@ +// +// FilterPlugin.swift +// AmplitudeSwiftUIExample +// +// Created by Alyssa.Yu on 2/22/24. +// + +import Foundation +import AmplitudeSwift + +class FilterPlugin: EnrichmentPlugin { + public override func execute(event: BaseEvent) -> BaseEvent? { + guard event.eventType != "Filtered Event" else { + return nil + } + return event + } +} diff --git a/Sources/Amplitude/Mediator.swift b/Sources/Amplitude/Mediator.swift index 130c50a0..7dbfaae3 100644 --- a/Sources/Amplitude/Mediator.swift +++ b/Sources/Amplitude/Mediator.swift @@ -23,7 +23,7 @@ internal class Mediator { } } - internal func execute(event: BaseEvent) -> BaseEvent? { + internal func execute(event: BaseEvent?) -> BaseEvent? { var result: BaseEvent? = event plugins.forEach { plugin in if let r = result { diff --git a/Sources/Amplitude/Timeline.swift b/Sources/Amplitude/Timeline.swift index f656f341..49c91126 100644 --- a/Sources/Amplitude/Timeline.swift +++ b/Sources/Amplitude/Timeline.swift @@ -28,7 +28,7 @@ public class Timeline { internal func applyPlugin(pluginType: PluginType, event: BaseEvent?) -> BaseEvent? { var result: BaseEvent? = event if let mediator = plugins[pluginType] { - result = mediator.execute(event: event!) + result = mediator.execute(event: event) } return result }