Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A tool to detect impression events for UIView (exposure of UIView) in iOS. SwiftUI supported.

License

NotificationsYou must be signed in to change notification settings

623637646/ImpressionKit

Repository files navigation

中文

ImpressionKit

This is a user behavior tracking (UBT) tool to analyze impression events for UIView (exposure of UIView) in iOS.

ezgif com-gif-maker

How it works: Hook thedidMoveToWindow method of a UIView bySwiftHook, periodically check the view is on the screen or not.

How to use ImpressionKit

Main APIs

It's quite simple.

// UIKitUIView().detectImpression{(view, state)inif state.isImpressed{print("This view is impressed to users.")}}// SwiftUIColor.red.detectImpression{ stateinif state.isImpressed{print("This view is impressed to users.")}}

UseImpressionGroup for UICollectionView, UITableView, List or other reusable view cases.

// UIKitvargroup=ImpressionGroup.init{(_, index:IndexPath, view, state)inif state.isImpressed{print("impressed index:\(index.row)")}}...func collectionView(_ collectionView:UICollectionView, cellForItemAt indexPath:IndexPath)->UICollectionViewCell{letcell= collectionView.dequeueReusableCell(withReuseIdentifier:"Cell", for: indexPath)as!Cellself.group.bind(view: cell, index: indexPath)return cell}// SwiftUIvargroup=ImpressionGroup.init{(_, index:Int, _, state)inif state.isImpressed{print("impressed index:\(index)")}}varbody:someView{List(0..<100){ indexinCellView(index: index).frame(height:100).detectImpression(group: group, index: index)}}

More APIs

Modify the detection (scan) interval (in seconds). SmallerdetectionInterval means higher accuracy and higher CPU consumption.

UIView.detectionInterval=0.1  // apply to all viewsUIView().detectionInterval=0.1    // apply to the specific view. `UIView.detectionInterval` will be used if it's nil.ImpressionGroup().detectionInterval=0.1   // apply to the group. `UIView.detectionInterval` will be used if it's nil.

Modify 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.

UIView.durationThreshold=2  // apply to all viewsUIView().durationThreshold=2    // apply to the specific view. `UIView.durationThreshold` will be used if it's nil.ImpressionGroup().durationThreshold=2   // apply to the group. `UIView.durationThreshold` will be used if it's nil.

Modify 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.

UIView.areaRatioThreshold=0.4  // apply to all viewsUIView().areaRatioThreshold=0.4    // apply to the specific view. `UIView.areaRatioThreshold` will be used if it's nil.ImpressionGroup().areaRatioThreshold=0.4   // apply to the group. `UIView.areaRatioThreshold` will be used if it's nil.

Modify the threshold (from 0 to 1) for the view opacity. If the view's opacity exceeds this threshold, it may trigger an impression.

UIView.alphaThreshold=0.4  // apply to all viewsUIView().alphaThreshold=0.4    // apply to the specific view. `UIView.alphaThreshold` will be used if it's nil.ImpressionGroup().alphaThreshold=0.4   // apply to the group. `UIView.alphaThreshold` will be used if it's nil.

Retrigger the impression event in some situations.

// 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).publicstaticletleftScreen=Redetect(rawValue:1 <<0)// Retrigger the impression event when the UIViewController of the view disappear.publicstaticletviewControllerDidDisappear=Redetect(rawValue:1 <<1)// Retrigger the impression event when the App did enter background.publicstaticletdidEnterBackground=Redetect(rawValue:1 <<2)// Retrigger the impression event when the App will resign active.publicstaticletwillResignActive=Redetect(rawValue:1 <<3)
UIView.redetectOptions=[.leftScreen,.viewControllerDidDisappear,.didEnterBackground,.willResignActive]  // apply to all viewsUIView().redetectOptions=[.leftScreen,.viewControllerDidDisappear,.didEnterBackground,.willResignActive]    // apply to the specific view. `UIView.redetectOptions` will be used if it's nil.ImpressionGroup().redetectOptions=[.leftScreen,.viewControllerDidDisappear,.didEnterBackground,.willResignActive]   // apply to the group. `UIView.redetectOptions` will be used if it's nil.

Refer to the Demo for more details.

How to integrate ImpressionKit

ImpressionKit can be integrated bycocoapods.

pod 'ImpressionKit'

Or use Swift Package Manager. SPM is supported from 3.1.0.

Requirements

  • iOS 12.0+ (UIKit)
  • iOS 13.0+ (SwiftUI)
  • Xcode 15.1+

About

A tool to detect impression events for UIView (exposure of UIView) in iOS. SwiftUI supported.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp