Skip to main content

Referrals

The SDK supports referral program integration — fetching referral codes/stats and tracking new referrals.

Service Methods

Referral functionality is available through the LoyaltyService (not wrapped in a dedicated hook).
const { loyalty } = useStackfront();

// Get referral code and stats
const referral = await loyalty.getReferral(customerId);
// { referralCode: string; totalReferrals: number; rewardsEarned: number; shareUrl: string }

// Track a new referral
await loyalty.trackReferral({
  referralCode: 'REF123',
  referredCustomerId: 'gid://shopify/Customer/456',
  orderId: 'gid://shopify/Order/789',
});

Displaying Referral Info

import { useLoyalty } from 'react-native-stackfront-sdk';

function ReferralRewards({ customerId }: { customerId: string }) {
  const { account } = useLoyalty(customerId);
  const [referral, setReferral] = useState<ReferralSdkResponse | null>(null);

  useEffect(() => {
    const { loyalty } = useStackfront();
    // Access service directly for referral data
    loyalty.getReferral(customerId).then(setReferral);
  }, [customerId]);

  if (!referral) return null;

  return (
    <View>
      <Text>Your referral code: {referral.referralCode}</Text>
      <Text>Total referrals: {referral.totalReferrals}</Text>
      <Text>Rewards earned: {referral.rewardsEarned}</Text>
      <ShareButton url={referral.shareUrl} />
    </View>
  );
}

Referral Response

{
  referralCode: string;
  totalReferrals: number;
  rewardsEarned: number;
  shareUrl: string;
}