Skip to content

Conversation

@edwinyjlim
Copy link
Member

@edwinyjlim edwinyjlim commented Oct 28, 2025

New example app for Tanstack Start based on React

  • create-vite and tanstack router
  • client-side + server-side code
  • placeholder auth
  • proxied calls to PostHog
  • PostHog product analytics, identified events, error tracking
image

@edwinyjlim edwinyjlim requested a review from a team October 28, 2025 15:52
@samueldrai
Copy link

Hi!
Thanks for this PR, super helpful.
Not quite sure I understand how calls are proxied though. Do you use a server function or an API route for that?
Thanks!

@edwinyjlim
Copy link
Member Author

Hey @samueldrai

To avoid CORS issues or ad blockers blocking calls to PostHog on the client side, we've configured the PostHog client to send its requests to a proxied /ingest API route.

// src/lib/posthog-client.ts
posthog.init(import.meta.env.VITE_POSTHOG_KEY!, {
      api_host: '/ingest', // <-- key config
      ui_host: import.meta.env.VITE_POSTHOG_HOST || 'https://us.posthog.com/',
      ...

Then we have a Vite server that intercepts the /ingest calls that then forwards them to PostHog.

// vite.config.ts
server: {
    proxy: {
      '/ingest': {
        target: 'https://us.i.posthog.com/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ingest/, ''),
        secure: false,
      },
    },
  },

For production, you'll probably need a managed reverse proxy. Here's a link to the docs on how to set that up!

Also if you have any feedback for this example app or requests for others, let us know!

Copy link
Collaborator

@daniloc daniloc left a comment

Choose a reason for hiding this comment

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

Do a pass to eliminate useEffect (preferring event handlers or other approaches) and good to merge

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.

4 participants