You need to enable JavaScript to run this app.
导航
Flutter SDK API 说明
最近更新时间:2025.07.14 15:51:47首次发布时间:2025.07.14 15:51:47
我的收藏
有用
有用
无用
无用

本文为您介绍Flutter端为您提供的一系列API,您可以结合埋点规划调用对应API进行埋点。

主要API说明

initRangersAppLog

  • 作用:初始化SDK。

  • 定义:static void initRangersAppLog(String appid, String channel, bool enableAb, bool enableEncrypt, bool enableLog, String? host)

  • 参数

    参数名

    类型

    必填

    说明

    appid

    String

    应用appid

    channel

    String

    App下载/分发渠道,例如iOS一般是'App Store'

    enableAb

    bool

    AB实验开关

    enableEncrypt

    bool

    加密开关

    enableLog

    bool

    原生端日志开关

    host

    String

    上报地址

  • 示例

    String appId = '{{APPID}}';
    String channel = 'App Store';
    bool enableAB = false;
    bool enableEncrypt = true;
    bool enableDebugLog = false;
    String? host = 'https://gator.volces.com';
    RangersApplogFlutterPlugin.initRangersAppLog(appId, channel, enableAB, enableEncrypt, enableDebugLog, host);
    

addInitParams

  • 作用:支持添加额外的一些初始化设置项,目前支持regionautoStartservice_vendor三个设置项。该方法需要在initRangersAppLog前执行。

  • 定义:static void addInitParams(Map<String, dynamic> params)

  • 参数

    参数名

    类型

    必填

    说明

    params

    Map<String, dynamic>

    目前支持regionautoStartservice_vendor三个设置项

    // 示例
    Map<String, dynamic> initParams = {
      'region': 'cn',
      'autoStart': true,
      'service_vendor': 'private',
    };
    
  • 示例

    // 设置region、autoStart
    Map<String, dynamic> initParams = {
      'region': 'cn', //对应客户端上报的app_region字段,用于需要自定义app_region的情况
      'autoStart': true, //false-初始化不start,true-初始化即start,默认为true(用于需要将init和start分开的场景)
    };
    RangersApplogFlutterPlugin.addInitParams(initParams);
    // 需要在下面这个initRangersAppLog前执行addInitParams
    RangersApplogFlutterPlugin.initRangersAppLog(/*appId, channel, enableAB, enableEncrypt, enableDebugLog, host*/);
    
    // 设置service_vendor,在不同环境下需要设置不同的service_vendor值
    Map<String, dynamic> initParams = RangersApplogFlutterPlugin.addInitParams({
        // 固定值 private
        'service_vendor': 'private',
    });
    RangersApplogFlutterPlugin.addInitParams(initParams);
    // 需要在下面这个initRangersAppLog前执行addInitParams
    RangersApplogFlutterPlugin.initRangersAppLog(/*appId, channel, enableAB, enableEncrypt, enableDebugLog, host*/);
    

start

  • 作用:当通过addInitParams设置autoStart为false的情况下,需要主动调用start方法告知SDK开始上报事件。
  • 定义:static void start()
  • 示例
    // ...
    Map<String, dynamic> initParams = {
      'autoStart': false,
    };
    RangersApplogFlutterPlugin.addInitParams(initParams);
    RangersApplogFlutterPlugin.initRangersAppLog(appId, channel, enableAB, enableEncrypt, enableDebugLog, host);
    
    // 之后再start
    RangersApplogFlutterPlugin.start();
    

setUserUniqueId

  • 作用:设置用户登录态。在初始化之后设置user_unique_id值,SDK会保存,因此只需要发生变化的时候设置。

  • 定义:static void setUserUniqueId(String? userUniqueID)

  • 参数

    参数名

    类型

    必填

    说明

    userUniqueID

    String

    是,可null

    为null时,表示退出用户态

  • 示例

    • 登录用户态
    RangersApplogFlutterPlugin.setUserUniqueId("{{USER_UNIQUE_ID}}")
    
    • 退出用户态
    RangersApplogFlutterPlugin.setUserUniqueId(null)
    

onEventV3

  • 作用:上报事件,在初始化之后设置才能调用。

  • 定义:static void onEventV3(String eventName, Map<String, dynamic>? params)

  • 参数

    参数名

    类型

    必填

    说明

    eventName

    String

    事件名称,不能空字符串

    params

    Map<String, dynamic>

    事件参数

    {
        "key_string": "value_string",
        "key_int": 10
    }
    
  • 示例

    // 示例:上报事件event_name,该事件不包含属性
    RangersApplogFlutterPlugin.onEventV3("event_name");
    
    // 示例:上报事件event_name,该事件包含两个属性
    // 一个string类型的属性,属性名为key_string,属性值为value_string
    // 一个int类型的属性,属性名为key_int,属性值为10
    RangersApplogFlutterPlugin.onEventV3("event_name", {
        "key_string": "value_string",
        "key_int": 10
    });
    

setHeaderInfo

  • 作用:设置自定义的公共属性。

  • 定义:static void setHeaderInfo(Map<String, dynamic> customHeader)

  • 参数

    参数名

    类型

    必填

    说明

    customHeader

    Map<String, dynamic>

    自定义上报value,一般需要传NSString或者数字,或者nil

  • 示例

    // 设置自定义的公共属性,属性名为key_public,属性值为value_public
    RangersApplogFlutterPlugin.setHeaderInfo({
        "key_public": "value_public"
    });
    

removeHeaderInfo

  • 作用:移除自定义的公共属性。

  • 定义:static void removeHeaderInfo(String key)

  • 参数

    参数名

    类型

    必填

    说明

    key

    String

    自定义上报key

  • 示例

    // 示例:移除属性名为key_public的公共属性
    RangersApplogFlutterPlugin.removeHeaderInfo("key_public");
    

getDeviceId

  • 作用:获取平台ID。

  • 定义:static Future<String?> getDeviceId() async

  • 返回值

    类型

    说明

    Future<String?>

    该方法是异步方法,会返回Future。

  • 示例

    // 请在初始化完成的3秒后开始获取,否则可能返回为空
    String did = await RangersApplogFlutterPlugin.getDeviceId();
    

AB实验功能API说明

SDK提供AB实验能力,并提供了一系列的方法:getAbSdkVersion、getAllAbTestConfig、getABTestConfigValueForKey。

开启AB实验

//开启AB实验
bool enableAB = true;
RangersApplogFlutterPlugin.initRangersAppLog(appId, channel, enableAB, enableEncrypt, enableDebugLog, host);

SDK在初始化后会向分流服务发送一个分流请求(request),在获取到分流服务的响应(response)后,客户端开发可以根据分流的结果参数完成代码分支。

注意

  • 此步骤的前置条件:已经根据实验的需求方创建好了实验及相关的参数,具体见创建实验
  • 每次调用getABTestConfigValueForKey时,会默认上报一条曝光事件 abtest_exposure

getABTestConfigValueForKey

  • 作用:获取AB实验的配置值,在初始化之后设置才能调用。

  • 定义:static Future getABTestConfigValueForKey(String key, dynamic defaultValue) async

  • 参数

    参数名

    类型

    必填

    说明

    key

    String

    AB实验配置的key

    defaultValue

    dynamic

    默认值,如果没有配置,或者未开启AB实验则返回默认值

  • 返回值

    类型

    说明

    Future

    该方法是异步方法,会返回Future。

  • 示例

    String value = await RangersApplogFlutterPlugin.getABTestConfigValueForKey('ab_test_key');
    

getAbSdkVersion

  • 作用:获取已曝光的AB实验配置的vids,在初始化之后设置才能调用。

  • 定义:static Future<String?> getAbSdkVersion() async

  • 返回值

    类型

    说明

    Future<String?>

    该方法是异步方法,会返回Future。

  • 示例

    String value = await RangersApplogFlutterPlugin.getAbSdkVersion();
    

getAllAbTestConfig

  • 作用:获取AB实验的所有配置项,在初始化之后设置才能调用。

  • 定义:static Future<Map<dynamic, dynamic>?> getAllAbTestConfig() async

  • 返回值

    类型

    说明

    Future<Map<dynamic, dynamic>?>

    该方法是异步方法,会返回Future。

  • 示例

    Map<dynamic, dynamic> configs = await RangersApplogFlutterPlugin.getAllAbTestConfig();
    

用户属性功能API说明

提供设置用户属性能力,并提供了一系列的方法:profileSet、profileSetOnce、profileUnset、profileIncrement、profileAppend。

profileSet

  • 作用:设置用户属性,存在则覆盖,不存在则创建。

  • 定义:static void profileSet(Map<String, dynamic> profileDict)

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Map<String, dynamic>

    参数字典的值只能是以下类型:字符串、整型、浮点型、字符串数组

  • 示例

    RangersApplogFlutterPlugin.profileSet({"key": "value"});
    

profileSetOnce

  • 作用:设置用户属性,存在则不设置,不存在则创建,适合首次相关的用户属性,比如首次访问时间等。与profileSet接口不同的是:若某profile已成功通过profileSetOnce接口设置,那么对该profile再次调用profileSetOnce接口无效。

  • 定义:static void profileSetOnce(Map<String, dynamic> profileDict)

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Map<String, dynamic>

    参数字典的值只能是以下类型:字符串、整型、浮点型、字符串数组

  • 示例

    RangersApplogFlutterPlugin.profileSetOnce({"key_once": "value_once"});
    

profileIncrement

  • 作用:设置数值类型的属性,可进行累加。

  • 定义:static void profileIncrement(Map<String, dynamic> profileDict)

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Map<String, dynamic>

    只能自增整数(可以为负整数)。如果传入浮点数,SDK将忽略。

  • 示例

    RangersApplogFlutterPlugin.profileIncrement({"key": 1});
    

profileAppend

  • 作用:设置List类型的用户属性,可持续向List内添加。

  • 定义:static void profileAppend(Map<String, dynamic> profileDict)

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Map<String, dynamic>

    参数字典的值只能为字符串或者字符串数组。

  • 示例

    RangersApplogFlutterPlugin.profileAppend({"key": "value_append"});
    

profileUnset

  • 作用:删除用户的属性。

  • 定义:static void profileUnset(String key)

  • 参数

    参数名

    类型

    必填

    说明

    key

    String

    要unset的profile的名称

  • 示例

    RangersApplogFlutterPlugin.profileUnset("key");