Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/BasicExample/BasicExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ContentView: View {
Text("Track")
}).padding(6)
Button(action: {
Analytics.main.screen(title: "Screen appeared")
Analytics.main.screen(title: "MyScreen")
}, label: {
Text("Screen")
}).padding(6)
Expand Down
38 changes: 2 additions & 36 deletions Sources/SegmentAmplitude/AmplitudeSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle {
public var type = PluginType.enrichment
public weak var analytics: Analytics?

internal struct Constants {
static let ampPrefix = "[Amplitude] "

static let ampSessionEndEvent = "session_end"
static let ampSessionStartEvent = "session_start"
static let ampAppInstalledEvent = "\(ampPrefix)Application Installed"
static let ampAppUpdatedEvent = "\(ampPrefix)Application Updated"
static let ampAppOpenedEvent = "\(ampPrefix)Application Opened"
static let ampAppBackgroundedEvent = "\(ampPrefix)Application Backgrounded"
static let ampDeepLinkOpenedEvent = "\(ampPrefix)Deep Link Opened"
static let ampScreenViewedEvent = "\(ampPrefix)Screen Viewed"
static let ampScreenNameProperty = "\(ampPrefix)Screen Name"
}

public var logging: Bool = false

@Atomic private var active = false
Expand Down Expand Up @@ -112,6 +98,7 @@ 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
// amp needs the `name` in the properties
Expand All @@ -123,6 +110,7 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle {
screenEvent.properties = adjustedProps
workingEvent = screenEvent as? T
}


// handle track
if var trackEvent = workingEvent as? TrackEvent {
Expand All @@ -146,28 +134,6 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle {
trackEvent.integrations = integrations
}

// handle events that need to be re-generated back to amplitude.
// block the originals from going to amplitude as well.
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
}

Expand Down
22 changes: 22 additions & 0 deletions Sources/SegmentAmplitude/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Constants.swift
//
//
// Created by Brandon Sneed on 7/9/24.
//

import Foundation

internal struct Constants {
static let ampPrefix = "[Amplitude] "

static let ampSessionEndEvent = "session_end"
static let ampSessionStartEvent = "session_start"
static let ampAppInstalledEvent = "\(ampPrefix)Application Installed"
static let ampAppUpdatedEvent = "\(ampPrefix)Application Updated"
static let ampAppOpenedEvent = "\(ampPrefix)Application Opened"
static let ampAppBackgroundedEvent = "\(ampPrefix)Application Backgrounded"
static let ampDeepLinkOpenedEvent = "\(ampPrefix)Deep Link Opened"
static let ampScreenViewedEvent = "\(ampPrefix)Screen Viewed"
static let ampScreenNameProperty = "\(ampPrefix)Screen Name"
}
14 changes: 0 additions & 14 deletions Sources/SegmentAmplitude/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ import Segment
// MARK: - Amplitude Session Management

internal class Session {
internal struct Constants {
static let ampPrefix = "[Amplitude] "

static let ampSessionEndEvent = "session_end"
static let ampSessionStartEvent = "session_start"
static let ampAppInstalledEvent = "\(ampPrefix)Application Installed"
static let ampAppUpdatedEvent = "\(ampPrefix)Application Updated"
static let ampAppOpenedEvent = "\(ampPrefix)Application Opened"
static let ampAppBackgroundedEvent = "\(ampPrefix)Application Backgrounded"
static let ampDeepLinkOpenedEvent = "\(ampPrefix)Deep Link Opened"
static let ampScreenViewedEvent = "\(ampPrefix)Screen Viewed"
static let ampRevenueEvent = "revenue_amount"
}

@Atomic var sessionID: Int64 {
didSet {
storage.write(key: Storage.Constants.previousSessionID, value: sessionID)
Expand Down