feat(creators): added referrers, code redemption, campaign tracking, etc#3198
feat(creators): added referrers, code redemption, campaign tracking, etc#3198waleedlatif1 merged 11 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR implements a comprehensive referral and campaign tracking system with both automatic UTM-based attribution and manual code redemption. The implementation includes database schema for campaigns and attribution, admin APIs for campaign management, and client-side integration. Key referral system features:
Additional improvements in this PR:
Previous feedback addressed:
The referral system implementation is well-architected with proper error handling, idempotency via unique constraints, and comprehensive logging. The admin APIs include proper validation and pagination. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Proxy
participant Browser
participant AttributionAPI
participant RedeemAPI
participant BonusCredits
participant DB
Note over User,DB: UTM-Based Attribution Flow
User->>Proxy: Visit auth page with UTM params
Proxy->>Browser: Set sim_utm cookie (UTM data + timestamp)
Browser->>Proxy: Complete signup
User->>Browser: Navigate to workspace page
Browser->>AttributionAPI: POST /api/attribution (with cookie)
AttributionAPI->>DB: Check user created_at vs cookie timestamp
AttributionAPI->>DB: Find matching campaign by UTM specificity
AttributionAPI->>DB: Begin transaction
AttributionAPI->>DB: Ensure userStats exists
AttributionAPI->>DB: Insert referral_attribution (conflict: userId)
alt Attribution successful
AttributionAPI->>BonusCredits: applyBonusCredits(userId, amount, tx)
BonusCredits->>DB: Get subscription plan
alt Team/Enterprise
BonusCredits->>DB: Update org.creditBalance + orgUsageLimit
else Free/Pro
BonusCredits->>DB: Update userStats.creditBalance + currentUsageLimit
end
AttributionAPI->>DB: Commit transaction
AttributionAPI->>Browser: { attributed: true, bonusAmount }
else Already attributed
AttributionAPI->>DB: Rollback (conflict)
AttributionAPI->>Browser: { attributed: false }
end
Note over User,DB: Manual Code Redemption Flow
User->>Browser: Enter referral code in settings
Browser->>RedeemAPI: POST /api/referral-code/redeem { code }
RedeemAPI->>DB: Get user subscription plan
alt Enterprise user
RedeemAPI->>Browser: { error: "Enterprise cannot redeem" }
else Non-enterprise
RedeemAPI->>DB: Find campaign by code
RedeemAPI->>DB: Check existing user attribution
RedeemAPI->>DB: Check existing org attribution (if team)
alt Code available
RedeemAPI->>DB: Begin transaction
RedeemAPI->>DB: Ensure userStats exists
RedeemAPI->>DB: Insert referral_attribution (with orgId if team)
RedeemAPI->>BonusCredits: applyBonusCredits(userId, amount, tx)
BonusCredits->>DB: Update credit balance based on plan
RedeemAPI->>DB: Commit transaction
RedeemAPI->>Browser: { redeemed: true, bonusAmount }
else Already redeemed
RedeemAPI->>Browser: { error: "Already redeemed" }
end
end
Last reviewed commit: ad10971 |
|
@greptile |
|
@greptile |
|
@greptile |
|
@cursor review |
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
|
@cursor review |
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts
Show resolved
Hide resolved
apps/sim/app/api/workflows/[id]/executions/[executionId]/stream/route.ts
Show resolved
Hide resolved
ad10971 to
8b57a68
Compare
|
@cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
8b57a68 to
31113e5
Compare
Summary
Type of Change
Testing
Tested manually
Checklist