Skip to main content

User Experience Data Related Interfaces

Custom Trace Points

Since the TingYun SDK is set to focus on system classes and methods by default, it cannot monitor the performance of 'business code'. The 'Custom Trace Point' interface can be used to complete the 'Page Experience Analysis' and 'Operation Experience Analysis' modules in the [Breakdown Chart], helping developers clearly understand the performance and calling situation of their business code.

  • Related Interface

Note: The 'Custom Trace Point' interface must be called in pairs and should not be used across methods, processes, or in asynchronous loading and recursive calls.

/**
* @param tracerName The name of the current method or a custom name, supporting Chinese, English, numbers, underscores, but cannot contain spaces or other escape characters
*/
NBSAppAgent.beginTracer(String tracerName);
NBSAppAgent.endTracer(String tracerName);
  • Code Example
//Users can add custom Trace points before and after any method after SDK initialization
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}

private void init() {
//Add beginTracer before the method starts
NBSAppAgent.beginTracer(This is the Init method”);
try {
………
} catch (NameNotFoundException e) {
e.printStackTrace();
}
//Add endTracer after the method ends
NBSAppAgent.endTracer(This is the Init method”);
}

Custom Cold Start Time

The TingYun SDK calculates the time from the start of the SDK initialization to the end of the first page load as the 'Cold Start Time' by default. Developers can change the end point of the 'Cold Start Time' calculation according to their application needs.

  • Enable Custom Cold Start Time Control Switch

    • Related Interface

      /**
      * @param isCustom Default is false, set to true to enable custom start time
      */
      NBSAppAgent.isCustomAppStart(boolean isCustom);
    • Code Example

      public class MyApplication extends Application {
      @Override
      public void onCreate() {
      NBSAppAgent.setLicenseKey("AppKey")
      .isCustomAppStart(true)//Call when initializing the SDK to enable custom start time feature
      .start(this.getApplicationContext());
      }
      }
  • Set Custom Cold Start Time End Point

    This interface needs to be used in conjunction with 'isCustomAppStart'. When the 'isCustomAppStart' interface is set to true, the 'setCustomOnResumeEndIns' interface setting takes effect.

    • Related Interface

      /** 
      * @param className Pass the class.getName of the first Activity that starts, should be called after the first Activity's onResume() method ends
      */
      NBSAppAgent.setCustomOnResumeEndIns(String className);
    • Code Example

      public class MyApplication extends Application { 
      @Override public void onCreate() {
      NBSAppAgent.setLicenseKey("AppKey")
      .isCustomAppStart(true)//Call when initializing the SDK to enable custom start time feature
      .start(this.getApplicationContext());
      }
      }

      public class SplashActivity extends Activity {
      //The first Activity that starts
      }

      public class MainActivity extends Activity {
      //The second Activity that starts
      @Override public void onResume() {
      super.onResume();
      NBSAppAgent.setCustomOnResumeEndIns(SplashActivity.class.getName()); //Use the second Activity's onResume() method as the end time of the start
      }
      }

Custom Operation

Define a [Business Operation] through 'Custom Operations' to understand its performance.

  • Related Interface

Note: The 'Custom Operation' interface must be called in pairs, actionName cannot be empty, and supports cross-method and cross-thread calls.

/**
* @param actionName The name of the operation
*/
standbyEventActionStart(String actionName);
standbyEventActionEnd(String actionName);
  • Code Example
private void login() {   
NBSAppAgent.standbyEventActionStart(“login”);

………

NBSAppAgent.standbyEventActionEnd(“login”);
}

Set ViewID

After setting the viewId, the platform's 'Operation Analysis' and 'Visual Naming' features will prioritize using this attribute for classification.

  • Related Interface
/**
* @param view The control to set the ID for
* @param viewId The set control ID, viewId can contain up to 128 characters, supporting English, numbers, underscores
*/
NBSAppAgent.setViewId(View view, String viewId);
  • Code Example
Button button = findViewById(R.id.bt_login);
NBSAppAgent.setViewId(button, "login");

Set ViewName

After setting the ViewName, the platform's 'Operation Analysis' and 'Visual Naming' features will prioritize using this attribute for classification.

  • Related Interface
/**
* @param view The View object
* @param description The ViewName, can contain up to 128 characters
*/
setViewContent(View view, String description)
  • Code Example
Button button = findViewById(R.id.bt_login);
NBSAppAgent.setViewContent(button, "Log in");

Set PageName 'View Alias'

After setting the PageName, the platform's 'Operation Analysis' and 'Visual Naming' features will prioritize using this attribute for classification.

  • Related Interface
/**
* @param activity The Activity object
* @param fragment The Fragment object
* @param alias The PageName, can contain up to 128 characters
*/
setPageName(Activity activity, String alias)
setPageName(Fragment fragment, String alias)
  • Code Example
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uiactivity);
NBSAppAgent.setPageName(this, "Home Page");
}
}

Collect List Operation Item Position

If the project uses the RecyclerView from the androidx package and overrides onBindViewHolder(), the SDK can automatically embed and collect item position data. If the project uses ListView (GridView) or RecyclerView from the support package, it is necessary to manually call the setRowTagForList() method to collect item position data.

  • Related Interface
/**
* Collect for RecyclerView from the support package or ListView (GridView), needs to be embedded in the Adapter
* @param obj The item View
* @param position The position
*/
NBSActionInstrumentation.setRowTagForList(Object obj, int position)
  • Code Example
//  If using RecyclerView from the support package, it is necessary to embed in the Adapter's onBindViewHolder() method
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
...// Other code
NBSActionInstrumentation.setRowTagForList(holder.itemView, position);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List payloads) {
super.onBindViewHolder(holder, position, payloads);
...// Other code
NBSActionInstrumentation.setRowTagForList(holder.itemView, position);
}

// If using ListView or GridView, it is necessary to embed in the Adapter's getView() method
public View getView(int position, View convertView, ViewGroup parent) {
...// 其他代码
NBSActionInstrumentation.setRowTagForList(view, position);
return view;
}

Set View status

**During page loading, the SDK scans the status of the View in the current page at a certain interval to calculate whether the page has been loaded. You can set the status of the View through setViewStatus(), and the SDK will give priority to the set status. **

  • Related interfaces
/**
* @param view View object
* @param NBSViewStatus view status tag, supports the following three states:
* NBSViewStatus.VIEW_STATUS_VALID, valid
* NBSViewStatus.VIEW_STATUS_INVALID, invalid
* NBSViewStatus.VIEW_STATUS_IGNORE), ignore
*/
setViewStatus(View view, NBSViewStatus viewStatus)
  • Code example
TextView tv = new TextView(this);
NBSAppAgent.setViewStatus(tv, NBSViewStatus.VIEW_STATUS_IGNORE);// Set tv to ignore state

Set Page Scan Interval

You can customize the time interval for scanning the View in the page, the default is 50ms.

  • Related interfaces
/**
* @param scanInterval Scan interval, in milliseconds, default 50ms, minimum setting 50ms
*/
setPageScanInterval(int scanInterval)
  • Code example
NBSAppAgent.setPageScanInterval(100);// Scan interval is set to 100ms

Set Scan Timeout

You can customize the timeout of the View in the scan page, default 5s.

  • Related interfaces
/**
* @param timeout timeout, in seconds, default 5 seconds, can be set to 5 - 15 seconds
*/
setPageLoadTimeoutSec(int timeout)
  • Code example
NBSAppAgent.setPageLoadTimeoutSec(10);// Set the scan timeout to 10 seconds

Customize page time

You can set the page end time point by using the custom page time method.

  • Turn on the custom cold start time control switch

  • Related interfaces

/**
* @return Returns the page ID
* @param isCustom Whether the current page uses a custom page end point
*/
NBSAppAgent.customPageLoad(boolean isCustom);
  • Code example
public class MainActivity extends Activity {
String pageId;
@Override
public void onCreate() {
pageId = NBSAppAgent.customPageLoad(true);
}
}
  • Set the end point of the page time consumption

**This interface needs to be used in conjunction with "customPageLoad". When the "customPageLoad" interface is set to true, the "customPageLoadFinish" interface setting takes effect. **

  • Related interfaces
/**
* @param pageId pageId when custom page needs to be called
* @param clasz class of the first Activity or Fragment to be loaded in the current custom page
*/
NBSAppAgent.customPageLoadFinish(String pageId, Class clasz);
  • Code example
public class MainActivity extends Activity {
String pageId;
@Override
public void onCreate() {
pageId = NBSAppAgent.customPageLoad(true);
}

public void loadFinish() {// After the page is loaded, call customPageLoadFinish()
NBSAppAgent.customPageLoadFinish(pageId, MainActivity.class);
}
}