{"id":17992610,"url":"https://github.com/623637646/impressionkit","last_synced_at":"2025-05-09T00:03:36.321Z","repository":{"id":42626037,"uuid":"164836974","full_name":"623637646/ImpressionKit","owner":"623637646","description":"A tool to detect impression events for UIView (exposure of UIView) in iOS. SwiftUI supported.","archived":false,"fork":false,"pushed_at":"2025-04-01T10:36:18.000Z","size":1527,"stargazers_count":130,"open_issues_count":0,"forks_count":25,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-09T00:03:02.216Z","etag":null,"topics":["exposed","exposure","impression","impressions","swiftui","track","ubt","usertracking"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/623637646.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-01-09T09:59:33.000Z","updated_at":"2025-05-08T02:23:48.000Z","dependencies_parsed_at":"2023-11-25T11:25:35.319Z","dependency_job_id":"894c836d-7630-436a-80fb-bc483b9ee7cc","html_url":"https://github.com/623637646/ImpressionKit","commit_stats":{"total_commits":168,"total_committers":9,"mean_commits":"18.666666666666668","dds":0.6190476190476191,"last_synced_commit":"1a70ee3e308fb7ccfaa9f524044a04aaae8c2e8a"},"previous_names":["623637646/exposurekit"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/623637646%2FImpressionKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/623637646%2FImpressionKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/623637646%2FImpressionKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/623637646%2FImpressionKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/623637646","download_url":"https://codeload.github.com/623637646/ImpressionKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166502,"owners_count":21864475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exposed","exposure","impression","impressions","swiftui","track","ubt","usertracking"],"created_at":"2024-10-29T20:08:34.256Z","updated_at":"2025-05-09T00:03:36.126Z","avatar_url":"https://github.com/623637646.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[中文](README.zh-Hans.md)\n\n# ImpressionKit\n\nThis is a user behavior tracking (UBT) tool to analyze impression events for UIView (exposure of UIView) in iOS.\n\n![ezgif com-gif-maker](https://user-images.githubusercontent.com/5275802/120922347-30a2d200-c6fb-11eb-8994-f97c2bbc0ff8.gif)\n\nHow it works: Hook the `didMoveToWindow` method of a UIView by [SwiftHook](https://github.com/623637646/SwiftHook), periodically check the view is on the screen or not.\n\n# How to use ImpressionKit\n\n### Main APIs\n\nIt's quite simple. \n\n\n```swift\n\n// UIKit\n\nUIView().detectImpression { (view, state) in\n    if state.isImpressed {\n        print(\"This view is impressed to users.\")\n    }\n}\n\n// SwiftUI\n\nColor.red.detectImpression { state in\n    if state.isImpressed {\n        print(\"This view is impressed to users.\")\n    }\n}\n```\n\nUse `ImpressionGroup` for UICollectionView, UITableView, List or other reusable view cases.\n\n```swift\n// UIKit\n\nvar group = ImpressionGroup.init {(_, index: IndexPath, view, state) in\n    if state.isImpressed {\n        print(\"impressed index: \\(index.row)\")\n    }\n}\n\n...\n\nfunc collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -\u003e UICollectionViewCell {\n    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) as! Cell\n    self.group.bind(view: cell, index: indexPath)\n    return cell\n}\n\n// SwiftUI\n\nvar group = ImpressionGroup.init { (_, index: Int, _, state) in\n    if state.isImpressed {\n        print(\"impressed index: \\(index)\")\n    }\n}\n\nvar body: some View {\n    List(0 ..\u003c 100) { index in\n        CellView(index: index)\n            .frame(height: 100)\n            .detectImpression(group: group, index: index)\n    }\n}\n```\n\n### More APIs\n\nModify the detection (scan) interval (in seconds). Smaller `detectionInterval` means higher accuracy and higher CPU consumption.\n\n```swift\nUIView.detectionInterval = 0.1  // apply to all views\nUIView().detectionInterval = 0.1    // apply to the specific view. `UIView.detectionInterval` will be used if it's nil.\nImpressionGroup().detectionInterval = 0.1   // apply to the group. `UIView.detectionInterval` will be used if it's nil.\n```\n\nModify the threshold (seconds) for the duration of a view on the screen. If the view's duration on the screen exceeds this threshold, it may trigger an impression.\n\n```swift\nUIView.durationThreshold = 2  // apply to all views\nUIView().durationThreshold = 2    // apply to the specific view. `UIView.durationThreshold` will be used if it's nil.\nImpressionGroup().durationThreshold = 2   // apply to the group. `UIView.durationThreshold` will be used if it's nil.\n```\n\nModify the threshold (from 0 to 1) for the area ratio of the view on the screen. If the percentage of the view's area on the screen exceeds this threshold, it may trigger an impression.\n\n```swift\nUIView.areaRatioThreshold = 0.4  // apply to all views\nUIView().areaRatioThreshold = 0.4    // apply to the specific view. `UIView.areaRatioThreshold` will be used if it's nil.\nImpressionGroup().areaRatioThreshold = 0.4   // apply to the group. `UIView.areaRatioThreshold` will be used if it's nil.\n```\n\nModify the threshold (from 0 to 1) for the view opacity. If the view's opacity exceeds this threshold, it may trigger an impression.\n\n```swift\nUIView.alphaThreshold = 0.4  // apply to all views\nUIView().alphaThreshold = 0.4    // apply to the specific view. `UIView.alphaThreshold` will be used if it's nil.\nImpressionGroup().alphaThreshold = 0.4   // apply to the group. `UIView.alphaThreshold` will be used if it's nil.\n```\n\nRetrigger the impression event in some situations.\n\n```swift\n// Retrigger the impression event when a view left from the screen (The UIViewController (page) is still here, Just the view is out of the screen).\npublic static let leftScreen = Redetect(rawValue: 1 \u003c\u003c 0)\n\n// Retrigger the impression event when the UIViewController of the view disappear.\npublic static let viewControllerDidDisappear = Redetect(rawValue: 1 \u003c\u003c 1)\n\n// Retrigger the impression event when the App did enter background.\npublic static let didEnterBackground = Redetect(rawValue: 1 \u003c\u003c 2)\n\n// Retrigger the impression event when the App will resign active.\npublic static let willResignActive = Redetect(rawValue: 1 \u003c\u003c 3)\n```\n\n```swift\nUIView.redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive]  // apply to all views\nUIView().redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive]    // apply to the specific view. `UIView.redetectOptions` will be used if it's nil.\nImpressionGroup().redetectOptions = [.leftScreen, .viewControllerDidDisappear, .didEnterBackground, .willResignActive]   // apply to the group. `UIView.redetectOptions` will be used if it's nil.\n```\n\nRefer to the Demo for more details.\n\n# How to integrate ImpressionKit\n\n**ImpressionKit** can be integrated by [cocoapods](https://cocoapods.org/). \n\n```\npod 'ImpressionKit'\n```\n\nOr use Swift Package Manager. SPM is supported from 3.1.0.\n\n# Requirements\n\n- iOS 12.0+ (UIKit)\n- iOS 13.0+ (SwiftUI)\n- Xcode 15.1+\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F623637646%2Fimpressionkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F623637646%2Fimpressionkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F623637646%2Fimpressionkit/lists"}