Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: manual start/stop session recording #276

Merged
merged 23 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8a7a667
chore: add swiftformat config
ioannisj Dec 13, 2024
581a08b
fix: avoid registering for notifications multiple times
ioannisj Dec 13, 2024
5faf328
feat: add session replay automatic start config
ioannisj Dec 13, 2024
9fc8a1e
fix: capture timestamp along with snapshot events
ioannisj Dec 13, 2024
ac651e4
feat: add start/stop session recording and refactor session manager
ioannisj Dec 19, 2024
8c18241
fix(ci): use Xcode 16 for unit testing
ioannisj Dec 23, 2024
7edb51b
fix(ci): switch to macos-14 for tests
ioannisj Dec 23, 2024
ce0bb4a
fix(ci): tests
ioannisj Dec 23, 2024
241282d
fix: remove start mode from session replay config
ioannisj Dec 24, 2024
23236cc
fix: use timestamp at time of checking as the new session timestamp
ioannisj Dec 30, 2024
c06ac99
feat: capture session id on network request start
ioannisj Dec 30, 2024
2d02d50
fix: get session id only after snapshot is generated
ioannisj Dec 30, 2024
25200fe
fix: don't process $snapshot if session id is missing
ioannisj Dec 30, 2024
3225259
fix: remove todo
ioannisj Dec 30, 2024
a40fa50
chore: update CHANGELOG
ioannisj Dec 30, 2024
1dc7fbd
fix(ci): use latest-stable Xcode version
ioannisj Jan 7, 2025
661b545
Merge branch 'main' into feat/start-stop-session-recording
ioannisj Jan 7, 2025
7fbe044
feat: additional checks on react native
ioannisj Jan 8, 2025
a4ac7df
fix: lint
ioannisj Jan 8, 2025
c2f408d
fix: remove didFinishLaunching notification
ioannisj Jan 8, 2025
7fea299
fix: tests
ioannisj Jan 8, 2025
6acd291
Merge branch 'main' into feat/start-stop-session-recording
ioannisj Jan 8, 2025
0783154
chore(ci): build examples on latest macos
ioannisj Jan 8, 2025
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
96 changes: 96 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
--acronyms ID,URL,UUID
--allman false
--anonymousforeach convert
--assetliterals visual-width
--asynccapturing
--beforemarks
--binarygrouping none
--callsiteparen default
--categorymark "MARK: %c"
--classthreshold 0
--closingparen balanced
--closurevoid remove
--commas always
--complexattrs preserve
--computedvarattrs preserve
--condassignment after-property
--conflictmarkers reject
--dateformat system
--decimalgrouping ignore
--doccomments before-declarations
--elseposition same-line
--emptybraces no-space
--enumnamespaces always
--enumthreshold 0
--exponentcase lowercase
--exponentgrouping disabled
--extensionacl on-extension
--extensionlength 0
--extensionmark "MARK: - %t + %c"
--fractiongrouping disabled
--fragment false
--funcattributes preserve
--generictypes
--groupedextension "MARK: %c"
--guardelse auto
--header ignore
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef indent
--importgrouping alpha
--indent 4
--indentcase false
--indentstrings false
--initcodernil false
--lifecycle
--lineaftermarks true
--linebreaks lf
--markcategories true
--markextensions always
--marktypes always
--maxwidth none
--modifierorder
--nevertrailing
--nilinit remove
--noncomplexattrs
--nospaceoperators
--nowrapoperators
--octalgrouping none
--onelineforeach ignore
--operatorfunc spaced
--organizationmode visibility
--organizetypes actor,class,enum,struct
--patternlet hoist
--ranges spaced
--redundanttype infer-locals-only
--self remove
--selfrequired
--semicolons never
--shortoptionals except-properties
--smarttabs enabled
--someany true
--storedvarattrs preserve
--stripunusedargs always
--structthreshold 0
--tabwidth unspecified
--throwcapturing
--timezone system
--trailingclosures
--trimwhitespace always
--typeattributes preserve
--typeblanklines remove
--typedelimiter space-after
--typemark "MARK: - %t"
--voidtype void
--wraparguments preserve
--wrapcollections preserve
--wrapconditions preserve
--wrapeffects preserve
--wrapenumcases always
--wrapparameters default
--wrapreturntype preserve
--wrapternary default
--wraptypealiases preserve
--xcodeindentation disabled
--yodaswap always
--hexgrouping ignore
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 {
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
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
Loading