User Experience Data
Custom Cold Start Duration
By default, the SDK calculates the time from SDK initialization start to the first page load completion as "cold start duration." Developers can change the end point for calculating "cold start duration" according to their application requirements.
-
Enable Custom Cold Start Duration Switch
- Related API
/**
* @enable Pass YES to enable custom launch end functionality
*/
+ (void)customLaunchEnd:(BOOL)enable;- Code Example
int main(int argc, char * argv[]) {
@autoreleasepool {
// Enable custom launch end functionality, call before starting the SDK.
[NBSAppAgent customLaunchEnd:YES];
[NBSAppAgent startWithAppID:@"appkey"];
...
}
} -
Set Custom Cold Start End Point
This API needs to be used together with
customLaunchEnd. WhencustomLaunchEndis set to YES, thelaunchFinishAPI takes effect.- Related API
/**
* Custom end time point, call at the end of launch.
*/
+ (void)launchFinish:(NSString *)lanuchName;- Code Example
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[NBSAppAgent launchFinish:@"firstVC"];
}
Custom Trace Instrumentation
Since TingYun_SDK by default tracks system classes and methods, it cannot track the duration of "business code." Using the "custom trace" API can supplement the [Page Experience Analysis] and [Action Experience Analysis] modules' breakdown chart, helping developers clearly understand the duration and invocation of their business code.
- Related API
Note: The "custom trace" API must be used in pairs. Do not use across methods, processes, or in asynchronous loading and recursive calls.
// @String Name is the method name or custom name for the current method, supports Chinese, English, numbers, underscores, but cannot contain spaces or other special characters
beginTracer(@"StringName")
endTracer(@"StringName")
- Code Example
- (void)doSomething
{
// Developers can add custom traces before and after any method after SDK initialization
beginTracer(@"TraceName")
// write your code here
endTracer(@"TraceName")
}
Custom Action
Define a [business action] through "custom action" to understand its performance.
- Related API
Note: The "custom action" API must be used in pairs. actionName cannot be empty, supports cross-method, cross-thread calls.
+ (void)customActionStart:(NSString *)actionName;
+ (void)customActionEnd:(NSString *)actionName withTag:(NSString *)tag withCustomInfo:(NSDictionary *)customInfo;
- Code Example
- (void)doSomething
{
[NBSAppAgent customActionStart:@"doSomething"];
...
NSDictionary *cust = @{@"key":@"value"};
[NBSAppAgent customActionEnd:@"doSomething" withTag:@"tag" withCustomInfo:cust];
}
Custom Page End
Define a [real page load duration] through "custom page end" to understand its performance.
- Related API
Note: The "custom page end" API must be used in pairs. pageName cannot be empty, supports cross-method, cross-thread calls. During app startup, custom view controllers are not supported; you need to pass the customId returned by customPageLoad: to customPageLoadFinish:withPageName: to associate the end. Call customPageLoad: in viewDidLoad of the custom view controller; call customPageLoadFinish:withPageName: after viewDidAppear of the custom view controller.
/**
* Whether to use custom page end point
* @param enable Whether to use custom.
* @result identifier for associating the end.
*/
+ (NSInteger)customPageLoad:(BOOL)enable;
/**
* Custom page end.
* @param customId Pass the id returned by customPageLoad.
* @param pageName Page name
*/
+ (void)customPageLoadFinish:(NSInteger)customId withPageName:(NSString *)pageName;
- Code Example
- (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"];
});
}
Set ViewID
After setting viewId, the platform's [Action Analysis] and [Visual Naming] features will prioritize this attribute for classification.
- Example
UIView *view = [UIView new];
[view setTingyunAttributesIdentifier:@"TYIdentifier"];
Set ViewName
After setting ViewName, the platform's [Action Analysis] and [Visual Naming] features will prioritize this attribute for classification.
- Example
UIView *view = [UIView new];
[view setTingyunAttributesName:@"TYViewName"];
Set PageName (Visual Naming)
After setting PageName, the platform's [Action Analysis] and [Visual Naming] features will prioritize this attribute for classification.
- Example
ViewController *vc = [ViewController new];
[vc setTingyunAttributesPageName:@"TYPageName"];
Set Page Scan Interval
You can customize the scan interval for Views in the page. Default is 50ms per scan.
- API
/**
* Set page load scan interval, unit ms, default 50ms
*/
+ (void)setPageScanInterval:(NSInteger)interval;
- Example
[NBSAppAgent setPageScanInterval:100]; // Set scan interval to 100ms
Set Scan Timeout
You can customize the scan timeout for Views in the page. Default is 5s.
- API
/**
* Set page load timeout, unit s, default 5s, maximum 15s
*/
+ (void)setPageLoadTimeoutSec:(NSInteger)sec;
- Example
[NBSAppAgent setPageLoadTimeoutSec:10]; // Set scan timeout to 10 seconds
Set View State
During page load, the SDK scans the status of Views in the current page at intervals to determine if the page has finished loading. You can set the View's isInvalidView and isIgnoredView properties to set the View state. The SDK will prioritize the set state.
- Description
// Set the view as invalid first, after rendering is complete set it as valid. This can solve the problem of inaccurate page load end points caused by placeholder images.
@property (nonatomic, assign) BOOL isInvalidView;
// Ignore this view, it will not be included in page load completion calculation
@property (nonatomic, assign) BOOL isIgnoredView;
- Example
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
view.isIgnoredView = YES; // Set the view as ignored first
view.isInvalidView = YES; // Ignore this view, it will not be included in page load completion calculation
...
// Page load complete
view.isIgnoredView = NO;