You need to enable JavaScript to run this app.
增长分析 DataFinder

增长分析 DataFinder

复制全文
React Native SDK
React Native SDK API 说明
复制全文
React Native SDK API 说明

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

主要API说明

setUserUniqueId

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

  • 定义:setUserUniqueId(userUniqueID: string 或 null): void

  • 参数

    参数名

    类型

    必填

    说明

    userUniqueID

    string 或 null

    是,可null

    为null时,表示退出用户态

  • 示例

    • 登录用户态
    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    // 登录时设置您账号体系的ID, 并保证其唯一性
    RangersAppLogModule.setUserUniqueId('{{USER_UNIQUE_ID}}');
    
    • 退出用户态
    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    // 登出时设置uuid为null
    RangersAppLogModule.setUserUniqueId(null);
    

onEventV3

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

  • 定义:onEventV3(eventName: string, params?: Record<string, string 或 number 或 boolean>): void

  • 参数

    参数名

    类型

    必填

    说明

    eventName

    string

    事件名称,不能空字符串

    params

    Record<string, string 或 number 或 boolean>

    事件参数

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

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    // 示例:上报事件event_name,该事件不包含属性
    RangersAppLogModule.onEventV3("event_name");
    
    // 示例:上报事件event_name,该事件包含两个属性
    // 一个string类型的属性,属性名为key_string,属性值为value_string
    // 一个int类型的属性,属性名为key_int,属性值为10
    RangersAppLogModule.onEventV3("event_name", {
        "key_string": "value_string",
        "key_int": 10
    });
    

setHeaderInfo

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

  • 定义:setHeaderInfo(customHeader: Record<string, string 或 number 或 boolean>): void

  • 参数

    参数名

    类型

    必填

    说明

    customHeader

    Record<string, string 或 number 或 boolean>

    自定义的公共属性。

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    // 示例:设置自定义的公共属性,属性名为key_public,属性值为value_public
    RangersAppLogModule.setHeaderInfo({
        "key_public": "value_public"
    });
    

removeHeaderInfo

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

  • 定义:removeHeaderInfo(key: string): void

  • 参数

    参数名

    类型

    必填

    说明

    key

    string

    自定义上报key(自定义公共属性名)

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    // 示例:移除自定义的公共属性,属性名为key_public
    RangersAppLogModule.removeHeaderInfo("key_public");
    

getDeviceId

  • 作用:获取火山引擎平台自动生成的device_id。

  • 定义:getDeviceId(): Promise

  • 返回值

    类型

    说明

    Promise

    异步返回火山引擎平台自动生成的device id。

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    // 示例:获取did
    let didPromise = RangersAppLogModule.getDeviceID();
    didPromise.then((deviceID) => {
        console.log(deviceID);
    });
    

AB实验功能API说明

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

开启AB实验

注意

需要在原生端代码的初始化时开启AB相应设置。

getABTestConfigValueForKey

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

  • 定义:getABTestConfigValueForKey(key: string, defaultValue: any): Promise

  • 参数

    参数名

    类型

    必填

    说明

    key

    string

    AB实验配置的实验参数的key

    defaultValue

    any

    兜底的A/B实验的实验参数默认值。如果没有开启A/B实验,或者A/B实验对应的实验参数未配置参数取值,则通过此方法返回该默认值。

  • 返回值

    类型

    说明

    Promise

    异步返回AB实验配置的值

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.getABTestConfigValueForKey('ab_test_key', 'default_value').then((value) => {
        console.log(value);
    });
    

getAbSdkVersion

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

  • 定义:getAbSdkVersion(): Promise

  • 返回值

    类型

    说明

    Promise

    异步返回已曝光的vids,值类似于"1234,2345,1111"

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.getAbSdkVersion().then((vids) => {
        // vids值如"1234,2345,1111"
        console.log(vids);
    });
    

getAllAbTestConfigs

  • 作用:获取AB实验的所有配置项(实验VID、实验参数等配置项),在初始化之后设置才能调用。

  • 定义:getAllAbTestConfigs(): Promise<Record<string, any>>

  • 返回值

    类型

    说明

    Promise<Record<string, any>>

    异步返回AB实验所有配置项。

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.getAllAbTestConfigs().then((result) => {
        console.log(result);
    });
    

用户属性功能API说明

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

profileSet

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

  • 定义:profileSet(profileDict: Record<string, string 或 number 或 string[]>): void

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Record<string, string 或 number 或 string[]>

    设置的用户属性,属性取值为参数字典格式,参数字典的值只能是以下类型:字符串、整型、浮点型、字符串数组

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.profileSet({"key": "value"});
    

profileSetOnce

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

  • 定义:profileSetOnce(profileDict: Record<string, string 或 number 或 string[]>): void

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Record<string, string 或 number 或 string[]>

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

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.profileSetOnce({"key_once": "value_once"});
    

profileIncrement

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

  • 定义:profileIncrement(profileDict: Record<string, number>): void

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Record<string, number>

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

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.profileSetOnce({"key": 1});
    

profileAppend

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

  • 定义:profileAppend(profileDict: Record<string, string 或 string[]>): void

  • 参数

    参数名

    类型

    必填

    说明

    profileDict

    Record<string, string 或 string[]>

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

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.profileAppend({"key": "value_append"});
    

profileUnset

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

  • 定义:profileUnset(key: string): void

  • 参数

    参数名

    类型

    必填

    说明

    key

    string

    要unset的profile的名称

  • 示例

    import { NativeModules } from 'react-native';
    const { RangersAppLogModule } = NativeModules;
    
    RangersAppLogModule.profileUnset("key");
    
最近更新时间:2025.07.01 20:10:12
这个页面对您有帮助吗?
有用
有用
无用
无用