@affiliateo/react-native
v4.2.0
Published
Affiliateo SDK for React Native. mobile affiliate attribution and session tracking
Downloads
1,623
Maintainers
Readme
@affiliateo/react-native
Affiliateo SDK for React Native. mobile affiliate attribution and screen tracking.
Install
npm install @affiliateo/react-nativeSetup
Wrap your app with AffiliateoProvider. To get a complete funnel without
adding tracking calls to every screen, also pass a React Navigation
navigationRef. the SDK subscribes to navigation state changes and
auto-fires one screen_view per route.
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import { AffiliateoProvider } from '@affiliateo/react-native';
export default function App() {
const navigationRef = useNavigationContainerRef();
return (
<NavigationContainer ref={navigationRef}>
<AffiliateoProvider
campaignId="YOUR_CAMPAIGN_ID"
navigationRef={navigationRef}
>
<YourApp />
</AffiliateoProvider>
</NavigationContainer>
);
}Without navigationRef the SDK still fires an entry screen_view at
launch and a final one on background, but per-screen tracking would
require manual .page() calls.
Track Screens manually (optional)
If you don't use React Navigation, or want to fire a specific custom
screen name, call .page() from the context:
import { useAffiliateRef } from '@affiliateo/react-native';
function PricingScreen() {
const { page } = useAffiliateRef();
useEffect(() => { page('Pricing'); }, []);
return <View>...</View>;
}Track custom goals
Screen views auto-track. For specific moments that matter to your
funnel (signup_completed, trial_started, etc.), call track():
import { useEffect } from 'react';
import { useAffiliateRef } from '@affiliateo/react-native';
function SignupSuccessScreen() {
const { track } = useAffiliateRef();
useEffect(() => {
track('signup_completed', { plan: 'free' });
}, []);
return <View>...</View>;
}Goal names: lowercase letters, digits, underscores, hyphens, colons. Max 64 chars. Optional metadata bounded to 4KB JSON.
Identify signed-in users (cross-device stitching)
Without identify(), the same person on phone + tablet counts as two
visitors and your funnel splits. Call once after sign-in:
import { useEffect } from 'react';
import { useAffiliateRef } from '@affiliateo/react-native';
import { useUser } from './your-auth';
export default function App() {
const { identify } = useAffiliateRef();
const user = useUser();
useEffect(() => {
if (user) identify(user.id);
}, [user]);
return <NavigationContainer>...</NavigationContainer>;
}Idempotent. safe to fire on every app launch while a user is signed in. user_id only. The SDK does not accept, collect, or transmit email or any other PII.
Get Affiliate Ref
import { useAffiliateRef } from '@affiliateo/react-native';
function MyComponent() {
const { refCode, isMatched, isLoading } = useAffiliateRef();
// ...
}Apple Native IAP (StoreKit 2)
If your iOS app uses StoreKit 2 directly (not RevenueCat), pass the SDK's
appAccountToken to your purchase call. Apple stamps it onto every
transaction in the chain so we can credit the affiliate on every renewal
and refund.
import { useAffiliateRef } from '@affiliateo/react-native';
import { requestPurchase } from 'expo-iap'; // or react-native-iap v14+
function BuyButton() {
const { appAccountToken } = useAffiliateRef();
async function buy() {
await requestPurchase({
sku: 'pro_monthly',
appAccountTokenIOS: appAccountToken ?? undefined,
});
}
return <Button onPress={buy} title="Subscribe" />;
}Swift StoreKit 2 (if you have a Swift purchase layer):
let token = UUID(uuidString: affiliateoAppAccountToken)
let result = try await product.purchase(
options: token.map { [.appAccountToken($0)] } ?? []
)Requires iOS 15+. On Android (or before identify completes, or for
unmatched users), appAccountToken is null.
How It Works
- On first app open, the SDK sends a device fingerprint to Affiliateo
- Affiliateo matches it against recent affiliate link clicks using IP + device signals
- If matched, the SDK:
- Auto-sets the
affiliateo_refattribute on RevenueCat (if installed) - Mints + registers a StoreKit 2
appAccountTokenso Apple native purchases get attributed automatically
- Auto-sets the
- Screen views are batched and sent every 30s for funnel analytics
- Events are persisted offline and flushed when connectivity returns
