[英]google analytics events for uicollectionview cell in ios
I have a collection view in my app. 我的应用程序中有一个收藏夹视图。 I want to put google analytics events for each collection view cell.
我想为每个集合视图单元格放置Google Analytics(分析)事件。 That meant ,as an example when user taps on a cell, google analycis event should trigger.
这意味着,例如,当用户点击一个单元格时,应触发google analycis事件。 I have implement google analytics for screens(for main screen).stiil I do not have permission to attach images.
我已经针对屏幕(针对主屏幕)实施了Google Analytics(分析)。stiil我没有附加图像的权限。
this is my code. 这是我的代码。
- (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;
}
call the analytics
action to didSelectItemAtIndexPath
将
analytics
操作调用到didSelectItemAtIndexPath
remove the following line from cellForItemAtIndexPath
here 在此处从
cellForItemAtIndexPath
删除以下行
self.tracker = [[GAI sharedInstance] defaultTracker];
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"categories" action:attch.attachmenttitle label:attch.attachmenttitle value:[NSNumber numberWithInt:100]] build]];
add the line to didSelectItemAtIndexPath
将行添加到
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
is called each time cell is about to be presented ot screen(for example if it was not visible and user scrolled or when initial load of collection view). cellForItemAtIndexPath
将要在屏幕上显示单元格时,都会调用cellForItemAtIndexPath
(例如,如果单元格不可见且用户滚动或初始加载集合视图时)。 If you want to track when user taps on cell you need to call GAI method inside didSelectItemAtIndexPath
. 如果要跟踪用户何时点击单元格,则需要在
didSelectItemAtIndexPath
内部调用GAI方法。
Copy the same code of Screen Tracking & replace it with you required values in the CollectionView
Delegate method. 复制相同的屏幕跟踪代码,并在
CollectionView
委托方法中将其替换为所需的值。
- (void)tableView:(UICollectionView *)tableView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// Your Google Analytics code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.