# React Native埋点SDK

{% hint style="success" %}
React Native 埋点 SDK 仅自动采集设备信息和埋点数据，如果想自动采集用户点击事件或者页面访问事件等， 请集成 ReactNative 无埋点 SDK。
{% endhint %}

{% hint style="success" %}
版本支持：

* App适配最低系统版本：iOS 8及以上、Android 4.2-10
  {% endhint %}

## 1. 集成SDK

{% tabs %}
{% tab title="Android" %}

### 1. 添加跟踪代码

React Native埋点SDK是在Android 原生SDK上的扩展，请参照Android SDK > [埋点SDK](/v3/developer-manual/sdkintegrated/android-sdk/manunl-android-sdk.md)，完成添加跟踪代码配置。

{% hint style="warning" %}
添加跟踪代码时注意将SDK版本号换成RN版本： `RN-track-2.8.20`
{% endhint %}

集成步骤中，只有版本号不同，适配RN与原生混合开发场景。

**代码示例**

```javascript
apply plugin: 'com.android.application'
android {
    defaultConfig {
        resValue("string", "growingio_project_id", "您的项目ID")
        resValue("string", "growingio_url_scheme", "您的URL Scheme")
    }
}
dependencies {
    //GrowingIO RN 埋点 SDK
    implementation 'com.growingio.android:vds-android-agent:RN-track-2.8.22'
}
```

### 2. 重要配置

由于 SDK 需要在`java`代码中进行初始化。

在项目的Application中，添加`GrowingIOPackage`：

```java
public class MainApplication extends Application implements ReactApplication {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(), 
          // 此处加入GrowingIOPackage
          new GrowingIOPackage()
      );
    }
}
```

{% endtab %}

{% tab title="iOS" %}

### 1. 添加跟踪代码

React Native 埋点 SDK 是在 iOS 原生 SDK 上的扩展，请参照iOS SDK > [埋点 SDK集成](/v3/developer-manual/sdkintegrated/ios-sdk/manunl-ios-sdk.md) ，完成添加跟踪代码配置。

### 2. 集成React Native埋点SDK

```
npm install --save https://github.com/growingio/react-native-growingio.git#0.0.7
```

```
react-native link react-native-growingio
```

{% hint style="danger" %}
react-native link react-native-growingio 失败（即发现 Libraries中没有 GrowingIORNPlugin.xcodeproj ，则可手动配置）处理方法：

1. 打开 XCode 工程中, 右键点击 Libraries 文件夹 ➜ Add Files to <...>
2. 去 `node_modules` ➜ `react-native-growingio` ➜ iOS ➜ 选择 `GrowingIORNPlugin.xcodeproj`
3. 在工程`Build Phases` ➜ `Link Binary With Libraries`中添加`libGrowingIORNPlugin.a`
   {% endhint %}

{% hint style="info" %}
如果您使用的是pod方式集成：

请添加以下内容到Podfile中，并在添加之后执&#x884C;**`pod update`**：

pod 'GrowingReactNativeTrackKit', :path => '../node\_modules/react-native-growingio'
{% endhint %}

### 重要配置

与原生混合开发的开发者可详细查看 iOS SDK > 无埋点 SDK > [重要配置](/v3/developer-manual/sdkintegrated/ios-sdk/auto-ios-sdk.md#fu-lu-1-zhong-yao-pei-zhi)文档，如果原生控件使用不多，只需关注如下配置即可：

* **​**[**App Store 提交应用注意事项**](/v3/developer-manual/sdkintegrated/ios-sdk/auto-ios-sdk.md#app-store-ti-jiao-ying-yong-zhu-yi-shi-xiang)\*\*\*\*
  {% endtab %}
  {% endtabs %}

## 2. 自定义数据上传

同[React Native 无埋点SDK 自定义数据上传](/v3/developer-manual/sdkintegrated/otherframe-sdk/rn-autosdk.md#4-zi-ding-yi-shu-ju-shang-chuan)一致。

## 3. 创建应用

{% hint style="danger" %}
**添加代码之后，请先Clean项目，然后再进行编译，并在你的 App 安装了 SDK 后重新启动几次 App，保证行为采集数据自动发送给 GrowingIO，以便顺利完成检测。**
{% endhint %}

在GrowingIO平台的应用创建页面继续完成应用创建的数据检测，检测成功后应用创建成功。

## 4. 验证SDK是否正常采集数据 <a href="#id-5-yan-zheng-sdk-shi-fou-zheng-chang-cai-ji-shu-ju" id="id-5-yan-zheng-sdk-shi-fou-zheng-chang-cai-ji-shu-ju"></a>

了解GrowingIO平台数据采集类型请参考[数据模型](/v3/introduction/datamodel.md)。

GrowingIO为您提供多种验证SDK是否正常采集数据的方式：

方式一：[Mobile Debugger​​](/v3/developer-manual/debugging/mobile-debugger.md)

方式二：在SDK中设置了Debug模式后，在IDE编译器控制台查看数据采集日志。

方式三：[数据校验](/v3/product-manual/data-center/datacheck/app.md#app-duan-shu-ju-xiao-yan)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://growingio.gitbook.io/v3/developer-manual/sdkintegrated/otherframe-sdk/rn-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
