ios - ios 中 uicollectionview 单元格的谷歌分析事件

标签 ios google-analytics uicollectionviewcell

我的应用程序中有一个 Collection View 。我想为每个 Collection View 单元格放置谷歌分析事件。这意味着,例如,当用户点击单元格时,应该触发 google analycis 事件。我已经为屏幕实现了谷歌分析(对于主屏幕)。但我没有附加图像的权限。

这是我的代码。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CategoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionreuseIdentifier" forIndexPath:indexPath];

[cell addSubview:cell.categorylabel];
//    [cell addSubview:cell.imageWebView];

Attachments *attch = [attachments objectAtIndex:indexPath.row];
cell.categorylabel.text =[NSString stringWithFormat:@" %@  ", attch.attachmenttitle];
[cell.categorylabel sizeToFit];
 //    [cell.imageWebView loadRequest:attch.request];

NSString *html = [NSString stringWithFormat:@"<html><head><style>body{padding:0; margin:0;}</style></head><body><img src='%@' width='800' height='800'></body></html>",attch.imageurl];
[cell.imageWebView loadHTMLString:html baseURL:nil];

self.tracker = [[GAI sharedInstance] defaultTracker];
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"categories" action:attch.attachmenttitle label:attch.attachmenttitle value:[NSNumber numberWithInt:100]] build]];



return cell;
 }

最佳答案

analytics 操作调用到 didSelectItemAtIndexPath

从此处的 cellForItemAtIndexPath 中删除以下行

  self.tracker = [[GAI sharedInstance] defaultTracker];
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"categories" action:attch.attachmenttitle label:attch.attachmenttitle value:[NSNumber numberWithInt:100]] build]];

将行添加到 didSelectItemAtIndexPath

 - (void)tableView:(UICollectionView *)tableView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

 NSArray*cells = [mainTable visibleCells];

UITableViewCell *currentcell = [mainTable cellForRowAtIndexPath:indexPath];
for (UITableViewCell*cell in cells)
{
    if ([cell isEqual:currentcell] == NO) 
     {

       }
    else
    {
       self.tracker = [[GAI sharedInstance] defaultTracker];
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"categories" action:attch.attachmenttitle label:attch.attachmenttitle value:[NSNumber numberWithInt:100]] build]];
     }

}



}

关于ios - ios 中 uicollectionview 单元格的谷歌分析事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31423678/

相关文章:

ios - 垂直滚动时在未调用的 collectionView 上向左/向右滑动

ios - 带有协议(protocol)的 UICollectionViewCell 动画

objective-c - 如何把 "放到 NSString 中?

ios - 如何解析应用程序中的userInfo字典(应用程序: UIApplication, didReceiveRemoteNotification userInfo:[NSObject:AnyObject])

php - 如何使用新的 Google Analytics 在 PHP 中获取当前访问者的推荐人、付费/自然人和关键字?

google-analytics - Google Analytics 上的平均页面停留时间 VS 平均访问持续时间

google-analytics - 我可以使用Google Analytics(分析)查看/检索全局统计信息吗

快速获取位置然后加载表

ios - 隐藏 MPRemoteCommand 向前搜索和向后搜索

iphone - 自动释放和属性