GrowthRailDocs
Prerequisites: You need a Growth Rail account. If you haven't signed up yet, create an account at the Growth Rail dashboard. Once logged in, the onboarding wizard will guide you through organization and project creation.

Architecture Overview

Growth Rail uses a hierarchical structure to organize your data. Understanding this hierarchy is key to setting up your integration correctly.

Organization
Your company or team account
Project
One per app or environment
Campaign
Referral UI & experience config
Users
App users with referral codes
EntityScopeDescription
OrganizationAccount-wideYour top-level account. Manages billing, team members, and projects. All projects live under one org.
ProjectPer app / environmentAn isolated container with its own secret, users, campaigns, and webhooks. Create one per app or per environment (dev/staging/prod).
CampaignPer projectDefines the referral UI experience — trigger button, sharing modal, and new-user welcome banner.
App UsersPer projectYour end users, each with a unique referral code. Isolated per project — a user in "Production" is separate from a user in "Staging".

Creating a Project

You can create a project during onboarding or at any time from the dashboard.

1

Choose a platform type

Select whether your project targets Web App or Mobile App. This choice determines which configuration options appear (e.g., mobile projects get App Store / Play Store URL fields). The platform type cannot be changed after creation.

Onboarding Platform Type Selection
Select Web App or Mobile App during initial project setup.

Web App

For websites and web apps. Referral links redirect to your configured URL. The SDK uses cookies for tracking and renders UI components in the browser DOM.

Mobile App

For React Native and native iOS / Android apps. Supports deep linking, install referrer / fingerprint matching for deferred deep links, and automatic mobile referral UI.

2

Name and describe your project

Give your project a clear, descriptive name. If you run multiple environments, include the environment in the name to avoid confusion.

FieldTypeDescription
namestringA human-readable name (e.g. "MyApp - Production"). Required.
descriptionstringOptional. A short description to help identify the project's purpose.
uniqueIdstringAuto-generated identifier (e.g. proj_k8xn2m). Used in all REST API paths.
appType"Web" | "Mobile"Platform type (Web App or Mobile App). Set during creation and cannot be changed.
3

Get your Project Secret

After creation, your project is assigned a Project Secret (prefixed with sk_). This is the credential your SDK uses on every request. You'll find it under Project Settings in the dashboard.

bash
# Your project secret looks like this:
sk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6

Project Secret

The Project Secret is the credential the SDK sends on every API request in the X-GrowthRail-ProjectSecret header. Growth Rail uses it to identify which project the request belongs to and to verify the request origin.

bash
# .env (recommended approach)
GROWTH_RAIL_PROJECT_SECRET=sk_a1b2c3d4e5f6g7h8i9j0...

# Access in your app
process.env.GROWTH_RAIL_PROJECT_SECRET
Keep your Project Secret safe. Always load it from an environment variable — never hardcode it in source files or share it in Slack messages.

Referral Redirect Link

The Referral Redirect Link is the base URL that Growth Rail appends referral parameters to when generating shareable links for your users. Set this in the dashboard under Project Settings.

Referral Redirect URL Settings
Specify the default landing page URL for referred users in the Project Settings panel.

This URL should point to your signup or landing page — the page where new users land when following a referral link. When the SDK initializes on that page, it automatically detects the referralCode query parameter and calls trackReferral() behind the scenes.

Points to your signup or landing page
Uses HTTPS in production
The SDK is initialized on this page (so it can detect the referral code)
!Do not add query parameters to the base URL — Growth Rail appends them automatically

Mobile App Configuration

If your project type is Mobile, you'll need to configure additional app details for deep linking and store redirects. Navigate to Project Settings and fill in your app information.

FieldDescriptionExample
appNameYour app's display nameMyApp
appStoreUrliOS App Store listing URLhttps://apps.apple.com/app/id123456
playStoreUrlGoogle Play Store listing URLhttps://play.google.com/store/apps/details?id=com.yourapp
iconUrlApp icon (max 10 MB, drag-and-drop upload)Used in referral link previews

SDK Installation

With your project configured, install the Growth Rail SDK in your application.

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

Initialize the SDK

tsx
// main.tsx or App.tsx
import { GrowthRailProvider } from '@growth-rail/react';

function App() {
  const currentUser = useAuth(); // 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} // verbose logging in dev
    >
      <YourApp />
    </GrowthRailProvider>
  );
}

Configuration Options

The SDK accepts the following configuration options during initialization:

OptionTypeDefaultDescription
projectSecretKeystringRequired. Your project's secret key (starts with sk_).
userIdstring?undefinedYour internal user ID. If provided, auto-calls initAppUser().
cookieDomainstring?Current domainDomain for tracking cookies. Use .yourapp.com for cross-subdomain attribution.
autoPageTrackboolean?falseAutomatically detect referralCode in URL and track referral on page load.
debugboolean?falseEnable verbose console logging for debugging. Disable in production.

REST API Authentication

For server-to-server calls to the Growth Rail REST API, use an API Key (prefixed grak_). Create one in the dashboard under Organisation → API Keys and pass it as a Bearer token.

Server-to-server REST API call
curl -X POST https://api.growthrail.dev/api/v1/public/projects/{projectId}/referrals/track \
  -H "Authorization: Bearer grak_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"referralCode": "ABC123"}'
See the Authentication guide for the full breakdown of Project Secret (SDK) vs API Key (REST API).

Multiple Environments

The recommended pattern is to create one project per environment. Each project has its own secret, campaigns, and user data — ensuring test data never bleeds into production.

Project NamePurpose
MyApp - DevelopmentLocal testing and feature development
MyApp - StagingPre-production QA and integration testing
MyApp - ProductionLive traffic with real users
Environment-based SDK configuration
// config.ts
const config = {
  development: {
    projectSecret: process.env.GR_DEV_SECRET,
    debug: true,
  },
  staging: {
    projectSecret: process.env.GR_STAGING_SECRET,
    debug: true,
  },
  production: {
    projectSecret: process.env.GR_PROD_SECRET,
    debug: false,
  },
};

export const grConfig = config[process.env.NODE_ENV || 'development'];

Setup Verification Checklist

Before moving on to implementing the referral flow, verify that your project is configured correctly:

Project created — visible in the dashboard with a unique ID
Project Secret copied — stored securely in environment variables
Referral Redirect Link set — points to your signup or landing page
SDK installed — package added and provider/init configured
Debug mode enabled in dev — check console for Growth Rail initialization logs

Troubleshooting

What's Next

Referral Flow

Learn the complete lifecycle from link generation to reward delivery.

Campaign Setup

Configure the referral UI — trigger button, modal, and new-user banner.

Webhooks

Set up real-time reward event delivery to your backend.