AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

integration-tanstack-start

PostHog integration for TanStack Start full-stack applications

Original source
posthog
License
MIT
Pinned revision
cac7c80a9e5b73484d18eda1bffb47297c938e0c

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read posthog--integration-tanstack-start at revision cac7c80a9e5b73484d18eda1bffb47297c938e0c, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 8

references/EXAMPLE.md · 24000

outeImport, } as any) const BurritoRoute = BurritoRouteImport.update({ id: '/burrito', path: '/burrito', getParentRoute: () => rootRouteImport, } as any) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) const ApiBurritoConsiderRoute = ApiBurritoConsiderRouteImport.update({ id: '/api/burrito/consider', path: '/api/burrito/consider', getParentRoute: () => rootRouteImport, } as any) const ApiAuthLoginRoute = ApiAuthLoginRouteImport.update({ id: '/api/auth/login', path: '/api/auth/login', getParentRoute: () => rootRouteImport, } as any)

export interface FileRoutesByFullPath { '/': typeof IndexRoute '/burrito': typeof BurritoRoute '/profile': typeof ProfileRoute '/api/auth/login': typeof ApiAuthLoginRoute '/api/burrito/consider': typeof ApiBurritoConsiderRoute } export interface FileRoutesByTo { '/': typeof IndexRoute '/burrito': typeof BurritoRoute '/profile': typeof ProfileRoute '/api/auth/login': typeof ApiAuthLoginRoute '/api/burrito/consider': typeof ApiBurritoConsiderRoute } export interface FileRoutesById { root: typeof rootRouteImport '/': typeof IndexRoute '/burrito': typeof BurritoRoute '/profile': typeof ProfileRoute '/api/auth/login': typeof ApiAuthLoginRoute '/api/burrito/consider': typeof ApiBurritoConsiderRoute } export interface FileRouteTypes { fileRoutesByFullPath: FileRoutesByFullPath fullPaths: | '/' | '/burrito' | '/profile' | '/api/auth/login' | '/api/burrito/consider' fileRoutesByTo: FileRoutesByTo to: | '/' | '/burrito' | '/profile' | '/api/auth/login' | '/api/burrito/consider' id: | 'root' | '/' | '/burrito' | '/profile' | '/api/auth/login' | '/api/burrito/consider' fileRoutesById: FileRoutesById } export interface RootRouteChildren { IndexRoute: typeof IndexRoute BurritoRoute: typeof BurritoRoute ProfileRoute: typeof ProfileRoute ApiAuthLoginRoute: typeof ApiAuthLoginRoute ApiBurritoConsiderRoute: typeof ApiBurritoConsiderRoute }

declare module '@tanstack/react-router' { interface FileRoutesByPath { '/profile': { id: '/profile' path: '/profile' fullPath: '/profile' preLoaderRoute: typeof ProfileRouteImport parentRoute: typeof rootRouteImport } '/burrito': { id: '/burrito' path: '/burrito' fullPath: '/burrito' preLoaderRoute: typeof BurritoRouteImport parentRoute: typeof rootRouteImport } '/': { id: '/' path: '/' fullPath: '/' preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } '/api/burrito/consider': { id: '/api/burrito/consider' path: '/api/burrito/consider' fullPath: '/api/burrito/consider' preLoaderRoute: typeof ApiBurritoConsiderRouteImport parentRoute: typeof rootRouteImport } '/api/auth/login': { id: '/api/auth/login' path: '/api/auth/login' fullPath: '/api/auth/login' preLoaderRoute: typeof ApiAuthLoginRouteImport parentRoute: typeof rootRouteImport } } }

const rootRouteChildren: RootRouteChildren = { IndexRoute: IndexRoute, BurritoRoute: BurritoRoute, ProfileRoute: ProfileRoute, ApiAuthLoginRoute: ApiAuthLoginRoute, ApiBurritoConsiderRoute: ApiBurritoConsiderRoute, } export const routeTree = rootRouteImport ._addFileChildren(rootRouteChildren) ._addFileTypes()

import type { getRouter } from './router.tsx' import type { createStart } from '@tanstack/react-start' declare module '@tanstack/react-start' { interface Register { ssr: true router: Awaited<ReturnType> } }


---

## src/utils/posthog-server.ts

```ts
import { PostHog } from 'posthog-node'

let posthogClient: PostHog | null = null

export function getPostHogClient() {
  if (!posthogClient) {
    posthogClient = new PostHog(
      process.env.VITE_PUBLIC_POSTHOG_PROJECT_TOKEN || import.meta.env.VITE_PUBLIC_POSTHOG_PROJECT_TOKEN!,
      {
        host: process.env.VITE_PUBLIC_POSTHOG_HOST || import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
        flushAt: 1,
        flushInterval: 0,
      },
    )
  }
  return posthogClient
}



vite.config.ts

import { defineConfig } from 'vite'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import viteReact from '@vitejs/plugin-react'
import viteTsConfigPaths from 'vite-tsconfig-paths'

const config = defineConfig({
  plugins: [
    // this is the plugin that enables path aliases
    viteTsConfigPaths({
      projects: ['./tsconfig.json'],
    }),
    tanstackStart(),
    viteReact(),
  ],
  server: {
    proxy: {
      '/ingest': {
        target: 'https://us.i.posthog.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ingest/, ''),
        secure: false,
      },
    },
  },
})

export default config