@growth-rail/core
v2.1.1
Published
Growth Rail SDK
Readme
@growth-rail/core
The foundation of the Growth Rail SDK. A platform-agnostic, pure TypeScript library for tracking referrals, managing user sessions, and interacting with the Growth Rail API.
🚀 Features
- Platform Agnostic: Works in Node.js, Browsers, and React Native.
- Lightweight: Zero dependencies (except for environment-specific polyfills).
- Isomorphic: Unified API for client and server-side tracking.
- Type-Safe: First-class TypeScript support.
- Modular: Easy to extend or wrap with framework-specific adapters.
📦 Installation
# npm
npm install @growth-rail/core
# yarn
yarn add @growth-rail/core
# pnpm
pnpm add @growth-rail/core🛠 Usage
Initialization
Initialize the singleton instance with your API Key.
import { GrowthRail } from '@growth-rail/core';
GrowthRail.init({
apiKey: 'your_api_key_here'
});
// Initialize a user session
await GrowthRail.initAppUser('user_external_id_123');Tracking Referrals
Track when a new user arrives with a referral code.
import { GrowthRail } from '@growth-rail/core';
async function handleReferral(code: string) {
const result = await GrowthRail.trackReferral(code);
console.log('Referral success:', result.success);
}Creating Referral Links
Generate a referral link for a user to share.
import { GrowthRail } from '@growth-rail/core';
async function getLink() {
const { referralLink } = await GrowthRail.createReferralLink(
GrowthRail.getUserId()
);
return referralLink;
}🔌 Framework Wrappers
Looking for a framework-specific version?
📖 Documentation
For full documentation and advanced configuration, visit docs.growthrail.com.
📄 License
MIT © Growth Rail
