一、 在需要使用统计的地方加入 ⤵️ -----------------------------------```
- 页面统计 - 进入某一个界面时.
[UMengRecordTool umengEnterViewWithName:@"类名/界面名称"];
- 页面统计 - 退出某一个界面时.
[UMengRecordTool umengOutViewWithName:@"类名/界面名称"];
- 自定义事件统计之计数事件 - 比如点击了某处.
[UMengRecordTool umengEventCountWithId:@"事件ID"];
4.自定义事件统计之计算事件 - 需要观察分析的较复杂数据.
[UMengRecordTool umengEventCalculatWithId:@"在开发者中心预设的对应事件id" attributes:<#(NSDictionary *)#> number:<#(id)#>]; //number为该统计观察的数据,number\attributes可传nil.
5.扩展 - 用户浏览滚动视图界面的多少/百分比 tableView/collectionView也可以用
//竖直滚动方向isVertical为YES,水平方向为NO
[UMengRecordTool umengEventScrollViewWithId:@"在开发者中心预设的对应id" attributes:nil scrollview: tableView/collectionView/scrollView isVertical:YES];
--------分割一下--------
二、工具类代码: -----------------------------------```
1、 .h文件:
#import <Foundation/Foundation.h>
#import "UMMobClick/MobClick.h"
@interface UMengRecordTool : NSObject
/**
@ 页面统计 - 进入
@param name 界面名称
*/
+ (void)umengEnterViewWithName:(NSString *)name;
/**
@ 页面统计 - 退出
@param name 界面名称
*/
+ (void)umengOutViewWithName:(NSString *)name;
/**
@ 计数事件统计
@param eventId 事件Id
*/
+ (void)umengEventCountWithId:(NSString *)eventId;
/**
@ 计算事件统计
@param eventId 事件Id
@param attributes 统计内容
@param number 统计的数
*/
+ (void)umengEventCalculatWithId:(NSString *)eventId
attributes:(NSDictionary *)attributes
number:(id)number;
/**
ScrollView 已滚动/浏览的百分比
@param eventId 事件Id
@param attributes 内容[可不传、为nil]
@param scrollview 滚动视图
@param isVertical 竖直方向YES、 水平方向NO
*/
+ (void)umengEventScrollViewWithId:(NSString *)eventId
attributes:(NSDictionary *)attributes
scrollview:(UIScrollView *)scrollview
isVertical:(BOOL)isVertical;
@end
2、.m文件:
#import "UMengRecordTool.h"
@implementation UMengRecordTool
/**
@ 页面统计 - 进入
*/
+ (void)umengEnterViewWithName:(NSString *)name
{
[MobClick beginLogPageView:name];
}
/**
@ 页面统计 - 退出
*/
+ (void)umengOutViewWithName:(NSString *)name
{
[MobClick endLogPageView:name];
}
/**
@ 计数事件统计
*/
+ (void)umengEventCountWithId:(NSString *)eventId
{
[MobClick event:eventId];
}
/**
@ 计算事件统计
*/
+ (void)umengEventCalculatWithId:(NSString *)eventId attributes:(NSDictionary *)attributes number:(id)number
{
NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:attributes];
if (number) {
NSString *numberKey = @"__ct__";
[mutableDictionary setObject:[number stringValue] forKey:numberKey];
}
[MobClick event:eventId attributes:mutableDictionary];
}
/**
@ ScrollView 已滚动/浏览的百分比
*/
+ (void)umengEventScrollViewWithId:(NSString *)eventId attributes:(NSDictionary *)attributes scrollview:(UIScrollView *)scrollview isVertical:(BOOL)isVertical
{
NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:attributes];
CGFloat x = scrollview.contentOffset.x;
CGFloat y = scrollview.contentOffset.y;
CGFloat width = scrollview.contentSize.width;
CGFloat height = scrollview.contentSize.height;
CGFloat superVWidth = scrollview.superview.frame.size.width;
CGFloat superVHeight = scrollview.superview.frame.size.height;
if (isVertical) { //竖直
int yInt;
if (height <= superVHeight)
{
yInt = 100;
}else
{
yInt = ((y+superVHeight)/height) *100;
}
NSString *numberKey = @"__ct__";
[mutableDictionary setObject:[NSString stringWithFormat:@"%d",yInt] forKey:numberKey];
}else{
int xInt;
if (width <= superVWidth)
{
xInt = 100;
}else{
xInt = ((x+superVWidth)/width) *100;
}
NSString *numberKey = @"__ct__";
[mutableDictionary setObject:[NSString stringWithFormat:@"%d",xInt] forKey:numberKey];
}
[MobClick event:eventId attributes:mutableDictionary];
}
@end
完。