User Experience Data
Custom Trace Instrumentation
Since TingYun_SDK by default focuses on system classes and methods and cannot monitor the time consumption of "business code", you can use the "custom instrumentation" interface to supplement the [Breakdown Chart] in the "Page Experience Analysis" and "Operation Experience Analysis" modules. This helps developers clearly understand the time consumption and call situation of their business code.
- Related interface
Note: The "custom trace instrumentation" interface must be called in pairs. Do not use it across methods, across processes, or in asynchronous loading and recursive calls.
/**
* @param tracerName The name of the current method or a custom name. Supports Chinese, English, numbers, and underscores, but cannot contain spaces or other escape characters
*/
NBSAppAgent.beginTracer(String tracerName);
NBSAppAgent.endTracer(String tracerName);
- Code example
// You can add custom Trace 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 Duration
TingYun_SDK by default calculates the time from SDK initialization start to the end of the first page load as the "cold start duration". Developers can change the end point of the "cold start duration" calculation according to their application needs.
-
Enable custom cold start duration control switch
-
Related interface
/**
* @param isCustom Defaults to false. Set to true to enable custom start duration
*/
NBSAppAgent.isCustomAppStart(boolean isCustom); -
Code example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.isCustomAppStart(true) // Enable custom start time during SDK initialization
.start(this.getApplicationContext());
}
}
-
-
Set the end point of custom cold start duration
This interface must be used with "isCustomAppStart". When "isCustomAppStart" is set to true, the "setCustomOnResumeEndIns" interface takes effect.
-
Related interface
/**
* @param className Pass in the class.getName of the first Activity to start. Call after the onResume() of the first Activity ends
*/
NBSAppAgent.setCustomOnResumeEndIns(String className);-
Code example
public class MyApplication extends Application {
@Override public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.isCustomAppStart(true) // Enable custom start time during SDK initialization
.start(this.getApplicationContext());
}
}
public class SplashActivity extends Activity {
// The first Activity to start
}
public class MainActivity extends Activity {
// The second Activity to start
@Override public void onResume() {
super.onResume();
NBSAppAgent.setCustomOnResumeEndIns(SplashActivity.class.getName()); // Use the onResume() method of the second Activity as the end time of the start
}
}
-
Custom Operation
Define a [business operation] using "custom operation" to understand its performance.
- Related interface
Note: The "custom operation" interface must be called in pairs. actionName cannot be empty. Supports cross-method and cross-thread calls.
/**
* @param actionName Operation name
*/
standbyEventActionStart(String actionName);
standbyEventActionEnd(String actionName);
- Code example
private void login() {
NBSAppAgent.standbyEventActionStart("login");
// ...
NBSAppAgent.standbyEventActionEnd("login");
}
Set ViewID
After setting viewId, the platform's "Operation Analysis" and "Visual Naming" features will prioritize this property for classification.
- Related interface
/**
* @param view The control to set the ID for
* @param viewId The control ID to set, up to 128 characters, supports English, numbers, and underscores
*/
NBSAppAgent.setViewId(View view, String viewId);
- Code example
Button button = findViewById(R.id.bt_login);
NBSAppAgent.setViewId(button, "login");
Set ViewName
After setting ViewName, the platform's "Operation Analysis" and "Visual Naming" features will prioritize this property for classification.
- Related interface
/**
* @param view View object
* @param description ViewName, up to 128 characters
*/
setViewContent(View view, String description)
- Code example
Button button = findViewById(R.id.bt_login);
NBSAppAgent.setViewContent(button, "Login");
Set PageName (View Alias)
After setting PageName, the platform's "Operation Analysis" and "Visual Naming" features will prioritize this property for classification.
- Related interface
/**
* @param activity Activity object
* @param fragment Fragment object
* @param alias PageName, 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 Item Position
If your project uses the androidx package's RecyclerView and overrides onBindViewHolder(), the SDK can automatically instrument and collect item position data. If your project uses ListView (GridView) or the support package's RecyclerView, you need to manually call setRowTagForList() to collect item position data.
- Related interface
/**
* For support package RecyclerView or ListView (GridView), you need to instrument in the Adapter
* @param obj item View
* @param position Position
*/
NBSActionInstrumentation.setRowTagForList(Object obj, int position)
- Code example
// If using the support package's RecyclerView, instrument at the end of 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, instrument at the end of the Adapter's getView() method
public View getView(int position, View convertView, ViewGroup parent) {
... // other code
NBSActionInstrumentation.setRowTagForList(view, position);
return view;
}
Set View Status
During page loading, the SDK scans the status of Views on the current page at intervals to determine if the page has finished loading. You can use setViewStatus() to set the status of a View, and the SDK will prioritize the set status.
- Related interface
/**
* @param view View object
* @param NBSViewStatus View status flag, 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 status
Set Scan Interval
You can customize the scan interval for Views on the page. The default is 50ms per scan.
- Related interface
/**
* @param scanInterval Scan interval in milliseconds. Default is 50ms. Minimum is 50ms
*/
setPageScanInterval(int scanInterval)
- Code example
NBSAppAgent.setPageScanInterval(100); // Set scan interval to 100ms
Set Scan Timeout
You can customize the scan timeout for Views on the page. The default is 5 seconds.
- Related interface
/**
* @param timeout Timeout in seconds. Default is 5 seconds. Can be set to 5 - 15 seconds
*/
setPageLoadTimeoutSec(int timeout)
- Code example
NBSAppAgent.setPageLoadTimeoutSec(10); // Set scan timeout to 10 seconds
Custom Page Load Duration
You can set the end point of the page load duration using the custom page load method.
-
Enable custom cold start duration control switch
-
Related interface
/**
* @return Returns the page ID
* @param isCustom Whether the current page uses a custom 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 page load duration
This interface must be used with "customPageLoad". When "customPageLoad" is set to true, the "customPageLoadFinish" interface takes effect.
-
Related interface
/**
* @param pageId The pageId returned when calling customPageLoad
* @param clasz The first loaded Activity or Fragment class of 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() { // Call customPageLoadFinish() after the page has finished loading
NBSAppAgent.customPageLoadFinish(pageId, MainActivity.class);
}
}
-