Skip to content

feat: Event setup mode#94

Merged
daniloc merged 39 commits into
mainfrom
event-setup-mode
Jul 29, 2025
Merged

feat: Event setup mode#94
daniloc merged 39 commits into
mainfrom
event-setup-mode

Conversation

@daniloc
Copy link
Copy Markdown
Collaborator

@daniloc daniloc commented Jul 10, 2025

This pull adds experimental event setup for Nexts.js 15.3+:

src/nextjs/event-setup.ts

This adds the new workflow, including a very thorough prompt with rules that prevent stupid changes from happening. In addition, the workflow creates a markdown report at the end explaining what happened and providing next steps.

Other changes

I needed debug logging for query.ts at various points, so that's in here too. Can take or leave.

Testing

I found a nice and meaty project to test this on:

https://github.com/nextjs/saas-starter

@daniloc daniloc force-pushed the event-setup-mode branch from 8bff812 to a8f1deb Compare July 16, 2025 18:12
@daniloc daniloc force-pushed the event-setup-mode branch from 007ea8c to 6fae908 Compare July 16, 2025 18:18
@daniloc daniloc force-pushed the event-setup-mode branch from 6fae908 to 4fc3429 Compare July 16, 2025 18:19
@daniloc daniloc marked this pull request as ready for review July 16, 2025 18:33
@daniloc daniloc changed the title Event setup mode (WIP) feat: Event setup mode (WIP) Jul 16, 2025
@daniloc
Copy link
Copy Markdown
Collaborator Author

daniloc commented Jul 16, 2025

a couple remaining to-dos:

  • Check state of git and warn if uncommitted files
  • Analytics events so I can get emails from people who try this

@daniloc daniloc changed the title feat: Event setup mode (WIP) feat: Event setup mode Jul 17, 2025
@daniloc
Copy link
Copy Markdown
Collaborator Author

daniloc commented Jul 29, 2025

@jonathanlab welp: it's not nearly as ambitious as I'd hoped but: constraining to client-side files at least provides consistent, reliable outcomes. It gets the ball rolling, and when we have a proper library for this framework we can take another pass for the more compelling version!

Comment thread src/utils/query.ts
Comment thread src/nextjs/event-setup.ts
Comment thread src/nextjs/event-setup.ts Outdated
Copy link
Copy Markdown
Collaborator

@jonathanlab jonathanlab left a comment

Choose a reason for hiding this comment

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

This is genuinely so nice: I think it's a great start to just try this out with client side analytics first. Excited to see how people use it!

I ran into an issue with the next-js-instrumentation-client-app where it would sometimes fail to enhance one of the pages available:

│  Enhancing files with event tracking. Changes will be applied as they come in. Use your git interface to review new events. Feel free to toss anything you don't like...
│
◇  ✗ Failed to enhance src/app/example/page.tsx
│
◇  ✓ Enhanced src/app/page.tsx with 3 events
│
└  Success! Added 3 events across 1 files.
    
    Event tracking plan saved to: event-tracking-report.md
    
    Next steps:
    1. Review changes with your favorite git tool
    2. Revert unwanted changes with git checkout <file>
    3. Test that events are being captured in your PostHog project
    4. Create insights in PostHog

I ran it again and it enhanced the failed file successfully, so more of a transient error I guess 🤷🏻

daniloc and others added 2 commits July 29, 2025 11:16
Co-authored-by: Jonathan Mieloo <32547391+JonathanLab@users.noreply.github.com>
@daniloc daniloc requested a review from jonathanlab July 29, 2025 15:28
@daniloc daniloc merged commit c412501 into main Jul 29, 2025
10 checks passed
daniloc added a commit that referenced this pull request Oct 27, 2025
* Basics of event tracking setup

* Add debug flag handling to query.ts

* Working API connection

* Get better event suggestions

* Rework event generation

* Better prompting

* Move Wizard into next-specific directory for now

* Update import paths

* Iterating prompt

* More robust server-side handling

* Aggressively detect client vs server, discourage bad events

* Add helper

* IT WORKS WELL

* Prevent weird mangling of file endings

* UI tweaks

* Use the query implementation from main

* Add newline

* Replace debug logging

* remove unneeded file picker

* Remove unneeded package

* Let's make typescript happy

* Prettier

* Add event tracking for event workflow

* Check for git status before proceeding

* harmonize events with rest of project

* Opt out of no-console for the helper file; logging is a good start for devs to improve on

* obeisance to the linter

* More linter deference

* prevent posthog-node being included in client bundle

* Restore old approach

* Lint and pretty

* Copy tweaks

* Radically simplify: client-side only for now

* Invite folks to try the event-setup mode

* Check for dirty git status before proceeding

* prettier

* Update src/nextjs/event-setup.ts

Co-authored-by: Jonathan Mieloo <32547391+JonathanLab@users.noreply.github.com>

* Re-add analytics

---------

Co-authored-by: Jonathan Mieloo <32547391+JonathanLab@users.noreply.github.com>
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.

2 participants