Session Data Related Interfaces
Start a New Session
After calling the interface, a new session can be started.
- Related Interface
/**
* @brief Start a new session and end the old session. By default, it is already called in the SDK initialization method +startWithAppID:
* @note It can only be called after the SDK is initialized. It is generally not recommended to call unless you want to customize the start and end point of a session.
*/
+ (void)startNextSession;
- Code Example
[NBSAppAgent startNextSession];
Get Session ID
After invoking the interface, the current session ID can be obtained.
- Related Interface
/**
* @brief Get the current session ID.
*/
+ (NSString *)getSessionId;
- Code Example
NSString *sessionId = [NBSAppAgent getSessionId];
Set Session Idle Time
The default idle duration for a session is 600 seconds. When the app is idle for longer than this threshold, the SDK will start a new session; the idle duration can be adjusted as needed, and it is recommended to set it before SDK initialization.
- Related Interface
/**
* @brief Set the session idle duration to the default of 600 seconds (10 minutes), meaning that the current session will automatically end after 10 minutes of no activity. When set to 0, it indicates that no idle time judgment will be made, i.e., the session will only end when the program exits or when startNextSession is called. It should be called before SDK initialization, and only the first setting will take effect. Unit: s.
* @param idleTime The minimum setting is 60 seconds.
*/
+ (void)setSessionIdleTime:(NSUInteger)idleTime;
- Code Example
[NBSAppAgent setSessionIdleTime:700];
Custom Events
Custom events can track any event within the app. Developers can call the 'Custom Event Interface' and set the corresponding upload parameters at any position after SDK initialization. For example: when a real user clicks on a certain feature button or triggers a certain feature event, etc.
- Related Interface
/**
* @brief Collect custom events.
* @param name The name of the event, which cannot be empty and is limited to 1024 characters. If exceeded, only the first 1024 characters will be taken.
* @param properties The properties of the event.
*/
+ (void)reportEvent:(NSString *)name properties:(NSDictionary *)properties;
- Code Example
[NBSAppAgent reportEvent:@"login" properties:@{@"account":@"xxx"}];
Screen Recording
Screen recording can be controlled by invoking the interface to start, pause, or resume.
- Related Interface
/**
* Start video recording.
*/
+ (void)startVideoReplay;
/**
* Pause. Only valid when the current state is recording.
*/
+ (void)pauseVideoReplay;
/**
* Resume. Only valid when the current state is pause.
*/
+ (void)resumeVideoReplay;
- Code Example
The following example starts video recording when entering the home page, pauses video recording when submitting an order, and resumes video recording when leaving the order page.
// Entering the home page
- (void)initHomeViews
{
...
[NBSAppAgent startVideoReplay];
}
// Submitting an order
- (void)submitOrders
{
...
[NBSAppAgent pauseVideoReplay];
}
// Leaving the order page
- (void)dismissOrderPage
{
...
[NBSAppAgent resumeVideoReplay];
}
Sensitive Information Masking
Sensitive information can be masked by invoking the sensitive information masking interface from a finer granularity 'accessibilityIdentifier, page, class name, region'.
- Related Interface
/**
* @brief Mask sensitive information.
* @param view The view that needs to be masked.
*/
+(void)maskSensitiveView:(UIView *)view;
/**
* @brief Unmask sensitive information.
* @param view The view to unmask.
*/
+(void)unmaskSensitiveView:(UIView *)view;
/**
* @brief Mask sensitive information.
* @param region The coordinates relative to the main window.
*/
+(void)maskSensitiveRegion:(CGRect)region;
/**
* @brief Unmask sensitive information.
* @param region The coordinates relative to the main window.
*/
+(void)unmaskSensitiveRegion:(CGRect)region;
/**
* @brief Mask sensitive information.
* @param viewId The accessibilityIdentifier of the view that needs to be masked, which is effective only if set in advance.
*/
+ (void)maskViewId:(NSString*)viewId;
/**
* @brief Mask sensitive information.
* @param screens An array of the pages that need to be masked, where the elements are the class names of the viewController.
*/
+ (void)maskScreens:(NSArray <NSString *>*)screens;
/**
* @brief Mask sensitive information.
* @param classes An array of the classes that need to be masked, where the elements are the class names of the viewController or view.
*/
+ (void)maskClasses:(NSArray <NSString *>*)classes;
- Code Example
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[NBSAppAgent maskViewId:btn.accessibilityIdentifier]; // Mask the corresponding viewId
[NBSAppAgent maskSensitiveView:btn]; // Mask btn
CGRect rect = CGRectMake(100, 100, 200, 200);
[NBSAppAgent maskSensitiveRegion:rect]; // Mask the region of rect
[NBSAppAgent unmaskSensitiveView:btn]; // Unmask btn
[NBSAppAgent unmaskSensitiveRegion:rect]; // Unmask the region of rect
[NBSAppAgent maskScreens:@[@"WebviewController",@"ViewController"]]; // Mask pages
[NBSAppAgent maskClasses:@[@"SensitiveView"]]; // Mask class