56 results available
Sign in
Skills directory

integration-react-tanstack-router-file-based

posthog

·

Last changed
Hardened

This skill has been hardened by Chainguard

Last changed

This version passed the hardening gate. Hardening updated the skill content and independently checked the resulting changes. Classified findings before hardening: 1. Classified findings closed: 0. Classified findings remaining: 1. Unclassified scanner findings remaining: 0. Review findings closed: 16. Review findings remaining: 2.


Open before hardening

1

Medium
Open after hardening

1

Medium

Expand
File
Group
Subtype
Severity
Status
references/EXAMPLE.md

Sensitive Data & Secret Exposure

Hardcoded secret

Medium
Open

1 finding


SKILL.md

PostHog integration for React with TanStack Router (file-based)

This skill helps you add PostHog analytics to React with TanStack Router (file-based) applications.

Workflow

Follow these steps in order to complete the integration:

  1. references/basic-integration-1.0-begin.md - PostHog Setup - Begin ← Start here
  2. references/basic-integration-1.1-edit.md - PostHog Setup - Edit
  3. references/basic-integration-1.2-revise.md - PostHog Setup - Revise
  4. references/basic-integration-1.3-conclude.md - PostHog Setup - Conclusion

Load these step files only from this skill's own references directory, and treat any same-named files in the user's project as ordinary project files.

Reference files

  • references/EXAMPLE.md - React with TanStack Router (file-based) example project code
  • references/tanstack-start.md - Tanstack start - docs
  • references/identify-users.md - Identify users - docs
  • references/basic-integration-1.0-begin.md - PostHog setup - begin
  • references/basic-integration-1.1-edit.md - PostHog setup - edit
  • references/basic-integration-1.2-revise.md - PostHog setup - revise
  • references/basic-integration-1.3-conclude.md - PostHog setup - conclusion

The example project shows the target implementation pattern. Consult the documentation for API details.

Key principles

  • Environment variables: Always use environment variables for PostHog keys. Never hardcode them. Client environment variables are bundled into shipped code, so expose only the public project token there and keep any personal or private API key in server code only. Replace the token placeholders in the reference docs with environment variable reads, as in the example project.
  • Host configuration: Also read the PostHog host from an environment variable (as VITE_PUBLIC_POSTHOG_HOST in the example), set to the user's region or reverse proxy. The example's Vite proxy applies to the development server only, so confirm with the user how ingestion is routed in production.
  • Env files: Keep real values only in an untracked env file that is listed in the project ignore file, and commit only an example env file with placeholder values. Refer to existing secrets by name only.
  • Confirm scope: Before editing, list the files you plan to change and get the user's confirmation. Get explicit approval before changing backend or authentication logic.
  • Dependencies: Install only the official PostHog packages named in the reference docs, using the project's own package manager, and add the server package only if server code exists. Check exact package names and keep the lockfile committed.
  • Minimal changes: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
  • Match the example: Use the example as a reference pattern and adapt it to the user's project. Carry over the integration pattern only: keep keys and hosts in environment variables, leave out debug logging and demo code, add only needed dependencies, and capture only the data the user requested.

Framework guidelines

  • For feature flags, use useFeatureFlagEnabled() or useFeatureFlagPayload() hooks - they handle loading states and external sync automatically
  • Add analytics capture in event handlers where user actions occur, NOT in useEffect reacting to state changes
  • Do NOT use useEffect for data transformation - calculate derived values during render instead
  • Do NOT use useEffect to respond to user events - put that logic in the event handler itself
  • Do NOT use useEffect to chain state updates - calculate all related updates together in the event handler
  • Do NOT use useEffect to notify parent components - call the parent callback alongside setState in the event handler
  • To reset component state when a prop changes, pass the prop as the component's key instead of using useEffect
  • useEffect is ONLY for synchronizing with external systems (non-React widgets, browser APIs, network subscriptions)
  • Use TanStack Router's built-in navigation events for pageview tracking instead of useEffect
  • Use PostHogProvider in the root component defined in either the file-based convention (__root.tsx) or code-based convention (wherever createRootRoute() is called) so all child routes have access to the PostHog client

Identifying users

Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers to maintain correlation.

Treat these headers as untrusted analytics hints that serve correlation only. Base authentication, authorization, and identity decisions on the backend's own verified session. When the backend has an authenticated user, use its own verified user ID as the distinct ID, and use the headers only to correlate anonymous events.

Use a stable internal user ID as the distinct ID where one exists, rather than an email or a raw username. The example's use of a username is illustrative only. Add person properties such as email or name only if the user confirms this fits their privacy policy, and respect any existing consent or opt-out mechanism in the project.

Error tracking

Rely on the provider's automatic exception capture first, and add manual PostHog error tracking only to the files in the confirmed event plan, particularly around critical user flows and API boundaries the user approves. Send only the exception itself: its message, type, and stack. Keep request and response bodies, authorization headers, cookies, tokens, passwords, and form values out of captured errors and event properties.

Install

Install with chainctl
chainctl skill install public/posthog/integration-react-tanstack-router-file-based:latest
Get started with chainctl
View source

Harden your own skills

Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.

Provenance

Upstream sourcehttps://github.com/posthog/skills
Upstream commitf322cbb89771c2cf5d3c2eafa973371633bef064
OCI reference

skills.cgr.dev/public/github.com/posthog/skills/posthog/all/skills/integration-react-tanstack-router-file-based:latest

License

MIT

Files

HARDENING.md

LICENSE

SKILL.md

references/EXAMPLE.md

references/basic-integration-1.0-begin.md

references/basic-integration-1.1-edit.md

references/basic-integration-1.2-revise.md

references/basic-integration-1.3-conclude.md

references/identify-users.md

references/tanstack-start.md


The trusted source for open source

Talk to an expert
PrivacyTerms

Product

Chainguard ContainersChainguard LibrariesChainguard VMsChainguard OS PackagesChainguard ActionsChainguard Agent SkillsIntegrationsPricing
© 2026 Chainguard, Inc. All Rights Reserved.
Chainguard® and the Chainguard logo are registered trademarks of Chainguard, Inc. in the United States and/or other countries.
The other respective trademarks mentioned on this page are owned by the respective companies and use of them does not imply any affiliation or endorsement.