用户体验数据相关接口

自定义冷启动耗时

SDK 默认计算 SDK 初始化开始至第一个页面加载结束的时间为「冷启动耗时」,研发人员可以根据自身应用需求更改计算「冷启动耗时」的结束点。

  • 开启自定义冷启动耗时控制开关

    • 相关接口
    /**
     * @enable 传入YES,开启设置自定义启动结束功能
     */
    + (void)customLaunchEnd:(BOOL)enable;
    
    • 代码示例
    int main(int argc, char * argv[]) {
     @autoreleasepool {
        // 设置开启自定义结束点功能,在启动SDK之前调用。
        [NBSAppAgent customLaunchEnd:YES];
        [NBSAppAgent startWithAppID:@"appkey"];
        ...
        }
    }
    
  • 设置自定义冷启动耗时的结束点

    该接口需要与「customLaunchEnd」配合使用,当设置「customLaunchEnd」接口为 YES 时,「launchFinish」接口设置生效。

    • 相关接口
    /**
     * 自定义结束时间点,在启动结束时调用。
     */
    + (void)launchFinish:(NSString *)lanuchName;
    
    • 代码示例
    -(void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        [NBSAppAgent launchFinish:@"firstVC"];
    }
    

自定义Trace埋点

由于 TingYun_SDK 默认关注系统类和方法,无法关注「业务代码」的耗时情况,使用「自定义埋点」接口可以补全「页面体验分析」和「操作体验分析」模块中的【分解图】,能够帮助开发者清晰的了解其业务代码的耗时及调用情况。

  • 相关接口

注意:「自定义Trace埋点」接口需要成对调用,请勿跨方法、跨进程以及在异步加载和递归调用中使用该接口。

// @String Name为当前方法所在方法名或自定义名称,支持中文、英文、数字、下划线,但不能包含空格或其他的转义字符
beginTracer(@"StringName")
endTracer(@"StringName")
  • 代码示例
- (void)doSomething
{
  // 用户可以在SDK初始化后的任意方法前后添加自定义Trace
  beginTracer(@"TraceName")
  // write you code here
  endTracer(@"TraceName")
}

自定义操作

通过「自定义操作」来定义一个【业务操作】用以了解其性能表现情况。

  • 相关接口

注意:「自定义操作」接口需要成对调用,actionName不可为空,支持跨方法、跨线程调用。

+ (void)customActionStart:(NSString *)actionName;
+ (void)customActionEnd:(NSString *)actionName withTag:(NSString *)tag withCustomInfo:(NSDictionary *)customInfo;
  • 代码示例
- (void)doSomething
{
    [NBSAppAgent customActionStart:@"doSomething"];
        ...
    NSDictionary *cust = @{@"key":@"value"};
    [NBSAppAgent customActionEnd:@"doSomething" withTag:@"tag" withCustomInfo:cust];
}

自定义页面结束

通过「自定义页面结束」来定义一个【页面实际加载时间】用以了解其性能表现情况

  • 相关接口

注意:「自定义页面结束」接口需要成对调用,pageName不可为空,支持跨方法、跨线程调用,App启动过程中的视图控制器不支持自定义;需要将 customPageLoad: 返回的结果 customId 传入到 customPageLoadFinish:withPageName: 中来关联结束。 在待自定义视图控制器 viewDidLoad 中调用 customPageLoad: ;在待自定义视图控制器 viewDidAppear 之后调用customPageLoadFinish:withPageName: 。

/**
 * 是否自定义页面结束点
 * @param enable 是否自定义. 
 * @result identifier 关联结束。
 */
+ (NSInteger)customPageLoad:(BOOL)enable;

/**
 * 自定义页面结束。
 * @param customId 传入customPageLoad返回的id。
 * @param pageName 页面名称
 */
+ (void)customPageLoadFinish:(NSInteger)customId withPageName:(NSString *)pageName;
  • 代码示例
- (void)viewDidLoad {
    [super viewDidLoad];
    customId = [NBSAppAgent customPageLoad:YES];
    ...
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    ....
    dispatch_async(dispatch_get_main_queue(), ^{
        [NBSAppAgent customPageLoadFinish:customId withPageName:@"CustomPage"];
    });
}

设置ViewID

设置viewId后,平台「操作分析」和「可视化命名」功能会优先使用该属性进行归类。

  • 示例
UIView *view = [UIView new];
[view setTingyunAttributesIdentifier:@"TYIdentifier"];

设置ViewName

设置ViewName后,平台「操作分析」和「可视化命名」功能会优先使用该属性进行归类。

  • 示例
UIView *view = [UIView new];
[view setTingyunAttributesName:@"TYViewName"];

设置PageName「视图别名」

设置PageName后,平台「操作分析」和「可视化命名」功能会优先使用该属性进行归类。

  • 示例
ViewController *vc = [ViewController new];
[vc setTingyunAttributesPageName:@"TYPageName"];
© 2007-2024 北京基调网络股份有限公司 all right reserved,powered by Gitbook本文档更新于: 2024-03-04 10:18

results matching ""

    No results matching ""