Custom Tag Usage¶
Build Configuration Method¶
-
Create multiple
productFlavorsinbuild.gradleto differentiate tags. -
Add the corresponding
BuildConfigconstant in theRUMconfiguration.
Runtime File Read/Write Method¶
-
Store data in file-based storage, such as
SharedPreferences, configure theSDKto use it, and add code at the configuration location to retrieve the tag data.SharedPreferences sp = context.getSharedPreferences(SP_STORE_DATA, MODE_PRIVATE); String customDynamicValue = sp.getString(CUSTOM_DYNAMIC_TAG, "not set"); // Configure RUM FTSdk.initRUMWithConfig( new FTRUMConfig().addGlobalContext(CUSTOM_DYNAMIC_TAG, customDynamicValue) //… Add other configuration ); -
Add a method for modifying the file data when needed.
-
Finally, restart the app. For details, see SDK Demo
Add at SDK Runtime¶
After the SDK is initialized, use FTSdk.appendGlobalContext(globalContext), FTSdk.appendRUMGlobalContext(globalContext), and FTSdk.appendLogGlobalContext(globalContext) to dynamically add tags. The settings take effect immediately after they are configured. After that, data subsequently reported by RUM or Log will automatically carry the corresponding tags.
This usage is suitable for scenarios where data is obtained with a delay, for example, when tag data is only available after login, an API request, or local asynchronous initialization.
Warning
Avoid using the same key as globalContext in the SDK initialization configuration or as an SDK built-in field; when the names are the same, static tags in the initialization configuration take precedence over dynamically added tags.
Usage¶
/**
* Dynamically set global tag
* @param globalContext
*/
public static void appendGlobalContext(HashMap<String,Object> globalContext)
/**
* Dynamically set RUM global tag
* @param globalContext
*/
public static void appendRUMGlobalContext(HashMap<String,Object> globalContext)
/**
* Dynamically set log global tag
* @param globalContext
*/
public static void appendLogGlobalContext(HashMap<String,Object> globalContext)
/**
* Dynamically set global tag
* @param globalContext
*/
fun appendGlobalContext(globalContext: HashMap<String, Any>)
/**
* Dynamically set RUM global tag
* @param globalContext
*/
fun appendRUMGlobalContext(globalContext: HashMap<String, Any>)
/**
* Dynamically set log global tag
* @param globalContext
*/
fun appendLogGlobalContext(globalContext: HashMap<String, Any>)
//SDK initialization pseudocode: set tags after obtaining parameters from the network
FTSdk.init()
getInfoFromNet(info){
HashMap<String, Object> globalContext = new HashMap<>();
globalContext.put("delay_key", info.value);
FTSdk.appendGlobalContext(globalContext)
}
Code Example¶
HashMap<String, Object> globalContext = new HashMap<>();
globalContext.put("global_key", "global_value");
FTSdk.appendGlobalContext(globalContext);
HashMap<String, Object> rumGlobalContext = new HashMap<>();
rumGlobalContext.put("rum_key", "rum_value");
FTSdk.appendRUMGlobalContext(rumGlobalContext);
HashMap<String, Object> logGlobalContext = new HashMap<>();
logGlobalContext.put("log_key", "log_value");
FTSdk.appendLogGlobalContext(logGlobalContext);
val globalContext = hashMapOf<String, Any>(
"global_key" to "global_value"
)
FTSdk.appendGlobalContext(globalContext)
val rumGlobalContext = hashMapOf<String, Any>(
"rum_key" to "rum_value"
)
FTSdk.appendRUMGlobalContext(rumGlobalContext)
val logGlobalContext = hashMapOf<String, Any>(
"log_key" to "log_value"
)
FTSdk.appendLogGlobalContext(logGlobalContext)