Skip to main content

Session

Start New Session

After calling the API, you can start a new session.

  • Related API
/**
* @brief Start a new session and end the old session, default is already called in SDK initialization method +startWithAppID:
* @note Can only be called after SDK initialization, generally not recommended unless you want to customize a session's start and end points
*/
+ (void)startNextSession;
  • Code Example
[NBSAppAgent startNextSession];

Get Session ID

After calling the API, get the current session ID.

  • Related API
/**
* @brief Get current sessionId
*/
+ (NSString *)getSessionId;
  • Code Example
NSString *sessionId = [NBSAppAgent getSessionId];

Set Session Idle Time

Session default idle duration is 600 seconds. When App idle duration exceeds this threshold, SDK will start a new session. You can adjust the idle duration as needed. It's recommended to set before SDK initialization.

  • Related API
/**
* @brief Set session idle duration, default 600 seconds (10 minutes), meaning current session automatically ends after 10 minutes of no operation. When set to 0, it means no idle time judgment, i.e., session only ends when program exits or startNextSession is called. Should be called before SDK initialization, only first setting takes effect. Unit: s
* @param idleTime Minimum can be set to 60 seconds
*/
+ (void)setSessionIdleTime:(NSUInteger)idleTime;
  • Code Example
[NBSAppAgent setSessionIdleTime:700];

Custom Events

Custom events can count any events in the App. Developers can call "Custom Event API and set corresponding upload parameters" at any location after SDK initialization. For example: when real users click a function button or trigger a function event during operation, etc.

  • Related API
/**
* @brief Collect custom events
* @param name Event name, cannot be empty, length limit 1024 characters, truncate first 1024 characters if exceeded
* @param properties Event properties
*/
+ (void)reportEvent:(NSString *)name properties:(NSDictionary *)properties;
  • Code Example
[NBSAppAgent reportEvent:@"login" properties:@{@"account":@"xxx"}];

Screen Recording

You can control screen recording start, pause, and resume by calling APIs.

  • Related API
/**
* Start video recording
*/
+ (void)startVideoReplay;

/**
* Pause, only effective when current status is recording
*/
+ (void)pauseVideoReplay;

/**
* Resume, only effective when current status is pause
*/
+ (void)resumeVideoReplay;
  • Code Example

The following example shows starting video recording when entering homepage, pausing video recording when submitting order, and resuming video recording when leaving order page.

// Enter homepage
- (void)initHomeViews
{
...
[NBSAppAgent startVideoReplay];
}

// Submit order
- (void)submitOrders
{
...
[NBSAppAgent pauseVideoReplay];
}

// Leave order page
- (void)dismissOrderPage
{
...
[NBSAppAgent resumeVideoReplay];
}

Sensitive Information Masking

You can call sensitive information masking APIs to mask sensitive information from finer granularity "accessibilityIdentifier, page, class name, region".

  • Related API
/**
* @brief Mask sensitive information.
* @param view View that needs to be masked.
*/
+(void)maskSensitiveView:(UIView *)view;

/**
* @brief Unmask sensitive information.
* @param view View to unmask.
*/
+(void)unmaskSensitiveView:(UIView *)view;

/**
* @brief Mask sensitive information.
* @param region Coordinates relative to main window.
*/
+(void)maskSensitiveRegion:(CGRect)region;

/**
* @brief Unmask sensitive information.
* @param region Coordinates relative to main window.
*/
+(void)unmaskSensitiveRegion:(CGRect)region;
/**
* @brief Mask sensitive information.
* @param viewId accessibilityIdentifier of the view that needs to be masked, needs to be set in advance to be effective.
*/
+ (void)maskViewId:(NSString*)viewId;

/**
* @brief Mask sensitive information.
* @param screens Array of pages that need to be masked, elements are viewController class names
*/
+ (void)maskScreens:(NSArray <NSString *>*)screens;

/**
* @brief Mask sensitive information.
* @param classes Array that needs to be masked, elements are viewController or view class names
*/
+ (void)maskClasses:(NSArray <NSString *>*)classes;
  • Code Example
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[NBSAppAgent maskViewId:btn.accessibilityIdentifier]; // Mask corresponding viewId

[NBSAppAgent maskSensitiveView:btn]; // Mask btn

CGRect rect = CGRectMake(100, 100, 200, 200);
[NBSAppAgent maskSensitiveRegion:rect]; // Mask rect region

[NBSAppAgent unmaskSensitiveView:btn]; // Unmask btn
[NBSAppAgent unmaskSensitiveRegion:rect]; // Unmask rect region

[NBSAppAgent maskScreens:@[@"WebviewController",@"ViewController"]]; // Mask pages

[NBSAppAgent maskClasses:@[@"SensitiveView"]]; // Mask classes