iOS tableView 曝光埋点去重逻辑
思路
记录上次曝光时展示的cell, 和这次展示的cell 数组对比,上次没有的cell,就是这次需要曝光的cell
代码
//self.preTempArray 记录了上次曝光时候的数据,用来和这次的对比,做数据去重
- (void)cardExposureStatistics:(UITableView *)tableView dataSource:(NSMutableArray *)dataArray cellHeight:(CGFloat)cellHeight superView:(UIView *)superView pv_id:(NSString *)pv_id {
if (dataArray.count == 0) {
return;
}
NSMutableArray *cellArray = [NSMutableArray new];
[cellArray removeAllObjects];
[cellArray addObjectsFromArray:tableView.visibleCells];
UITableViewCell *firstCell = [cellArray firstObject];
UITableViewCell *lastCell = [cellArray lastObject];
NSIndexPath *firstIndexPath = [tableView indexPathForCell:firstCell];
NSIndexPath *lastIndexPath = [tableView indexPathForCell:lastCell];
CGRect firstRect = [tableView rectForRowAtIndexPath:firstIndexPath];
CGRect lastRect = [tableView rectForRowAtIndexPath:lastIndexPath];
CGFloat firstCellY = [tableView convertRect:firstRect toView:superView].origin.y;
CGFloat lastCellY = [tableView convertRect:lastRect toView:superView].origin.y;
if (cellHeight/2 firstCellY < SafeAreaTopHeight) {
/// 这里是cell需要有超过一半展示在屏幕中
[cellArray removeObject:firstCell];
}
if (cellHeight/2 lastCellY > bottomBarHeight) {
/// 这里是cell需要有超过一半展示在屏幕中
[cellArray removeObject:lastCell];
}
NSMutableArray *listBoArray = [NSMutableArray new];//这个记录上次屏幕出现的卡片,之后会筛掉preArray存的卡片
NSMutableArray *tempListBoArray = [NSMutableArray new];//这个只是为了记录上次屏幕出现的卡片,给preArray赋值
[cellArray enumerateObjectsUsingBlock:^(UITableViewCell *cell, NSUInteger idx, BOOL * _Nonnull stop) {
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
id data = dataArray[indexPath.row];
[listBoArray addObject:data];
[tempListBoArray addObject:data];
}];
[self.preTempArray enumerateObjectsUsingBlock:^(listContObjectVO *listItem, NSUInteger idx, BOOL * _Nonnull stop) {
if ([listBoArray containsObject:listItem]) {
/// 这里是做数据去重,去掉上次展示过的数据
[listBoArray removeObject:listItem];
}
}];
[self.preTempArray removeAllObjects];
///这里更新数据,下次展示的时候去重
[self.preTempArray addObjectsFromArray:tempListBoArray];
if (listBoArray.count > 0) {
/// listBoArray是已经去过重的数据
[[LogManager shareInstance] cardExposure:[ServiceAnalysisModel getCardExposureAnalysisModelArray:listBoArray pv_id:pv_id]];
}
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgcbjai
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01