Skip to content

Commit

Permalink
Merge branch 'main' into feat/autocapture-custom-label
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj authored Dec 9, 2024
2 parents dd495ef + 8a9d07f commit fbf8624
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- feat: ability to add a custom label to autocapture elements ([#271](https://github.com/PostHog/posthog-ios/pull/271))

## 3.16.2 - 2024-12-05

- fix: ignore autocapture events from keyboard window ([#269](https://github.com/PostHog/posthog-ios/pull/269))

## 3.16.1 - 2024-12-04

- fix: screen flicker when capturing a screenshot when a sensitive text field is on screen ([#270](https://github.com/PostHog/posthog-ios/pull/270))
Expand Down
2 changes: 1 addition & 1 deletion PostHog.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "PostHog"
s.version = "3.16.1"
s.version = "3.16.2"
s.summary = "The hassle-free way to add posthog to your iOS app."

s.description = <<-DESC
Expand Down
4 changes: 4 additions & 0 deletions PostHog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
69F5181A2BAC81FC00F52C14 /* UITextInputTraits+Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F518192BAC81FC00F52C14 /* UITextInputTraits+Util.swift */; };
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 */; };
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 Down Expand Up @@ -395,6 +396,7 @@
69F518192BAC81FC00F52C14 /* UITextInputTraits+Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextInputTraits+Util.swift"; sourceTree = "<group>"; };
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>"; };
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 Down Expand Up @@ -516,6 +518,7 @@
3AA4C09B2988315D006C4731 /* Utils */ = {
isa = PBXGroup;
children = (
DA0CA6F02CFF6B6300AF9500 /* UIWindow+.swift */,
DA5AA7132CE245CD004EFB99 /* UIApplication+.swift */,
3AE3FB422992985A00AFFC18 /* Reachability.swift */,
3AE3FB462992AB0000AFFC18 /* Hedgelog.swift */,
Expand Down Expand Up @@ -1160,6 +1163,7 @@
69261D1F2AD9681300232EC7 /* PostHogConsumerPayload.swift in Sources */,
6955CB732C517651008EFD8D /* CGSize+Util.swift in Sources */,
69F517EA2BAC684F00F52C14 /* RRStyle.swift in Sources */,
DA0CA6F12CFF6B6300AF9500 /* UIWindow+.swift in Sources */,
69F23A782BB30991001194F6 /* NetworkSample.swift in Sources */,
69F23A762BB308AE001194F6 /* URLSessionInterceptor.swift in Sources */,
690FF0BF2AEFA97F00A0B06B /* FileUtils.swift in Sources */,
Expand Down
19 changes: 17 additions & 2 deletions PostHog/Autocapture/PostHogAutocaptureEventTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,23 @@
}

extension UIScrollView {
@objc func ph_swizzled_setContentOffset_Setter(_ contentOffset: CGPoint) {
@objc func ph_swizzled_setContentOffset_Setter(_ newContentOffset: CGPoint) {
// first, call original method
ph_swizzled_setContentOffset_Setter(contentOffset)
ph_swizzled_setContentOffset_Setter(newContentOffset)

guard shouldTrack(self) else {
return
}

// ignore all keyboard events
if let window, window.isKeyboardWindow {
return
}

// scrollview did not scroll (contentOffset didn't change)
guard contentOffset != newContentOffset else {
return
}

// block scrolls on UIPickerTableView. (captured via a forwarding delegate implementation)
if String(describing: type(of: self)) == "UIPickerTableView" {
Expand Down Expand Up @@ -510,6 +524,7 @@
if view.isHidden { return false }
if !view.isUserInteractionEnabled { return false }
if view.isNoCapture() { return false }
if view.window?.isKeyboardWindow == true { return false }

if let textField = view as? UITextField, textField.isSensitiveText() {
return false
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// if you change this, make sure to also change it in the podspec and check if the script scripts/bump-version.sh still works
// This property is internal only
public var postHogVersion = "3.16.1"
public var postHogVersion = "3.16.2"

public let postHogiOSSdkName = "posthog-ios"
// This property is internal only
Expand Down
15 changes: 10 additions & 5 deletions PostHog/UIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
static func swizzleScreenView() {
swizzle(forClass: UIViewController.self,
original: #selector(UIViewController.viewDidAppear(_:)),
new: #selector(UIViewController.viewDidApperOverride))
new: #selector(UIViewController.viewDidAppearOverride))
}

static func unswizzleScreenView() {
swizzle(forClass: UIViewController.self,
original: #selector(UIViewController.viewDidApperOverride),
original: #selector(UIViewController.viewDidAppearOverride),
new: #selector(UIViewController.viewDidAppear(_:)))
}

Expand Down Expand Up @@ -58,11 +58,16 @@
}
}

@objc func viewDidApperOverride(animated: Bool) {
captureScreenView(viewIfLoaded?.window)
@objc func viewDidAppearOverride(animated: Bool) {
// ignore views from keyboard window
// these may include: UIInputWindowController, _UICursorAccessoryViewController, UICompatibilityInputViewController,UIKeyboardHiddenViewController_Autofill and others
if let window = viewIfLoaded?.window, !window.isKeyboardWindow {
captureScreenView(window)
}

// it looks like we're calling ourselves, but we're actually
// calling the original implementation of viewDidAppear since it's been swizzled.
viewDidApperOverride(animated: animated)
viewDidAppearOverride(animated: animated)
}

private func findVisibleViewController(_ controller: UIViewController?) -> UIViewController? {
Expand Down
17 changes: 17 additions & 0 deletions PostHog/Utils/UIWindow+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// UIWindow+.swift
// PostHog
//
// Created by Yiannis Josephides on 03/12/2024.
//

#if os(iOS) || os(tvOS)
import Foundation
import UIKit

extension UIWindow {
var isKeyboardWindow: Bool {
String(describing: type(of: window)) == "UIRemoteKeyboardWindow"
}
}
#endif

0 comments on commit fbf8624

Please sign in to comment.