Building Share-ID Referral Tracking for AI Labs
Our viral loop depends on the share modal. Here is how we mint unique share IDs, tie them to credits, and analyze the referrals.
1. Generate IDs client-side
`usage.js` creates a `client_id` and a `share_id` whenever the Share button fires. The ID flows through `/api/share`, `/api/credits/checkout`, and `Stripe webhooks`. This enables us to credit the original sharer if their friend buys a pack.
2. Embed UTMs everywhere
We append `utm_source`, `utm_medium`, and `utm_campaign` to every share link (see `/api/qr`). Inside Discord or TikTok captions we encourage creators to keep the URL intact so blame/credit remains intact.
3. Log to Redis + files
`logShareEvent` writes to `public/share-cache/share-events.log`. Once a day we ingest the log into BigQuery so we can query referral trees or top-converting labs. You can do the same with a simple cron job plus Python import.
4. Credit bonuses
When `/api/share` succeeds we call `grantShareCredits` inside `credit-store.js`. The share ID is part of the log entry, so support can manually reward big creators. For automated affiliate programs you can map share IDs to Stripe metadata and pay out monthly.
Further reading