ads tracking

This commit is contained in:
Stefan Lange-Hegermann
2025-11-05 11:13:40 +01:00
parent 5fcc33529a
commit ced06f9eb6
198 changed files with 21205 additions and 262 deletions

View File

@@ -0,0 +1,70 @@
//
// PostHogSurveysDefaultDelegate.swift
// PostHog
//
// Created by Ioannis Josephides on 18/06/2025.
//
#if os(iOS)
import UIKit
#else
import Foundation
#endif
final class PostHogSurveysDefaultDelegate: PostHogSurveysDelegate {
#if os(iOS)
private var surveysWindow: UIWindow?
private var displayController: SurveyDisplayController?
#endif
func renderSurvey(
_ survey: PostHogDisplaySurvey,
onSurveyShown: @escaping OnPostHogSurveyShown,
onSurveyResponse: @escaping OnPostHogSurveyResponse,
onSurveyClosed: @escaping OnPostHogSurveyClosed
) {
#if os(iOS)
guard #available(iOS 15.0, *) else { return }
if surveysWindow == nil {
// setup window for first-time display
setupWindow()
}
// Setup handlers
displayController?.onSurveyShown = onSurveyShown
displayController?.onSurveyResponse = onSurveyResponse
displayController?.onSurveyClosed = onSurveyClosed
// Display survey
displayController?.showSurvey(survey)
#endif
}
func cleanupSurveys() {
#if os(iOS)
displayController?.dismissSurvey() // dismiss any active surveys
surveysWindow?.rootViewController?.dismiss(animated: true) {
self.surveysWindow?.isHidden = true
self.surveysWindow = nil
self.displayController = nil
}
#endif
}
#if os(iOS)
@available(iOS 15.0, *)
private func setupWindow() {
if let activeWindow = UIApplication.getCurrentWindow(), let activeScene = activeWindow.windowScene {
let controller = SurveyDisplayController()
displayController = controller
surveysWindow = SurveysWindow(
controller: controller,
scene: activeScene
)
surveysWindow?.isHidden = false
surveysWindow?.windowLevel = activeWindow.windowLevel + 1
}
}
#endif
}