AppsFlyer React Native 插件 - 移动应用分析与归因解决方案

项目标题与描述

AppsFlyer React Native Plugin 是官方提供的React Native桥接库,用于集成AppsFlyer移动归因和分析SDK。该插件支持:

  • 安装归因和转化跟踪
  • 深度链接(Deferred/Direct Deep Linking)
  • 广告收入统计
  • 应用卸载测量
  • 跨应用推广跟踪
  • 用户邀请链接生成

当前版本兼容:

  • Android AppsFlyer SDK v6.17.0
  • iOS AppsFlyer SDK v6.17.0
  • React-Native v0.62.0+

功能特性

核心功能

  • 📊 安装归因:准确追踪应用安装来源
  • 🔗 统一深度链接(UDL):支持新老用户的深度链接跳转
  • :money_bag: 广告收入统计:通过logAdRevenue接口记录广告收益
  • :prohibited: 应用卸载跟踪:支持iOS/Android平台卸载测量
  • 🤝 跨平台推广:通过logCrossPromotionAndOpenStore实现应用交叉推广

高级功能

  • :locked_with_key: GDPR合规:提供setConsentData接口处理用户授权
  • :mobile_phone: Purchase Connector:自动验证应用内购和订阅收入
  • :chart_increasing: 多维度分析:支持自定义事件和用户属性上报
  • :globe_showing_Europe-Africa: 多平台支持:兼容Expo和裸React Native项目

安装指南

基础安装

npm install react-native-appsflyer --save
cd ios && pod install

Expo项目

expo install expo-dev-client react-native-appsflyer

在app.json中添加插件配置:

"plugins": [
  ["react-native-appsflyer", {"shouldUseStrictMode": true}]
]

环境要求

  • iOS 12.0+
  • Android API 21+
  • React Native 0.60+

使用说明

基础初始化

import appsFlyer from 'react-native-appsflyer';

appsFlyer.initSdk({
  devKey: 'YOUR_DEV_KEY',
  appId: 'IOS_APP_ID',
  isDebug: false,
  onDeepLinkListener: true
}, (success) => {
  console.log('SDK初始化成功', success);
}, (error) => {
  console.error('初始化失败', error);
});

深度链接处理

appsFlyer.onDeepLink(res => {
  if (res.deepLinkStatus === 'FOUND') {
    const deepLinkValue = res.data.deep_link_value;
    // 处理深度链接逻辑
  }
});

记录自定义事件

appsFlyer.logEvent('af_purchase', {
  af_content_id: '123',
  af_currency: 'USD',
  af_revenue: '9.99'
});

核心代码

iOS原生模块初始化

// RNAppsFlyer.m
- (void)initSdkWithOptions:(NSDictionary *)options {
  [AppsFlyerLib shared].appsFlyerDevKey = options[@"devKey"];
  [AppsFlyerLib shared].appleAppID = options[@"appId"];
  [AppsFlyerLib shared].isDebug = [options[@"isDebug"] boolValue];
  
  if (!self.isManualStart) {
    [[AppsFlyerLib shared] start];
  }
}

Android深度链接处理

// MainActivity.java
@Override
public void onNewIntent(Intent intent) {
  super.onNewIntent(intent);
  setIntent(intent); // 必须设置以保证深度链接正常处理
}

React Native事件桥接

// index.js
NativeEventEmitter.addListener(
  'onDeepLinking', 
  (res) => {
    if (res.status === 'success') {
      handleDeepLink(res.data);
    }
  }
);

更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
公众号二维码

posted @ 2025-07-02 20:01  qife  阅读(19)  评论(0)    收藏  举报