From b1fa3a06c0dc140a94c0824e0ae629656d01a8be Mon Sep 17 00:00:00 2001 From: Artem Demchenko Date: Sun, 19 Jan 2025 21:27:22 +0800 Subject: [PATCH] Session replay fix: added 'session_id' to 'event_properties' on amplitude --- Sources/SegmentAmplitude/AmplitudeSession.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/SegmentAmplitude/AmplitudeSession.swift b/Sources/SegmentAmplitude/AmplitudeSession.swift index 7fe5a31..5a72d0c 100644 --- a/Sources/SegmentAmplitude/AmplitudeSession.swift +++ b/Sources/SegmentAmplitude/AmplitudeSession.swift @@ -128,6 +128,18 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle { debugLog("EndSession = \(eventSessionID)") } + if active { + // "event_properties" have to contain "session_id" apart from "[Amplitude] Session Replay ID" + // - to make session replays appear in amplitude + var adjustedProps = trackEvent.properties + if adjustedProps == nil { + adjustedProps = try? JSON(["session_id": eventSessionID]) + } else { + adjustedProps?.setValue(eventSessionID, forKeyPath: KeyPath("session_id")) + } + trackEvent.properties = adjustedProps + } + // if it's amp specific stuff, disable all the integrations except for amp. if eventName.contains(Constants.ampPrefix) || eventName == Constants.ampSessionStartEvent || eventName == Constants.ampSessionEndEvent { var integrations = disableAllIntegrations(integrations: trackEvent.integrations)