移动应用开发中基本都要用到用户分析,大部分的应用选择的友盟统计,我们也不例(其实不是没有内部的统计,是实在是人手不足,做的没人家好用啊).这篇文章题主就来分享下自己是如何封装的统计模块.
业务需求经过抽象后,基本可以分为两层
我们的一个上报信息就由模块名 + 页面名 + 事件名字 + 事件类型 +事件子类型 + 上报的数据
组成
@interface TestUserAction : UserAction
+ (instancetype)usertAction1;
+ (instancetype)usertAction2;
@end
@implementation TestUserAction
- (instancetype)init
{
self = [super init];
if (self) {
self.module = @"__untiTest1";
}
return self;
}
+ (instancetype)usertAction1
{
TestUserAction *userAction = [TestUserAction uiTapEvent:@"event1" atPage:@"page1"];
return userAction;
}
+ (instancetype)usertAction2
{
TestUserAction *userAction = [TestUserAction businessStartEvent:@"event1" atPage:@"page1"];
userAction.userInfo = @{ @"rid" : @"100",
@"uid" : @"1000" };
userAction.autoSource = YES;
return userAction;
}
@end
// test
UXY_DESCRIBE( test1 )
{
[[ReportingService instance] removeASourceAtUserActionClassType:@"TestUserAction"];
[[ReportingService instance] addASource:@"来自火星" atUserActionClassType:@"TestUserAction"];
[[ReportingService instance] addASource:@"测试页面" atUserActionClassType:@"TestUserAction"];
[[ReportingService instance] removeASourceAtUserActionClassType:@"TestUserAction"];
}
UXY_DESCRIBE( test2 )
{
UXY_TIMES(10)
{
[[ReportingService instance] reportUserAction:[TestUserAction usertAction1]];
[[ReportingService instance] reportUserAction:[TestUserAction usertAction2]];
}
}
// test
UXY_DESCRIBE( test3 )
{
UXY_TIMES(10)
{
TestUserAction.ACTION(nil)
.MODULE(@"__untiTest2")
.PAGE(@"page1")
.EVENT(@"event2")
.SOURCE(@"test3")
.UI()
.TAP()
.REPORT();
TestUserAction.ACTION(nil)
.PAGE(@"page1")
.EVENT(@"event2")
.AUTOSOURCE()
.BUSINESS()
.START()
.REPORT();
}
}
UXY_DESCRIBE( test4 )
{
UXY_TIMES(10)
{
// 分开设置来源, 小模块, 事件类型, 事件名称
{
TestUserAction.ACTION(@"myEvent")
.SOURCE(@"test3");
}
{
TestUserAction.ACTION(@"myEvent")
.PAGE(@"page1");
}
{
TestUserAction.ACTION(@"myEvent")
.UI()
.TAP();
}
{
TestUserAction.ACTION(@"myEvent")
.EVENT(@"event2")
.REPORT();
}
}
}
原文地址:http://blog.csdn.net/uxyheaven/article/details/45873007