Skip to content

Commit

Permalink
feat: add start/stop session recording and refactor session manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj committed Dec 19, 2024
1 parent 9fc8a1e commit ac651e4
Show file tree
Hide file tree
Showing 24 changed files with 969 additions and 167 deletions.
16 changes: 16 additions & 0 deletions PostHog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
69F518382BB2BA0100F52C14 /* PostHogSwizzler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F518372BB2BA0100F52C14 /* PostHogSwizzler.swift */; };
69F5183A2BB2BA8300F52C14 /* UIApplicationTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F518392BB2BA8300F52C14 /* UIApplicationTracker.swift */; };
DA0CA6F12CFF6B6300AF9500 /* UIWindow+.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0CA6F02CFF6B6300AF9500 /* UIWindow+.swift */; };
DA1D295E2D10B7B2003A31DA /* ApplicationLifecyclePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA1D29582D10B7A6003A31DA /* ApplicationLifecyclePublisher.swift */; };
DA1D29602D10C810003A31DA /* PostHogSessionManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA1D295F2D10C80D003A31DA /* PostHogSessionManagerTest.swift */; };
DA1D29622D115E17003A31DA /* DI.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA1D29612D115E13003A31DA /* DI.swift */; };
DA26419C2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA26419A2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift */; };
DA4932FD2D0102950092C213 /* AssociatedKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4932FC2D0102910092C213 /* AssociatedKeys.swift */; };
DA5AA7192CE245D2004EFB99 /* UIApplication+.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5AA7132CE245CD004EFB99 /* UIApplication+.swift */; };
Expand All @@ -132,6 +135,7 @@
DAD5DD0C2CB6DEF30087387B /* PostHogMaskViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD5DD072CB6DEE70087387B /* PostHogMaskViewModifier.swift */; };
DAD76A212D006AEE003E1A43 /* UIView+PostHogLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD76A1B2D006AE8003E1A43 /* UIView+PostHogLabel.swift */; };
DAD76A242D006C15003E1A43 /* View+PostHogLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD76A232D006C0B003E1A43 /* View+PostHogLabel.swift */; };
DAF79A2A2D1309C00078A3C9 /* TestError.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF79A242D1309BE0078A3C9 /* TestError.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -397,6 +401,9 @@
69F518372BB2BA0100F52C14 /* PostHogSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogSwizzler.swift; sourceTree = "<group>"; };
69F518392BB2BA8300F52C14 /* UIApplicationTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplicationTracker.swift; sourceTree = "<group>"; };
DA0CA6F02CFF6B6300AF9500 /* UIWindow+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+.swift"; sourceTree = "<group>"; };
DA1D29582D10B7A6003A31DA /* ApplicationLifecyclePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationLifecyclePublisher.swift; sourceTree = "<group>"; };
DA1D295F2D10C80D003A31DA /* PostHogSessionManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogSessionManagerTest.swift; sourceTree = "<group>"; };
DA1D29612D115E13003A31DA /* DI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DI.swift; sourceTree = "<group>"; };
DA26419A2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogAutocaptureEventTracker.swift; sourceTree = "<group>"; };
DA4932FC2D0102910092C213 /* AssociatedKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssociatedKeys.swift; sourceTree = "<group>"; };
DA5AA7132CE245CD004EFB99 /* UIApplication+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+.swift"; sourceTree = "<group>"; };
Expand All @@ -409,6 +416,7 @@
DAD5DD072CB6DEE70087387B /* PostHogMaskViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogMaskViewModifier.swift; sourceTree = "<group>"; };
DAD76A1B2D006AE8003E1A43 /* UIView+PostHogLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+PostHogLabel.swift"; sourceTree = "<group>"; };
DAD76A232D006C0B003E1A43 /* View+PostHogLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+PostHogLabel.swift"; sourceTree = "<group>"; };
DAF79A242D1309BE0078A3C9 /* TestError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestError.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -485,6 +493,7 @@
3A62646829C9E37A007E8C07 /* TestUtils */ = {
isa = PBXGroup;
children = (
DAF79A242D1309BE0078A3C9 /* TestError.swift */,
3A62646929C9E385007E8C07 /* MockPostHogServer.swift */,
3A62647429CB0168007E8C07 /* TestPostHog.swift */,
3A580B4229E489D000C5C6F3 /* URLSession+body.swift */,
Expand Down Expand Up @@ -518,6 +527,7 @@
3AA4C09B2988315D006C4731 /* Utils */ = {
isa = PBXGroup;
children = (
DA1D29582D10B7A6003A31DA /* ApplicationLifecyclePublisher.swift */,
DA0CA6F02CFF6B6300AF9500 /* UIWindow+.swift */,
DA5AA7132CE245CD004EFB99 /* UIApplication+.swift */,
3AE3FB422992985A00AFFC18 /* Reachability.swift */,
Expand Down Expand Up @@ -572,6 +582,7 @@
3AC745B7296D6FE60025C109 /* PostHog */ = {
isa = PBXGroup;
children = (
DA1D29612D115E13003A31DA /* DI.swift */,
DA26419B2CC0499300CB427B /* Autocapture */,
69EE82B82BA9C4DA00EB9542 /* Replay */,
69BA38E62B893F2200AA69D6 /* Resources */,
Expand Down Expand Up @@ -606,6 +617,7 @@
3AC745C3296D6FE60025C109 /* PostHogTests */ = {
isa = PBXGroup;
children = (
DA1D295F2D10C80D003A31DA /* PostHogSessionManagerTest.swift */,
3A62646829C9E37A007E8C07 /* TestUtils */,
3AE3FB4A2993A68500AFFC18 /* PostHogStorageTest.swift */,
3A62647029CAF67B007E8C07 /* PostHogStorageManagerTest.swift */,
Expand Down Expand Up @@ -1168,6 +1180,7 @@
69F23A762BB308AE001194F6 /* URLSessionInterceptor.swift in Sources */,
690FF0BF2AEFA97F00A0B06B /* FileUtils.swift in Sources */,
69261D252AD9787A00232EC7 /* PostHogExtensions.swift in Sources */,
DA1D295E2D10B7B2003A31DA /* ApplicationLifecyclePublisher.swift in Sources */,
3AE3FB4E2993D1D600AFFC18 /* PostHogStorageManager.swift in Sources */,
3AE3FB49299391DF00AFFC18 /* PostHogStorage.swift in Sources */,
DAD76A212D006AEE003E1A43 /* UIView+PostHogLabel.swift in Sources */,
Expand Down Expand Up @@ -1208,6 +1221,7 @@
69EE82BC2BA9C53000EB9542 /* PostHogSessionReplayConfig.swift in Sources */,
DA5AA7192CE245D2004EFB99 /* UIApplication+.swift in Sources */,
69EE82CE2BAAC76000EB9542 /* ViewTreeSnapshotStatus.swift in Sources */,
DA1D29622D115E17003A31DA /* DI.swift in Sources */,
69ED1AD42C90A0F100FE7A91 /* URLSessionExtension.swift in Sources */,
69ED1A9F2C8F451B00FE7A91 /* PostHogPersonProfiles.swift in Sources */,
69EE82BA2BA9C50400EB9542 /* PostHogReplayIntegration.swift in Sources */,
Expand Down Expand Up @@ -1236,13 +1250,15 @@
3A62646A29C9E385007E8C07 /* MockPostHogServer.swift in Sources */,
690FF0BB2AEF8B8200A0B06B /* PostHogContextTest.swift in Sources */,
690FF0E32AEFD12900A0B06B /* PostHogConfigTest.swift in Sources */,
DAF79A2A2D1309C00078A3C9 /* TestError.swift in Sources */,
3A62647129CAF67B007E8C07 /* PostHogStorageManagerTest.swift in Sources */,
693E977D2C6257F9004B1030 /* ExampleSanitizer.swift in Sources */,
690FF0DF2AEFBC5700A0B06B /* PostHogLegacyQueueTest.swift in Sources */,
690FF0BD2AEF93F400A0B06B /* PostHogFeatureFlagsTest.swift in Sources */,
690FF0E92AEFD3BD00A0B06B /* PostHogQueueTest.swift in Sources */,
3AE3FB4B2993A68500AFFC18 /* PostHogStorageTest.swift in Sources */,
3A580B4329E489D000C5C6F3 /* URLSession+body.swift in Sources */,
DA1D29602D10C810003A31DA /* PostHogSessionManagerTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion PostHog/Autocapture/PostHogAutocaptureEventTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
private static func unswizzle() {
guard hasSwizzled else { return }
hasSwizzled = false
swizzleMethods() // swizzling again will excahnge implementations back to original
swizzleMethods() // swizzling again will exchange implementations back to original
unregisterNotifications()
}

Expand Down
16 changes: 16 additions & 0 deletions PostHog/DI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// DI.swift
// PostHog
//
// Created by Yiannis Josephides on 17/12/2024.
//

// swiftlint:disable:next type_name
enum DI {
static var main = Container()

final class Container {
lazy var appLifecyclePublisher: AppLifecyclePublishing = ApplicationLifecyclePublisher.shared
lazy var sessionManager: PostHogSessionManager = .init()
}
}
2 changes: 1 addition & 1 deletion PostHog/PostHogQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
The queue uses File persistence. This allows us to
1. Only send events when we have a network connection
2. Ensure that we can survive app closing or offline situations
3. Not hold too much in mempory
3. Not hold too much in memory

*/

Expand Down
Loading

0 comments on commit ac651e4

Please sign in to comment.