Custom Tag Usage¶
Compilation Configuration Method¶
You can create multiple Configurations and use preprocessor directives to set different tag values.
- Create multiple Configurations
- Set preprocessor macros to distinguish different Configurations
- Use preprocessor directives
//Target -> Build Settings -> GCC_PREPROCESSOR_DEFINITIONS to configure preprocessor definitions
#if PRE
#define Track_id @"0000000001"
#define STATIC_TAG @"preprod"
#elif DEVELOP
#define Track_id @"0000000002"
#define STATIC_TAG @"common"
#else
#define Track_id @"0000000003"
#define STATIC_TAG @"prod"
#endif
FTRumConfig *rumConfig = [[FTRumConfig alloc]init];
rumConfig.globalContext = @{@"track_id":Track_id,@"static_tag":STATIC_TAG};
... //Other configuration operations
[[FTMobileAgent sharedInstance] startRumWithConfigOptions:rumConfig];
You can also refer to the Multi-environment Configuration Parameters method for configuration.
Runtime Read/Write File Method¶
Since the globalContext set after RUM starts will not take effect, users can save it locally themselves and set it to take effect the next time the application starts.
- Save locally by storing in a file, such as
NSUserDefaults. When configuring the SDK, add code to retrieve tag data in the configuration section.
NSString *dynamicTag = [[NSUserDefaults standardUserDefaults] valueForKey:@"DYNAMIC_TAG"]?:@"NO_VALUE";
FTRumConfig *rumConfig = [[FTRumConfig alloc]init];
rumConfig.globalContext = @{@"dynamic_tag":dynamicTag};
... //Other configuration operations
[[FTMobileAgent sharedInstance] startRumWithConfigOptions:rumConfig];
- Add a method to change the file data anywhere.
- Finally, restart the application for the changes to take effect.
Adding at SDK Runtime¶
After the SDK is initialized, you can use [FTMobileAgent appendGlobalContext:globalContext], [FTMobileAgent appendRUMGlobalContext:globalContext], [FTMobileAgent appendLogGlobalContext:globalContext] to dynamically add tags. The settings will take effect immediately. Subsequently, data reported by RUM or Log will automatically include the corresponding tags.
This usage is suitable for scenarios where data acquisition is delayed, such as when tag data can only be obtained after login, API requests, or local asynchronous initialization.
Usage¶
/// Add SDK global tags, effective for RUM, Log data
/// - Parameter context: Custom data
+ (void)appendGlobalContext:(NSDictionary <NSString*,id>*)context;
/// Add RUM custom tags, effective for RUM data
/// - Parameter context: Custom data
+ (void)appendRUMGlobalContext:(NSDictionary <NSString*,id>*)context;
/// Add Log global tags, effective for Log data
/// - Parameter context: Custom data
+ (void)appendLogGlobalContext:(NSDictionary <NSString*,id>*)context;
/// Add SDK global tags, effective for RUM, Log data
/// - Parameter context: Custom data
open class func appendGlobalContext(_ context: [String : Any])
/// Add RUM custom tags, effective for RUM data
/// - Parameter context: Custom data
open class func appendRUMGlobalContext(_ context: [String : Any])
/// Add Log global tags, effective for Log data
/// - Parameter context: Custom data
open class func appendLogGlobalContext(_ context: [String : Any])

