google ios 中 uicollectionview 单元格的分析事件
google analytics events for uicollectionview cell in ios
我的应用程序中有一个集合视图。我想为每个集合视图单元放置 google 个分析事件。这意味着,例如,当用户点击一个单元格时,google analycis 事件应该触发。我已经实施 google 屏幕分析(对于主屏幕)。但我没有附加图像的权限。
这是我的代码。
- (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]];
}
}
}
cellForItemAtIndexPath
每次单元格即将显示在屏幕上时调用(例如,如果它不可见并且用户滚动或初始加载集合视图时)。如果您想跟踪用户点击单元格的时间,您需要在 didSelectItemAtIndexPath
.
中调用 GAI 方法
复制屏幕跟踪的相同代码,并在 CollectionView
委托方法中将其替换为您需要的值。
- (void)tableView:(UICollectionView *)tableView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// Your Google Analytics code
}
我的应用程序中有一个集合视图。我想为每个集合视图单元放置 google 个分析事件。这意味着,例如,当用户点击一个单元格时,google analycis 事件应该触发。我已经实施 google 屏幕分析(对于主屏幕)。但我没有附加图像的权限。
这是我的代码。
- (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]];
}
}
}
cellForItemAtIndexPath
每次单元格即将显示在屏幕上时调用(例如,如果它不可见并且用户滚动或初始加载集合视图时)。如果您想跟踪用户点击单元格的时间,您需要在 didSelectItemAtIndexPath
.
复制屏幕跟踪的相同代码,并在 CollectionView
委托方法中将其替换为您需要的值。
- (void)tableView:(UICollectionView *)tableView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// Your Google Analytics code
}