GrowthRailDocs
Prerequisites: You need a Growth Rail account and a project created in the dashboard. Grab your Project Secret from Settings and configure your Referral Redirect Link.

What You'll Build

By the end of this guide, your app will have a complete referral flow:

1
Install
Add SDK packages
2
Initialize
Wrap app with provider
3
Identify
Register users
4
Track
Track reward events
5
Deliver
Configure webhooks
1

Install the SDK

Install the Growth Rail SDK using your preferred package manager. Choose the package that matches your framework.

bash
npm install @growth-rail/react @growth-rail/core
# or
yarn add @growth-rail/react @growth-rail/core
# or
pnpm add @growth-rail/react @growth-rail/core
2

Initialize the SDK

Add the Growth Rail provider at the root of your application. Pass your Project Secret as the projectSecretKey prop.

Project Secret Key
Find your Project Secret under Project Settings in the Growth Rail dashboard.
tsx
// main.tsx or App.tsx
import { GrowthRailProvider } from '@growth-rail/react';

function App() {
  const currentUser = useCurrentUser(); // your auth hook

  return (
    <GrowthRailProvider
      projectSecretKey={import.meta.env.VITE_GROWTH_RAIL_SECRET}
      userId={currentUser?.id}   // pass once user is authenticated
      debug={import.meta.env.DEV}
    >
      <YourApp />
    </GrowthRailProvider>
  );
}
3

Identify users after login

Call initAppUser() once the user is authenticated. This creates the user in Growth Rail (if they don't exist), generates a unique referral code, and returns a shareable referral link.

tsx
import { useGrowthRail } from '@growth-rail/react';

export function DashboardPage() {
  const { initAppUser } = useGrowthRail();
  const { user } = useAuth();

  useEffect(() => {
    if (user?.id) initAppUser(user.id);
  }, [user?.id]);

  return <div>Welcome to your dashboard</div>;
}
4

Track reward events

When a referred user completes a qualifying action (signup, purchase, etc.), track the event via the backend REST API (POST /api/v1/sdk/track-reward-event) or automatically via native Stripe & RevenueCat integrations.

bash
curl -X POST https://api.growthrail.dev/api/v1/sdk/track-reward-event \
  -H "x-project-secret-key: sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "newUserId": "user_123",
    "referralTrackingId": "tr_789",
    "eventName": "user_signup",
    "environment": "Production"
  }'
5

Configure a webhook

In the Growth Rail dashboard, go to Integrations → Reward Webhooks and add your backend URL. When a reward is triggered, Growth Rail POSTs a signed JSON payload to your endpoint.

Reward Webhooks Configuration
Configure your reward webhooks endpoint in the Integrations dashboard.
For webhook payload details, authentication, retry behavior, and event types, see the Webhooks guide.

Bonus: Show the Referral UI

The SDK automatically renders a floating invite button and sharing modal based on your Campaign Setup settings — no extra code needed. To trigger the modal manually:

Client-Side Referral UI (Floating Button & Modal)
The built-in referral sharing modal with copy link and social sharing options.
tsx
const { showReferralDashboard, showFloatingButton } = useGrowthRail();

// Floating button (auto-shown from Campaign settings, or trigger manually)
showFloatingButton({ position: 'bottom-right', displayMode: 'floating' });

// Open the sharing modal from your own button
<button onClick={() => showReferralDashboard()}>Invite Friends</button>

What's Next

Project Setup

Configure redirect links, project secrets, and multi-environment strategies.

Referral Flow

Deep-dive into the full referral lifecycle from link creation to reward delivery.

Reward Logic

Understand trigger events, eligibility checks, and webhook routing per rule.