-
Notifications
You must be signed in to change notification settings - Fork 5
fix(revenue-analytics): Add guardrails for revenue analytics setup prompt #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,16 @@ Consult the PostHog revenue analytics documentation for the full setup guide, an | |
|
|
||
| Follow these tenets for every decision: | ||
|
|
||
| 1. **Never fabricate the value.** If the PostHog distinct_id is not available in the current scope, do NOT substitute another identifier (Stripe customer ID, internal user ID, org ID, etc.). A wrong value is worse than no value — it corrupts metadata and blocks correct identification downstream. | ||
| 1. **Never fabricate the value.** If the PostHog distinct_id is not available in the current scope, do NOT substitute another identifier (Stripe customer ID, internal user ID, org ID, etc.). A wrong value is worse than no value — it corrupts metadata and blocks correct identification downstream. Bring in the exact same identifier as used in the PostHog integrations. When this is not possible, use `"TODO_POSTHOG_DISTINCT_ID"` as a string placeholder and include this in the report. | ||
|
|
||
| 2. **Thread the value, don't invent it.** If a function needs the distinct_id but doesn't have it, add it as an optional parameter propagated from a caller that does. If no caller in the chain has it, skip that call site entirely and leave a TODO comment. | ||
|
|
||
| 3. **No extra API calls.** Never add new Stripe API calls (like `Customer.update`) just to set metadata. Instead, add `posthog_person_distinct_id` to the `metadata` parameter of Stripe objects that are already being created. | ||
|
|
||
| 4. **Follow existing Stripe abstraction patterns.** If the codebase wraps Stripe calls behind a utility/service layer, modify that layer. Don't call the Stripe API directly from business logic just to set metadata. | ||
|
|
||
| 5. **Never refactor unrelated existing code.** The only parts of the codebase that should be changed are the ones immediately related to getting PostHog distinct_id into Stripe calls. All remaining code should be left as is regardless. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lmao |
||
|
|
||
| ## How to find the PostHog distinct_id | ||
|
|
||
| Before writing any code, determine what this project uses as the PostHog distinct_id: | ||
|
|
@@ -32,6 +34,10 @@ Before writing any code, determine what this project uses as the PostHog distinc | |
|
|
||
| Once you know WHAT value is the distinct_id, determine HOW to access that same value at each Stripe call site. The variable name may differ between files — trace the data flow. | ||
|
|
||
| **Watch out!** Stripe's Checkout Sessions have a field called `client_reference_id`. This field **MAY NOT** be the same as PostHog distinct_id, so do not use it as a way to figure out what the distinc_id should be. | ||
|
|
||
| If you could not find a valid PostHog distinct_id, emit `[ABORT] Could not find a PostHog distinct_id`. The wizard middleware catches `[ABORT]` and terminates the run — you do not need to halt yourself. | ||
|
|
||
| ## What to modify | ||
|
|
||
| ### Step 1: Add metadata to Stripe Customer creation | ||
|
|
@@ -42,6 +48,8 @@ For each `Customer.create` call, add `posthog_person_distinct_id` to the `metada | |
| - If the distinct_id is not in scope, thread it as an optional parameter (Tenet 2). If no caller has it, skip this site with a TODO. | ||
| - Check if the codebase wraps Stripe calls behind a utility layer — if so, modify the wrapper (Tenet 4). | ||
|
|
||
| If you could not find a valid Stripe integration, emit `[ABORT] Could not find a Stripe integration`. The wizard middleware catches `[ABORT]` and terminates the run — you do not need to halt yourself. | ||
|
|
||
| ### Step 2: Add metadata to Stripe payment/charge objects (REQUIRED) | ||
|
|
||
| This step is **required**. The following Stripe objects support a `metadata` parameter: **Charge, PaymentIntent, Subscription, Invoice, Refund, Transfer**. Search the codebase for creation calls for any of these objects and add `posthog_person_distinct_id` to their `metadata`. | ||
|
|
@@ -60,6 +68,7 @@ If the project has a `checkout.session.completed` webhook handler and Stripe aut | |
| ### Step 3: Verify | ||
|
|
||
| Read each modified file to verify: | ||
|
|
||
| - No syntax errors | ||
| - Existing code logic is preserved | ||
| - The metadata uses the correct distinct_id value — not a fabricated property | ||
|
|
@@ -86,6 +95,12 @@ Report progress with `[STATUS]` prefixed messages: | |
| - Verifying changes | ||
| - Revenue analytics setup complete | ||
|
|
||
| ## Abort statuses | ||
|
|
||
| Report abort states with `[ABORT]` prefixed messages: | ||
| - Could not find PostHog distinct_id usage | ||
| - Could not find a Stripe integration | ||
|
|
||
| ## Framework guidelines | ||
|
|
||
| {commandments} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 interesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, tested and works pretty reliably. I think there are times where running til completion will cause the wizard to try its hardest to complete the task. It should really just give up xD instead of hallucinating stripe