美文网首页iOS 移动端开发
iOS 友盟统计 - 页面统计、自定义事件的统计

iOS 友盟统计 - 页面统计、自定义事件的统计

作者: L一N | 来源:发表于2018-03-12 17:58 被阅读1533次

一、 在需要使用统计的地方加入 ⤵️ -----------------------------------```

  1. 页面统计 - 进入某一个界面时.

[UMengRecordTool umengEnterViewWithName:@"类名/界面名称"];

  1. 页面统计 - 退出某一个界面时.

[UMengRecordTool umengOutViewWithName:@"类名/界面名称"];

  1. 自定义事件统计之计数事件 - 比如点击了某处.
[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


完。

相关文章

网友评论

  • 小代码仔:请问除了最后一个实例方法,您写这个Tool 类的优势在哪儿?
    L一N:没有什么优势,写这个tool的初衷:1是因为原来项目中根据登录账号会切换成四个客户端,然后想在友盟统计前增加前缀方便在友盟统计上查看统计数据来自什么角色的客户端; 2.其他项目可以复用; 3.是加了中文解释方便第一次接友盟统计的同行看明白一点。
  • 疯子一样男人:友盟能统计能统计停留时间吗 ?
    L一N:@UILabel12 友盟有自带应用使用时长时间统计,关于界面停留时间的话,可以自己加个自定义事件

本文标题:iOS 友盟统计 - 页面统计、自定义事件的统计

本文链接:https://www.haomeiwen.com/subject/fzfofftx.html