Skip to content

Commit b7c3b67

Browse files
authored
feat(autocapture): auto capture element interactions (#224)
* feat: add PostHogExampleAutocapture sample project * feat: add base autocapture integration * feat(autocapture): process captured events * feat(autocapture): add support for debouncing events for * feat(autocapture): update CHANGELOG.md * feat(autocapture): add support for UIScrollView * feat(autocapture): add support for UISwitch * feat(autocapture): add support for UIPickerView * feat(autocapture): add autocapture configuration * feat(autocapture): fix UITextField sample * feat(autocapture): fix support for UITextField * fix(autocapture): replace with hedgelog * feat(autocapture): sanitize text similar to js sdk * fix(autocapture): revert view controller name * refactor(autocapture): route events to shared instance * feat(autocapture): skip sensitive inputs and ph-no-capture * fix(autocapture): invalidate and clear debounce timers on stop * feat(tests): add unit tests * chore: format and lint * chore(autocapture): lint file name * ci(test): run iOS tests * ci(tests): run on latest iOS version available * ci(test): revert iOS tests runs are failing on CI both for make test and make test-ios. Will address in another PR * feat(autocapture): simplify configuration options * fix: lint * chore: revert new formats * chore: revert workflow changes
1 parent 0e3845e commit b7c3b67

File tree

143 files changed

+11538
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+11538
-3
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
with:
1616
xcode-version: latest-stable
1717
- name: Test SDK
18-
run: make test
18+
run: make test

.swiftlint.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
excluded: # case-sensitive paths to ignore during linting. Takes precedence over `included`
22
- PostHogExample
33
- PostHogExampleWithSPM
4+
- PostHogExampleAutocapture
45
- PostHogTests
56
- PostHog/Utils/ReadWriteLock.swift
67
- PostHog/Utils/Reachability.swift
@@ -19,6 +20,11 @@ file_length:
1920
warning: 1000
2021
error: 1200
2122

23+
identifier_name:
24+
excluded:
25+
- id
26+
- ^ph_.*$
27+
2228
function_body_length:
2329
- 1000 # warning
2430
- 1200 # error

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Next
22

3+
- add autocapture support for UIKit ([#224](https://github.com/PostHog/posthog-ios/pull/224))
4+
35
## 3.14.2 - 2024-11-08
46

57
- fix issue with resetting accent color in SwiftUI app ([#238](https://github.com/PostHog/posthog-ios/pull/238))

PostHog.xcodeproj/project.pbxproj

+60
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@
119119
69F5181A2BAC81FC00F52C14 /* UITextInputTraits+Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F518192BAC81FC00F52C14 /* UITextInputTraits+Util.swift */; };
120120
69F518382BB2BA0100F52C14 /* PostHogSwizzler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F518372BB2BA0100F52C14 /* PostHogSwizzler.swift */; };
121121
69F5183A2BB2BA8300F52C14 /* UIApplicationTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F518392BB2BA8300F52C14 /* UIApplicationTracker.swift */; };
122+
DA26419C2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA26419A2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift */; };
123+
DA5B85882CD21CBB00686389 /* AutocaptureEventProcessing.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5B85872CD21CBB00686389 /* AutocaptureEventProcessing.swift */; };
124+
DA979D7B2CD370B700F56BAE /* PostHogAutocaptureEventTrackerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA979D7A2CD370B700F56BAE /* PostHogAutocaptureEventTrackerSpec.swift */; };
125+
DAC699D62CC790D9000D1D6B /* PostHogAutocaptureIntegration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC699D52CC790D9000D1D6B /* PostHogAutocaptureIntegration.swift */; };
126+
DAC699EC2CCA73E5000D1D6B /* ForwardingPickerViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC699EB2CCA73E5000D1D6B /* ForwardingPickerViewDelegate.swift */; };
127+
DACF6D5D2CD2F5BC00F14133 /* PostHogAutocaptureIntegrationSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DACF6D5C2CD2F5BC00F14133 /* PostHogAutocaptureIntegrationSpec.swift */; };
122128
DAD5DD0C2CB6DEF30087387B /* PostHogMaskViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD5DD072CB6DEE70087387B /* PostHogMaskViewModifier.swift */; };
123129
/* End PBXBuildFile section */
124130

@@ -200,6 +206,13 @@
200206
remoteGlobalIDString = 3AC745B4296D6FE60025C109;
201207
remoteInfo = PostHog;
202208
};
209+
DA8D37282CBEAC03005EBD27 /* PBXContainerItemProxy */ = {
210+
isa = PBXContainerItemProxy;
211+
containerPortal = DA8D37242CBEAC02005EBD27 /* PostHogExampleAutocapture.xcodeproj */;
212+
proxyType = 2;
213+
remoteGlobalIDString = 228DB9F318BC53F1002BA12A;
214+
remoteInfo = PostHogExampleAutocapture;
215+
};
203216
/* End PBXContainerItemProxy section */
204217

205218
/* Begin PBXCopyFilesBuildPhase section */
@@ -376,6 +389,13 @@
376389
69F518192BAC81FC00F52C14 /* UITextInputTraits+Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextInputTraits+Util.swift"; sourceTree = "<group>"; };
377390
69F518372BB2BA0100F52C14 /* PostHogSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogSwizzler.swift; sourceTree = "<group>"; };
378391
69F518392BB2BA8300F52C14 /* UIApplicationTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplicationTracker.swift; sourceTree = "<group>"; };
392+
DA26419A2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogAutocaptureEventTracker.swift; sourceTree = "<group>"; };
393+
DA5B85872CD21CBB00686389 /* AutocaptureEventProcessing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutocaptureEventProcessing.swift; sourceTree = "<group>"; };
394+
DA8D37242CBEAC02005EBD27 /* PostHogExampleAutocapture.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PostHogExampleAutocapture.xcodeproj; path = PostHogExampleAutocapture/PostHogExampleAutocapture.xcodeproj; sourceTree = "<group>"; };
395+
DA979D7A2CD370B700F56BAE /* PostHogAutocaptureEventTrackerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostHogAutocaptureEventTrackerSpec.swift; sourceTree = "<group>"; };
396+
DAC699D52CC790D9000D1D6B /* PostHogAutocaptureIntegration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogAutocaptureIntegration.swift; sourceTree = "<group>"; };
397+
DAC699EB2CCA73E5000D1D6B /* ForwardingPickerViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForwardingPickerViewDelegate.swift; sourceTree = "<group>"; };
398+
DACF6D5C2CD2F5BC00F14133 /* PostHogAutocaptureIntegrationSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogAutocaptureIntegrationSpec.swift; sourceTree = "<group>"; };
379399
DAD5DD072CB6DEE70087387B /* PostHogMaskViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogMaskViewModifier.swift; sourceTree = "<group>"; };
380400
/* End PBXFileReference section */
381401

@@ -503,6 +523,7 @@
503523
3AC745AB296D6FE60025C109 = {
504524
isa = PBXGroup;
505525
children = (
526+
DA8D37242CBEAC02005EBD27 /* PostHogExampleAutocapture.xcodeproj */,
506527
690FF1732AF3CE8A00A0B06B /* PostHogExampleWatchOS.xcodeproj */,
507528
690FF0532AE7DB3700A0B06B /* PostHogExampleWithSPM.xcodeproj */,
508529
690FF02F2AE7C5BA00A0B06B /* PostHogExampleWithPods.xcodeproj */,
@@ -536,6 +557,7 @@
536557
3AC745B7296D6FE60025C109 /* PostHog */ = {
537558
isa = PBXGroup;
538559
children = (
560+
DA26419B2CC0499300CB427B /* Autocapture */,
539561
69EE82B82BA9C4DA00EB9542 /* Replay */,
540562
69BA38E62B893F2200AA69D6 /* Resources */,
541563
69779BED2AE6B29E00D7A48E /* Models */,
@@ -579,6 +601,8 @@
579601
690FF0E22AEFD12900A0B06B /* PostHogConfigTest.swift */,
580602
690FF0E82AEFD3BD00A0B06B /* PostHogQueueTest.swift */,
581603
690FF0F42AF0F06100A0B06B /* PostHogSDKTest.swift */,
604+
DACF6D5C2CD2F5BC00F14133 /* PostHogAutocaptureIntegrationSpec.swift */,
605+
DA979D7A2CD370B700F56BAE /* PostHogAutocaptureEventTrackerSpec.swift */,
582606
699C5FEE2C20242A007DB818 /* UUIDTest.swift */,
583607
693E977C2C6257F9004B1030 /* ExampleSanitizer.swift */,
584608
69ED1AB52C90711D00FE7A91 /* PostHogSDKPersonProfilesTest.swift */,
@@ -733,6 +757,25 @@
733757
path = PostHogExampleStoryboard;
734758
sourceTree = "<group>";
735759
};
760+
DA26419B2CC0499300CB427B /* Autocapture */ = {
761+
isa = PBXGroup;
762+
children = (
763+
DA5B85872CD21CBB00686389 /* AutocaptureEventProcessing.swift */,
764+
DAC699EB2CCA73E5000D1D6B /* ForwardingPickerViewDelegate.swift */,
765+
DAC699D52CC790D9000D1D6B /* PostHogAutocaptureIntegration.swift */,
766+
DA26419A2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift */,
767+
);
768+
path = Autocapture;
769+
sourceTree = "<group>";
770+
};
771+
DA8D37252CBEAC02005EBD27 /* Products */ = {
772+
isa = PBXGroup;
773+
children = (
774+
DA8D37292CBEAC03005EBD27 /* PostHogExampleAutocapture.app */,
775+
);
776+
name = Products;
777+
sourceTree = "<group>";
778+
};
736779
/* End PBXGroup section */
737780

738781
/* Begin PBXHeadersBuildPhase section */
@@ -939,6 +982,10 @@
939982
productRefGroup = 3AC745B6296D6FE60025C109 /* Products */;
940983
projectDirPath = "";
941984
projectReferences = (
985+
{
986+
ProductGroup = DA8D37252CBEAC02005EBD27 /* Products */;
987+
ProjectRef = DA8D37242CBEAC02005EBD27 /* PostHogExampleAutocapture.xcodeproj */;
988+
},
942989
{
943990
ProductGroup = 690FF1742AF3CE8A00A0B06B /* Products */;
944991
ProjectRef = 690FF1732AF3CE8A00A0B06B /* PostHogExampleWatchOS.xcodeproj */;
@@ -994,6 +1041,13 @@
9941041
remoteRef = 690FF17A2AF3CE8B00A0B06B /* PBXContainerItemProxy */;
9951042
sourceTree = BUILT_PRODUCTS_DIR;
9961043
};
1044+
DA8D37292CBEAC03005EBD27 /* PostHogExampleAutocapture.app */ = {
1045+
isa = PBXReferenceProxy;
1046+
fileType = wrapper.application;
1047+
path = PostHogExampleAutocapture.app;
1048+
remoteRef = DA8D37282CBEAC03005EBD27 /* PBXContainerItemProxy */;
1049+
sourceTree = BUILT_PRODUCTS_DIR;
1050+
};
9971051
/* End PBXReferenceProxy section */
9981052

9991053
/* Begin PBXResourcesBuildPhase section */
@@ -1093,10 +1147,14 @@
10931147
69779BEC2AE68E6900D7A48E /* UIViewController.swift in Sources */,
10941148
3A0F108929C9BD76002C0084 /* Errors.swift in Sources */,
10951149
3AE3FB37299162EA00AFFC18 /* PostHogApi.swift in Sources */,
1150+
DAC699D62CC790D9000D1D6B /* PostHogAutocaptureIntegration.swift in Sources */,
10961151
6926DA8E2ADD2876005760D2 /* PostHogContext.swift in Sources */,
10971152
690FF0AF2AEB9C1400A0B06B /* DateUtils.swift in Sources */,
10981153
69F518162BAC7F9200F52C14 /* UIView+Util.swift in Sources */,
10991154
69261D192AD9673500232EC7 /* PostHogBatchUploadInfo.swift in Sources */,
1155+
DAC699EC2CCA73E5000D1D6B /* ForwardingPickerViewDelegate.swift in Sources */,
1156+
DA26419C2CC0499300CB427B /* PostHogAutocaptureEventTracker.swift in Sources */,
1157+
DA5B85882CD21CBB00686389 /* AutocaptureEventProcessing.swift in Sources */,
11001158
69ED1A5C2C7F15F300FE7A91 /* PostHogSessionManager.swift in Sources */,
11011159
69F23A742BB3088E001194F6 /* URLSessionSwizzler.swift in Sources */,
11021160
69F518142BAC7F4300F52C14 /* Date+Util.swift in Sources */,
@@ -1136,8 +1194,10 @@
11361194
isa = PBXSourcesBuildPhase;
11371195
buildActionMask = 2147483647;
11381196
files = (
1197+
DA979D7B2CD370B700F56BAE /* PostHogAutocaptureEventTrackerSpec.swift in Sources */,
11391198
690FF0F52AF0F06100A0B06B /* PostHogSDKTest.swift in Sources */,
11401199
690FF0E12AEFC59100A0B06B /* PostHogFileBackedQueueTest.swift in Sources */,
1200+
DACF6D5D2CD2F5BC00F14133 /* PostHogAutocaptureIntegrationSpec.swift in Sources */,
11411201
3A62647529CB0168007E8C07 /* TestPostHog.swift in Sources */,
11421202
699C5FEF2C20242A007DB818 /* UUIDTest.swift in Sources */,
11431203
69ED1AB62C90711D00FE7A91 /* PostHogSDKPersonProfilesTest.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// AutocaptureEventProcessing.swift
3+
// PostHog
4+
//
5+
// Created by Yiannis Josephides on 30/10/2024.
6+
//
7+
8+
#if os(iOS) || targetEnvironment(macCatalyst)
9+
import Foundation
10+
11+
protocol AutocaptureEventProcessing: AnyObject {
12+
func process(source: PostHogAutocaptureEventTracker.EventSource, event: PostHogAutocaptureEventTracker.EventData)
13+
}
14+
#endif

0 commit comments

Comments
 (0)