Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • added referrers, code redemption, campaign tracking, etc

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 13, 2026 3:49am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 11, 2026

Greptile Overview

Greptile Summary

This 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:

  • Automatic attribution via UTM parameters captured in cookies and matched to campaigns by specificity
  • Manual referral code redemption with organization-level uniqueness for team plans
  • Atomic transaction handling ensures userStats creation and credit application happen together
  • Bonus credits correctly route to user or organization balance based on subscription plan

Additional improvements in this PR:

  • New Redis-based execution event streaming system replacing polling with SSE
  • Workflow comparison normalization for trigger configs to fix false positives
  • Enhanced Confluence integration with label management tools
  • Copilot context handling improved to support multiple block IDs

Previous feedback addressed:

  • userStats creation moved inside transactions in both attribution endpoints (previously flagged as atomicity issue)
  • Transaction handling is now fully atomic for attribution + credit application flow

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

  • This PR is safe to merge with well-tested features and proper transaction handling
  • The implementation demonstrates solid engineering practices with atomic transactions, proper error handling, idempotency via database constraints, and comprehensive logging. Previous atomicity concerns have been addressed by moving userStats creation inside transactions. The bonus credit routing logic correctly handles different subscription plans, and the UTM matching algorithm provides flexible campaign targeting.
  • No files require special attention - the implementation is consistent and well-structured throughout

Important Files Changed

Filename Overview
apps/sim/app/api/attribution/route.ts New UTM-based automatic attribution endpoint with cookie tracking, campaign matching, and atomic credit application
apps/sim/app/api/referral-code/redeem/route.ts New manual referral code redemption endpoint with org-level uniqueness checks and atomic transaction handling
apps/sim/lib/billing/credits/bonus.ts New bonus credit application logic that routes to user or org balance based on subscription plan
packages/db/schema.ts Added referral_campaigns and referral_attribution tables with proper indexes and constraints
packages/db/migrations/0154_bumpy_living_mummy.sql Database migration creating referral tables with partial unique index for org-level redemption uniqueness
apps/sim/app/api/v1/admin/referral-campaigns/route.ts Admin endpoints for listing and creating referral campaigns with pagination and proper validation
apps/sim/proxy.ts Added UTM cookie tracking on auth pages with referrer and timestamp capture
apps/sim/lib/workflows/comparison/normalize.ts Added trigger config normalization to ensure consistent workflow comparison between client and deployed states
apps/sim/lib/execution/event-buffer.ts New Redis-based event buffering system for execution streaming with TTL and batching
apps/sim/app/api/workflows/[id]/executions/[executionId]/stream/route.ts New SSE endpoint for streaming execution events from Redis buffer

Sequence Diagram

sequenceDiagram
    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
Loading

Last reviewed commit: ad10971

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile
@cursor review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

62 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile
@cursor review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

62 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile
@cursor review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

62 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review
@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

62 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review
@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

62 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@waleedlatif1 waleedlatif1 merged commit 022e84c into staging Feb 13, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/creators branch February 13, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant