Swifty solution for marketing impression event tracking on UICollectionView
Tracking impression event of cells in the collection views requires a bit of dirty work, especially if it has minimum percentage constraint of visible area of cell to count as viewed. ListingImpressionStalker provides a solution for it. In the demo project, cells which are counted as viewed filled with green color as you can see below, of course it depends on their minimum percent values.
%30 Min Percentage | %90 Min Percentage |
---|---|
Just drag and drop ListingImpressionStalker to your project.
- Initialize ListingImpressionStalker with a desired initializer, after your collection view is set.
@IBOutlet weak var collectionView:UICollectionView!{
didSet{
impressionEventStalker = ListingImpressionStalker(minimumPercentageOfCell: 1.0, collectionView: collectionView, delegate: self)
}
}
- Make sure your view controller conforms "ListingImpressionStalkerDelegate"
- In your custom UICollectionViewCell class, conform "ListingImpressionItem" protocol to provide unique identifier for each item to ensure each items event sent only once.
- In your view controller, call stalkCells() method in viewDidAppear() and scrollViewDidScroll().
- After it is configured, sendEventForCell(atIndexPath indexPath:IndexPath) method fired from ListingImpressionStalker when a cell's visible percent becomes greater than minimumPercentageOfCell. A cell index sent via this method never sent again.
- minimumPercentageOfCell: Minimum percentage of visible area of cell to count cell as viewed. If it is not set properly, it is set to 0.5 automatically.
- delegate: ListingImpressionStalkerDelegate object. Viewed cells index paths are sent to object that conforms this protocol.
- collectionView: The collection view which is tracked.
Just send me an email (ergunemr@gmail.com)