写点什么

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

作者:qife
  • 2025-07-02
    福建
  • 本文字数:1213 字

    阅读完需:约 4 分钟

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):支持新老用户的深度链接跳转

  • 💰 广告收入统计:通过logAdRevenue接口记录广告收益

  • 🚫 应用卸载跟踪:支持 iOS/Android 平台卸载测量

  • 🤝 跨平台推广:通过logCrossPromotionAndOpenStore实现应用交叉推广

高级功能

  • 🔐 GDPR 合规:提供setConsentData接口处理用户授权

  • 📱 Purchase Connector:自动验证应用内购和订阅收入

  • 📈 多维度分析:支持自定义事件和用户属性上报

  • 🌍 多平台支持:兼容 Expo 和裸 React Native 项目

安装指南

基础安装

npm install react-native-appsflyer --savecd 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@Overridepublic void onNewIntent(Intent intent) {  super.onNewIntent(intent);  setIntent(intent); // 必须设置以保证深度链接正常处理}
复制代码

React Native 事件桥接

// index.jsNativeEventEmitter.addListener(  'onDeepLinking',   (res) => {    if (res.status === 'success') {      handleDeepLink(res.data);    }  });
复制代码


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


办公AI智能小助手


用户头像

qife

关注

还未添加个人签名 2021-05-19 加入

还未添加个人简介

评论

发布
暂无评论
AppsFlyer React Native 插件 - 移动应用分析与归因解决方案_react-native_qife_InfoQ写作社区