From 83824cfe4a828e30275b153882ef3ac2b0ae65ce Mon Sep 17 00:00:00 2001 From: Michael Grosse Huelsewiesche Date: Wed, 10 Jul 2024 18:16:27 -0400 Subject: [PATCH] Removing configurations and conditional code --- .../BasicExample/BasicExampleApp.swift | 7 +- .../SegmentAmplitude/AmplitudeSession.swift | 70 +------------------ 2 files changed, 2 insertions(+), 75 deletions(-) diff --git a/Example/BasicExample/BasicExample/BasicExampleApp.swift b/Example/BasicExample/BasicExample/BasicExampleApp.swift index 6212939..5616211 100644 --- a/Example/BasicExample/BasicExample/BasicExampleApp.swift +++ b/Example/BasicExample/BasicExample/BasicExampleApp.swift @@ -26,12 +26,7 @@ extension Analytics { instance = Analytics(configuration: Configuration(writeKey: "") .flushAt(3) .trackApplicationLifecycleEvents(true)) - instance?.add(plugin: AmplitudeSession( - enableSessionEvents: true, - enableLifecycleEvents: true, - enableScreenEvents: true, - enableDeepLinkEvents: true - )) + instance?.add(plugin: AmplitudeSession()) } return instance! diff --git a/Sources/SegmentAmplitude/AmplitudeSession.swift b/Sources/SegmentAmplitude/AmplitudeSession.swift index 2b80feb..6847027 100644 --- a/Sources/SegmentAmplitude/AmplitudeSession.swift +++ b/Sources/SegmentAmplitude/AmplitudeSession.swift @@ -42,11 +42,6 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle { public var logging: Bool = false - private let enableSessionEvents: Bool - private let enableLifecycleEvents: Bool - private let enableScreenEvents: Bool - private let enableDeepLinkEvents: Bool - @Atomic private var active = false @Atomic private var inForeground: Bool = false @Atomic private var resetPending: Bool = false @@ -66,20 +61,9 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle { } } - public init( - enableSessionEvents: Bool = true, - enableLifecycleEvents: Bool = false, - enableScreenEvents: Bool = false, - enableDeepLinkEvents: Bool = false - ) { + public init() { self.sessionID = storage.read(key: Storage.Constants.previousSessionID) ?? -1 self.lastEventTime = storage.read(key: Storage.Constants.lastEventTime) ?? -1 - - self.enableSessionEvents = enableSessionEvents - self.enableScreenEvents = enableScreenEvents - self.enableLifecycleEvents = enableLifecycleEvents - self.enableDeepLinkEvents = enableDeepLinkEvents - debugLog("startup sessionID = \(sessionID)") } @@ -114,7 +98,6 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle { startNewSessionIfNecessary() // handle screen - // this code works off the destination action logic. if var screenEvent = workingEvent as? ScreenEvent, let screenName = screenEvent.name { var adjustedProps = screenEvent.properties @@ -125,19 +108,6 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle { adjustedProps?.setValue(screenName, forKeyPath: KeyPath("name")) } screenEvent.properties = adjustedProps - - // if we're sending Amplitude's definition of a screen event ... - if enableScreenEvents { - // set the keyname amplitude wants - adjustedProps?.setValue(screenName, forKeyPath: KeyPath(Constants.ampScreenNameProperty)) - // remove the unnecessary `name` property. - adjustedProps = try? adjustedProps?.remove(key: "name") - // send a new track call for amplitude to pick up the screen. - analytics?.track(name: Constants.ampScreenViewedEvent, properties: adjustedProps) - // keep our current screen event from going to amplitude. - screenEvent.integrations?.setValue(false, forKeyPath: KeyPath(key)) - } - workingEvent = screenEvent as? T } @@ -151,18 +121,10 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle { resetPending = false eventSessionID = sessionID debugLog("NewSession = \(eventSessionID)") - if !enableSessionEvents { - // don't send these events, so return nil to drop it. - return nil - } } if eventName == Constants.ampSessionEndEvent { debugLog("EndSession = \(eventSessionID)") - if !enableSessionEvents { - // don't send these events, so return nil to drop it. - return nil - } } // if it's amp specific stuff, disable all the integrations except for amp. @@ -172,36 +134,6 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle { trackEvent.integrations = integrations } - if enableDeepLinkEvents { - if eventName == "Deep Link Opened" { - analytics?.track(name: Constants.ampDeepLinkOpenedEvent, properties: trackEvent.properties) - } - } - - // handle events that need to be re-generated back to amplitude. - // block the originals from going to amplitude as well. - if enableLifecycleEvents { - switch trackEvent.event { - case "Application Opened": - analytics?.track(name: Constants.ampAppOpenedEvent, properties: trackEvent.properties) - trackEvent.integrations?.setValue(false, forKeyPath: KeyPath(key)) - case "Application Installed": - analytics?.track(name: Constants.ampAppInstalledEvent, properties: trackEvent.properties) - trackEvent.integrations?.setValue(false, forKeyPath: KeyPath(key)) - case "Application Updated": - analytics?.track(name: Constants.ampAppUpdatedEvent, properties: trackEvent.properties) - trackEvent.integrations?.setValue(false, forKeyPath: KeyPath(key)) - case "Application Backgrounded": - analytics?.track(name: Constants.ampAppBackgroundedEvent, properties: trackEvent.properties) - trackEvent.integrations?.setValue(false, forKeyPath: KeyPath(key)) - case "Application Foregrounded": - // amplitude doesn't need this one, it's redundant. - trackEvent.integrations?.setValue(false, forKeyPath: KeyPath(key)) - default: - break - } - } - workingEvent = trackEvent as? T }