Instrument Product Analytics
PostHogOfficialCreated by PostHog
- Skill
- Tool integration
- Data and AI
- MIT
- Low risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured, multi-step workflow to integrate PostHog product analytics into a wide variety of software projects. It guides the user through detecting the project's framework, installing the appropriate SDK, initializing the service, and strategically placing event capture calls. The skill emphasizes non-intrusive implementation, requiring that new analytics code be added alongside existing logic without altering the project's fundamental architecture. It also covers user identification, error tracking, and secure environment variable management.
What it does
- Detects the project's framework and language to determine the correct PostHog SDK.
- Handles initial SDK installation and initialization based on framework-specific patterns.
- Identifies key user actions and business-critical events for tracking.
- Implements event capture calls and user identification logic.
- Configures environment variables securely for API tokens and host URLs.
- Verifies the integration and performs targeted linting on modified files.
When to use it
- After implementing new features that require tracking for product analytics.
- When reviewing pull requests to ensure meaningful user behaviors are captured.
- During the initial setup of a new project that needs product analytics.
- When migrating or adding analytics to an existing application.
Advantages
- Supports a broad range of frontend, backend, and mobile frameworks.
- Ensures consistent event naming and property usage across the codebase.
- Prioritizes non-breaking changes and minimal impact on existing code structure.
- Automates the complex setup of environment variables and SDK initialization.
Usage examples
- “Add PostHog analytics to my Next.js project.”
- The agent will analyze the project structure, install the PostHog SDK, initialize it in the appropriate client/server files, and prompt you to identify key events to track.
- “I need to track user signups and errors in my Django backend.”
- The agent will locate your authentication logic, add identify calls, implement exception capture, and ensure the PostHog project tokens are managed via environment variables.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/posthog/instrument-product-analytics/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip instrument-product-analytics.zip -d .agents/skills
Documentation by PostHog
Add PostHog product analytics events
Use this skill to add product analytics events (capture calls) that track meaningful user actions in new or changed code. Use it after implementing features or reviewing PRs to ensure key user behaviors are captured. If PostHog is not yet installed, this skill also covers initial SDK setup. Supports any framework or language.
Supported frameworks and languages: Next.js, React Router, Nuxt, Vue, TanStack Start, SvelteKit, Astro, Angular, Django, Flask, FastAPI, Laravel, PHP, Ruby on Rails, Go, Elixir, Android, iOS, Flutter, React Native, Expo, and more.
Instructions
Follow these steps IN ORDER:
STEP 1: Analyze the codebase and detect the platform.
Look for dependency files (package.json, pubspec.yaml, Podfile, Package.swift, requirements.txt, Gemfile, composer.json, go.mod, mix.exs, etc.) to determine the framework and language.
Look for lockfiles (pnpm-lock.yaml, package-lock.json, yarn.lock, bun.lockb, go.sum, pubspec.lock, Podfile.lock, Package.resolved, mix.lock) to determine the package manager.
Check for existing PostHog setup. If PostHog is already installed and initialized, skip to STEP 5.
STEP 2: Research integration. (Skip if PostHog is already set up.) 2.1. Find the reference file below that matches the detected framework — it is the source of truth for SDK initialization, provider setup, and event capture patterns. Read it now. 2.2. If no reference matches, fall back to your general knowledge and web search. Use posthog.com/docs as the primary search source.
STEP 3: Install the PostHog SDK. (Skip if PostHog is already set up.)
Add the PostHog SDK package for the detected platform. Do not manually edit package.json — use the package manager's install command.
STEP 4: Initialize PostHog. (Skip if PostHog is already set up.)
Follow the framework reference for where and how to initialize. This varies significantly by framework (e.g., instrumentation-client.ts for Next.js 15.3+, AppConfig.ready() for Django, create_app() for Flask).
STEP 5: Plan event tracking.
From the project's file list, select between 10 and 15 files that might have interesting business value for event tracking, especially conversion and churn events.
Also look for files related to login that could be used for identifying users, along with error handling.
Find any existing
posthog.capture()code. Make note of event name formatting. Don't duplicate existing events; supplement them.Track actions only, not pageviews (those can be captured automatically). Exceptions can be made for "viewed"-type events at the top of a conversion funnel.
Server-side events are REQUIRED if the project includes any instrumentable server-side code (API routes, server actions, webhook handlers, payment/checkout completion, authentication endpoints).
STEP 6: Implement event capture.
For each planned event, add
posthog.capture()calls with useful properties.If a file already has existing integration code for other tools or services, don't overwrite or remove that code. Place PostHog code below it.
Do not alter the fundamental architecture of existing files. Make additions minimal and targeted.
You must read a file immediately before attempting to write it.
STEP 7: Identify users.
Add PostHog
identify()calls on the client side during login and signup events. Use the contents of login and signup forms to identify users on submit.If both frontend and backend exist, pass the client-side session and distinct ID using
X-POSTHOG-DISTINCT-IDandX-POSTHOG-SESSION-IDheaders to the server-side code. On the server side, make sure events have a matching distinct ID.
STEP 8: Add error tracking.
Add PostHog exception capture error tracking to relevant files, particularly around critical user flows and API boundaries.
STEP 9: Set up environment variables.
Check if the project already has PostHog environment variables configured (e.g. in
.env,.env.local, or framework-specific env files). If valid values already exist, skip this step.If the PostHog project token is missing, use the PostHog MCP server's
projects-gettool to retrieve the project'sapi_token. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.For the PostHog host URL: check the
projects-getMCP response for aregionfield —USmaps tohttps://us.i.posthog.com,EUmaps tohttps://eu.i.posthog.com. If the region is not available from the MCP response or from existing project configuration, ask the user: "Are you on PostHog US Cloud or EU Cloud?" Do not assume US Cloud.Write these values to the appropriate env file using the framework's naming convention.
Reference these environment variables in code instead of hardcoding them.
STEP 10: Verify and clean up.
Check the project for errors. Look for type checking or build scripts in package.json.
Ensure any components created were actually used.
Run any linter or prettier-like scripts found in the package.json, but ONLY on the files you have edited or created during this session. Never run formatting or linting across the entire project's codebase.
Reference files
references/EXAMPLE-next-app-router.md- next-app-router example project codereferences/EXAMPLE-next-pages-router.md- next-pages-router example project codereferences/EXAMPLE-react-react-router-6.md- react-react-router-6 example project codereferences/EXAMPLE-react-react-router-7-framework.md- react-react-router-7-framework example project codereferences/EXAMPLE-react-react-router-7-data.md- react-react-router-7-data example project codereferences/EXAMPLE-react-react-router-7-declarative.md- react-react-router-7-declarative example project codereferences/EXAMPLE-nuxt-3-6.md- nuxt-3-6 example project codereferences/EXAMPLE-nuxt-4.md- nuxt-4 example project codereferences/EXAMPLE-vue-3.md- vue-3 example project codereferences/EXAMPLE-react-tanstack-router-file-based.md- react-tanstack-router-file-based example project codereferences/EXAMPLE-react-tanstack-router-code-based.md- react-tanstack-router-code-based example project codereferences/EXAMPLE-tanstack-start.md- tanstack-start example project codereferences/EXAMPLE-sveltekit.md- sveltekit example project codereferences/EXAMPLE-astro-static.md- astro-static example project codereferences/EXAMPLE-astro-view-transitions.md- astro-view-transitions example project codereferences/EXAMPLE-astro-ssr.md- astro-ssr example project codereferences/EXAMPLE-astro-hybrid.md- astro-hybrid example project codereferences/EXAMPLE-angular.md- angular example project codereferences/EXAMPLE-django.md- django example project codereferences/EXAMPLE-flask.md- flask example project codereferences/EXAMPLE-fastapi.md- fastapi example project codereferences/EXAMPLE-python.md- python example project codereferences/EXAMPLE-laravel.md- laravel example project codereferences/EXAMPLE-php.md- php example project codereferences/EXAMPLE-ruby-on-rails.md- ruby-on-rails example project codereferences/EXAMPLE-ruby.md- ruby example project codereferences/EXAMPLE-android.md- android example project codereferences/EXAMPLE-swift.md- swift example project codereferences/EXAMPLE-react-native.md- react-native example project codereferences/EXAMPLE-expo.md- expo example project codereferences/next-js.md- Next.jsreferences/react-router-v6.md- React router v6references/react-router-v7-framework-mode.md- React router v7 framework mode (remix v3)references/react-router-v7-data-mode.md- React router v7 data modereferences/react-router-v7-declarative-mode.md- React router v7 declarative modereferences/nuxt-js-3-6.md- Nuxt.js (v3.0 to v3.6)references/nuxt-js.md- Nuxt.jsreferences/vue-js.md- Vue.jsreferences/tanstack-start.md- Tanstack startreferences/svelte.md- Sveltereferences/astro.md- Astroreferences/angular.md- Angularreferences/django.md- Djangoreferences/flask.md- Flaskreferences/python.md- Pythonreferences/posthog-python.md- PostHog python SDKreferences/dotnet.md- .netreferences/elixir.md- Elixirreferences/go.md- Goreferences/laravel.md- Laravelreferences/php.md- Phpreferences/ruby-on-rails.md- Ruby on railsreferences/ruby.md- Rubyreferences/android.md- Androidreferences/ios.md- Iosreferences/usage.md- Ios SDK usagereferences/configuration.md- Ios SDK configurationreferences/flutter.md- Flutterreferences/react-native.md- React nativereferences/identify-users.md- Identify usersreferences/COMMANDMENTS.md- Framework-specific rules the integration must follow
Each framework reference contains SDK-specific installation, initialization, and usage patterns. Find the one matching the user's stack.
Key principles
Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
Minimal changes: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
Match the docs: Follow the framework reference's initialization and capture patterns exactly.
Files
- ATTRIBUTION.mdAdded by AutoGineer970 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md9.6 KiB
- references/COMMANDMENTS.md1.5 KiB
- references/EXAMPLE-android.md49.8 KiB
- references/EXAMPLE-angular.md23.1 KiB
- references/EXAMPLE-astro-hybrid.md27.5 KiB
- references/EXAMPLE-astro-ssr.md27.6 KiB
- references/EXAMPLE-astro-static.md19.6 KiB
- references/EXAMPLE-astro-view-transitions.md23.3 KiB
- references/EXAMPLE-django.md30.7 KiB
- references/EXAMPLE-expo.md35.1 KiB
- references/EXAMPLE-fastapi.md40.9 KiB
- references/EXAMPLE-flask.md32.4 KiB
- references/EXAMPLE-laravel.md59.3 KiB
- references/EXAMPLE-next-app-router.md17.6 KiB
- references/EXAMPLE-next-pages-router.md19.1 KiB
- references/EXAMPLE-nuxt-3-6.md22.3 KiB
- references/EXAMPLE-nuxt-4.md28.9 KiB
- references/EXAMPLE-php.md13.0 KiB
- references/EXAMPLE-python.md11.6 KiB
- references/EXAMPLE-react-native.md46.0 KiB
- references/EXAMPLE-react-react-router-6.md13.5 KiB
- references/EXAMPLE-react-react-router-7-data.md20.1 KiB
- references/EXAMPLE-react-react-router-7-declarative.md15.0 KiB
- references/EXAMPLE-react-react-router-7-framework.md32.5 KiB
- references/EXAMPLE-react-tanstack-router-code-based.md19.6 KiB
- references/EXAMPLE-react-tanstack-router-file-based.md18.3 KiB
- references/EXAMPLE-ruby-on-rails.md38.0 KiB
- references/EXAMPLE-ruby.md10.0 KiB
- references/EXAMPLE-sveltekit.md18.6 KiB
- references/EXAMPLE-swift.md18.8 KiB
- references/EXAMPLE-tanstack-start.md29.9 KiB
- references/EXAMPLE-vue-3.md17.9 KiB
- references/android.md33.3 KiB
- references/angular.md16.5 KiB
- references/astro.md15.8 KiB
- references/configuration.md17.2 KiB
- references/django.md14.9 KiB
- references/dotnet.md25.8 KiB
- references/elixir.md17.6 KiB
- references/flask.md8.1 KiB
- references/flutter.md42.8 KiB
- references/go.md20.1 KiB
- references/identify-users.md12.2 KiB
- references/ios.md8.0 KiB
- references/laravel.md13.1 KiB
- references/next-js.md18.3 KiB
- references/nuxt-js-3-6.md11.4 KiB
- references/nuxt-js.md15.1 KiB
- references/php.md23.7 KiB
- references/posthog-python.md69.3 KiB
- references/python.md52.2 KiB
- references/react-native.md59.9 KiB
- references/react-router-v6.md13.6 KiB
- references/react-router-v7-data-mode.md13.5 KiB
- references/react-router-v7-declarative-mode.md13.7 KiB
- references/react-router-v7-framework-mode.md20.2 KiB
- references/ruby-on-rails.md19.7 KiB
- references/ruby.md25.5 KiB
- references/svelte.md14.6 KiB
- references/tanstack-start.md12.8 KiB
- references/usage.md29.2 KiB
- references/vue-js.md13.4 KiB
references/EXAMPLE-android.md
PostHog android Example Project
Repository: https://github.com/PostHog/context-mill Path: example-apps/android
README.md
PostHog Android example
This is an Android example demonstrating PostHog integration with product analytics, session replay, and error tracking using Kotlin and Jetpack Compose.
This example uses the PostHog Android SDK (posthog-android) to provide automatic PostHog integration with built-in error tracking, session replay, and simplified configuration.
Features
Product Analytics: Track user events and behaviors
Session Replay: Record and replay user sessions
Error Tracking: Automatic error capture and crash reporting
User Authentication: Demo login system with PostHog user identification
Event Tracking: Examples of custom event tracking throughout the app
Getting Started
1. Prerequisites
Android Studio (latest stable version)
Android SDK (API level 24 or higher)
JDK 11 or higher
Gradle 8.0 or higher
2. Configure Environment Variables
The PostHog configuration is stored in local.properties (this file is gitignored):
# PostHog configuration
posthog.projectToken=your_posthog_project_token
posthog.host=https://us.i.posthog.comAlternatively, you can configure PostHog in your build.gradle file:
android {
defaultConfig {
buildConfigField "String", "POSTHOG_PROJECT_TOKEN", "\"your_posthog_project_token\""
buildConfigField "String", "POSTHOG_HOST", "\"https://us.i.posthog.com\""
}
}Get your PostHog project token from your PostHog project settings.
3. Build and Run
Open the project in Android Studio
Sync Gradle files
Run the app on an emulator or physical device
Project Structure
├── app/
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/com/example/posthog/
│ │ │ │ ├── BurritoApplication.kt # Application class with PostHog initialization
│ │ │ │ ├── MainActivity.kt # Main activity
│ │ │ │ ├── ui/
│ │ │ │ │ ├── screens/
│ │ │ │ │ │ ├── LoginScreen.kt # Login screen with user identification
│ │ │ │ │ │ ├── BurritoScreen.kt # Demo feature screen with event tracking
│ │ │ │ │ │ └── ProfileScreen.kt # User profile with error tracking demo
│ │ │ │ │ └── components/ # Reusable UI components
│ │ │ │ └── utils/
│ │ │ │ └── PostHogHelper.kt # PostHog utility functions
│ │ │ ├── res/ # Resources (layouts, strings, etc.)
│ │ │ └── AndroidManifest.xml # App manifest
│ │ └── test/ # Unit tests
│ └── build.gradle # App-level Gradle configuration
├── build.gradle # Project-level Gradle configuration
├── settings.gradle # Gradle settings
└── local.properties # Local configuration (gitignored)Key Integration Points
Application Initialization (BurritoApplication.kt)
PostHog is initialized in the Application class to ensure it's available throughout the app lifecycle:
class BurritoApplication : Application() {
override fun onCreate() {
super.onCreate()
val posthogConfig = PostHogConfig(
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST
).apply {
// Enable session replay
sessionReplay = true
// Enable automatic exception capture
captureApplicationLifecycleEvents = true
captureDeepLinks = true
captureScreenViews = true
}
PostHog.setup(this, posthogConfig)
}
}Key Points:
PostHog is initialized in
onCreate()to ensure it's initialized as early as possibleConfiguration is loaded from
BuildConfig(set inbuild.gradle)Session replay, lifecycle events, and screen views are enabled
The Application class must be registered in
AndroidManifest.xml
User Identification (LoginScreen.kt)
Users are identified when they log in:
val posthog = PostHog.getInstance()
fun handleLogin(username: String, password: String) {
// Authenticate user
val success = authenticateUser(username, password)
if (success) {
// Identify the user once on login/sign up
posthog.identify(
distinctId = username,
properties = mapOf(
"username" to username,
"login_method" to "password"
)
)
// Capture login event
posthog.capture("user_logged_in", mapOf(
"username" to username
))
}
}Key Points:
identify()is called once when the user logs in or signs upUser properties can be set during identification
Events are captured using
capture()with event names and propertiesThe
distinctIdshould be a unique identifier for the user
Event Tracking (BurritoScreen.kt)
Custom events are tracked throughout the app:
val posthog = PostHog.getInstance()
fun handleBurritoConsideration() {
// Track custom event
posthog.capture("burrito_considered", mapOf(
"total_considerations" to considerationCount,
"username" to currentUser.username,
"timestamp" to System.currentTimeMillis()
))
// Update user properties
posthog.setUserProperties(mapOf(
"last_burrito_consideration" to System.currentTimeMillis(),
"total_burrito_considerations" to considerationCount
))
}Key Points:
Events are captured with
capture()methodEvent properties provide context about the event
User properties can be updated with
setUserProperties()Properties can be strings, numbers, booleans, or dates
Error Tracking
Errors are captured automatically and can also be tracked manually:
Automatic Error Capture: PostHog automatically captures uncaught exceptions when configured:
val posthogConfig = PostHogConfig(
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST
).apply {
// Automatic exception capture is enabled by default
captureApplicationLifecycleEvents = true
}Manual Error Capture:
val posthog = PostHog.getInstance()
try {
// Risky operation
performRiskyOperation()
} catch (e: Exception) {
// Capture exception manually
posthog.captureException(e, mapOf(
"context" to "burrito_consideration",
"user_id" to currentUser.id
))
}Screen View Tracking
Screen views are automatically tracked when captureScreenViews is enabled. You can also manually track screen views:
val posthog = PostHog.getInstance()
// Manual screen view tracking
posthog.screen("BurritoScreen", mapOf(
"screen_category" to "features",
"user_type" to "premium"
))Session Replay
Session replay is enabled in the PostHog configuration:
val posthogConfig = PostHogConfig(
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST
).apply {
sessionReplay = true
sessionReplayConfig = SessionReplayConfig(
maskAllInputs = false, // Set to true to mask all input fields
maskAllText = false // Set to true to mask all text
)
}Accessing PostHog in Components
PostHog is accessed via the singleton instance:
val posthog = PostHog.getInstance()
posthog.capture("event_name", mapOf("property" to "value"))The instance is available throughout your application after initialization.
Gradle Configuration
App-level build.gradle
android {
defaultConfig {
// PostHog configuration
buildConfigField "String", "POSTHOG_PROJECT_TOKEN", "\"${project.findProperty("posthog.projectToken") ?: ""}\""
buildConfigField "String", "POSTHOG_HOST", "\"${project.findProperty("posthog.host") ?: "https://us.i.posthog.com"}\""
}
}
dependencies {
// PostHog Android SDK
implementation 'com.posthog:posthog-android:3.+'
// Other dependencies...
}Reading from local.properties
The local.properties file is automatically read by Gradle:
def localProperties = new Properties()
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
android {
defaultConfig {
buildConfigField "String", "POSTHOG_PROJECT_TOKEN", "\"${localProperties.getProperty("posthog.projectToken", "")}\""
buildConfigField "String", "POSTHOG_HOST", "\"${localProperties.getProperty("posthog.host", "https://us.i.posthog.com")}\""
}
}Best Practices
Initialize Early: Initialize PostHog in your
Application.onCreate()methodIdentify Once: Call
identify()once when the user logs in or signs upUse Meaningful Event Names: Use clear, descriptive event names (e.g.,
user_logged_ininstead oflogin)Include Context: Add relevant properties to events for better analysis
Handle Errors Gracefully: Don't let PostHog errors break your app
Test in Development: Use a separate PostHog project for development/testing
Respect Privacy: Be mindful of PII (Personally Identifiable Information) in events and properties
Learn More
app/src/main/java/com/example/posthog/BurritoApp.kt
package com.example.posthog
import android.app.Application
import com.posthog.android.PostHogAndroid
import com.posthog.android.PostHogAndroidConfig
class BurritoApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize PostHog early in Application lifecycle
val config = PostHogAndroidConfig(
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST,
).apply {
debug = true
errorTrackingConfig.autoCapture = true
}
PostHogAndroid.setup(this, config)
}
}
app/src/main/java/com/example/posthog/data/User.kt
package com.example.posthog.data
data class User(
val username: String,
val burritoConsiderations: Int = 0
)
app/src/main/java/com/example/posthog/data/UserRepository.kt
package com.example.posthog.data
import android.content.Context
import android.content.SharedPreferences
import org.json.JSONObject
class UserRepository(context: Context) {
private val prefs: SharedPreferences = context.getSharedPreferences(
PREFS_NAME, Context.MODE_PRIVATE
)
companion object {
private const val PREFS_NAME = "burrito_app_prefs"
private const val KEY_CURRENT_USERNAME = "current_username"
private const val KEY_USER_DATA_PREFIX = "user_data_"
}
fun getCurrentUsername(): String? {
return prefs.getString(KEY_CURRENT_USERNAME, null)
}
fun getUser(username: String): User? {
val json = prefs.getString("$KEY_USER_DATA_PREFIX$username", null) ?: return null
return try {
val obj = JSONObject(json)
User(
username = obj.getString("username"),
burritoConsiderations = obj.getInt("burritoConsiderations")
)
} catch (e: Exception) {
null
}
}
fun saveUser(user: User) {
val json = JSONObject().apply {
put("username", user.username)
put("burritoConsiderations", user.burritoConsiderations)
}.toString()
prefs.edit()
.putString("$KEY_USER_DATA_PREFIX${user.username}", json)
.putString(KEY_CURRENT_USERNAME, user.username)
.apply()
}
fun clearCurrentUser() {
prefs.edit()
.remove(KEY_CURRENT_USERNAME)
.apply()
}
fun getCurrentUser(): User? {
val username = getCurrentUsername() ?: return null
return getUser(username)
}
}
app/src/main/java/com/example/posthog/MainActivity.kt
package com.example.posthog
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.posthog.navigation.NavGraph
import com.example.posthog.navigation.Screen
import com.example.posthog.ui.components.AppHeader
import com.example.posthog.ui.components.BottomNavBar
import com.example.posthog.ui.theme.BackgroundGray
import com.example.posthog.ui.theme.PostHogTheme
import com.example.posthog.viewmodel.AuthViewModel
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
PostHogTheme {
BurritoApp()
}
}
}
}
@Composable
fun BurritoApp() {
val navController = rememberNavController()
val viewModel: AuthViewModel = viewModel()
val isAuthenticated by viewModel.isAuthenticated.collectAsState()
val currentUser by viewModel.currentUser.collectAsState()
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
Scaffold(
modifier = Modifier.fillMaxSize(),
topBar = {
AppHeader(
isAuthenticated = isAuthenticated,
username = currentUser?.username,
currentRoute = currentRoute,
onNavigate = { route ->
navController.navigate(route) {
popUpTo(Screen.Home.route)
launchSingleTop = true
}
},
onLogout = {
viewModel.logout()
navController.navigate(Screen.Home.route) {
popUpTo(Screen.Home.route) { inclusive = true }
}
}
)
},
bottomBar = {
BottomNavBar(
isAuthenticated = isAuthenticated,
currentRoute = currentRoute,
onNavigate = { route ->
navController.navigate(route) {
popUpTo(Screen.Home.route)
launchSingleTop = true
}
}
)
},
containerColor = BackgroundGray
) { innerPadding ->
Box(
modifier = Modifier
.fillMaxSize()
.background(BackgroundGray)
.padding(innerPadding)
) {
NavGraph(
navController = navController,
viewModel = viewModel
)
}
}
}
app/src/main/java/com/example/posthog/navigation/NavGraph.kt
package com.example.posthog.navigation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.example.posthog.ui.screens.BurritoScreen
import com.example.posthog.ui.screens.HomeScreen
import com.example.posthog.ui.screens.ProfileScreen
import com.example.posthog.viewmodel.AuthViewModel
sealed class Screen(val route: String) {
object Home : Screen("home")
object Burrito : Screen("burrito")
object Profile : Screen("profile")
}
@Composable
fun NavGraph(
navController: NavHostController,
viewModel: AuthViewModel
) {
val isAuthenticated by viewModel.isAuthenticated.collectAsState()
val currentUser by viewModel.currentUser.collectAsState()
NavHost(
navController = navController,
startDestination = Screen.Home.route
) {
composable(Screen.Home.route) {
HomeScreen(
isAuthenticated = isAuthenticated,
username = currentUser?.username,
onLogin = { username -> viewModel.login(username) }
)
}
composable(Screen.Burrito.route) {
if (!isAuthenticated) {
LaunchedEffect(Unit) {
navController.navigate(Screen.Home.route) {
popUpTo(Screen.Home.route) { inclusive = true }
}
}
} else {
BurritoScreen(
burritoCount = currentUser?.burritoConsiderations ?: 0,
onConsiderBurrito = { viewModel.incrementBurritoCount() }
)
}
}
composable(Screen.Profile.route) {
if (!isAuthenticated) {
LaunchedEffect(Unit) {
navController.navigate(Screen.Home.route) {
popUpTo(Screen.Home.route) { inclusive = true }
}
}
} else {
ProfileScreen(
username = currentUser?.username ?: "",
burritoCount = currentUser?.burritoConsiderations ?: 0
)
}
}
}
}
app/src/main/java/com/example/posthog/ui/components/AppHeader.kt
package com.example.posthog.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.posthog.ui.theme.DarkHeader
import com.example.posthog.ui.theme.ErrorRed
import com.example.posthog.ui.theme.White
@Composable
fun AppHeader(
isAuthenticated: Boolean,
username: String?,
currentRoute: String?,
onNavigate: (String) -> Unit,
onLogout: () -> Unit
) {
Box(
modifier = Modifier
.fillMaxWidth()
.background(DarkHeader)
.padding(horizontal = 16.dp, vertical = 12.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
// App title
Text(
text = "Burrito App",
color = White,
fontSize = 18.sp
)
// User section (right side)
if (isAuthenticated && username != null) {
Row(
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = username,
color = White,
fontSize = 14.sp
)
Button(
onClick = onLogout,
colors = ButtonDefaults.buttonColors(
containerColor = ErrorRed
),
shape = RoundedCornerShape(4.dp),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 6.dp)
) {
Text(
text = "Logout",
color = White,
fontSize = 14.sp
)
}
}
}
}
}
}
app/src/main/java/com/example/posthog/ui/components/BottomNavBar.kt
package com.example.posthog.ui.components
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Person
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.posthog.navigation.Screen
import com.example.posthog.ui.theme.PrimaryBlue
import com.example.posthog.ui.theme.TextGray
import com.example.posthog.ui.theme.White
sealed class BottomNavItem(
val route: String,
val label: String,
val selectedIcon: ImageVector?,
val unselectedIcon: ImageVector?
) {
object Home : BottomNavItem(
route = Screen.Home.route,
label = "Home",
selectedIcon = Icons.Filled.Home,
unselectedIcon = Icons.Outlined.Home
)
object Burrito : BottomNavItem(
route = Screen.Burrito.route,
label = "Burrito",
selectedIcon = null, // We'll use a custom icon or emoji
unselectedIcon = null
)
object Profile : BottomNavItem(
route = Screen.Profile.route,
label = "Profile",
selectedIcon = Icons.Filled.Person,
unselectedIcon = Icons.Outlined.Person
)
}
@Composable
fun BottomNavBar(
isAuthenticated: Boolean,
currentRoute: String?,
onNavigate: (String) -> Unit
) {
val items = if (isAuthenticated) {
listOf(BottomNavItem.Home, BottomNavItem.Burrito, BottomNavItem.Profile)
} else {
listOf(BottomNavItem.Home)
}
NavigationBar(
containerColor = White
) {
items.forEach { item ->
val selected = currentRoute == item.route
NavigationBarItem(
selected = selected,
onClick = { onNavigate(item.route) },
icon = {
if (item.selectedIcon != null && item.unselectedIcon != null) {
Icon(
imageVector = if (selected) item.selectedIcon else item.unselectedIcon,
contentDescription = item.label,
modifier = Modifier.size(24.dp)
)
} else {
// For Burrito, use text emoji as icon
Text(
text = "🌯",
fontSize = 24.sp
)
}
},
label = {
Text(
text = item.label,
fontSize = 12.sp
)
},
colors = NavigationBarItemDefaults.colors(
selectedIconColor = PrimaryBlue,
selectedTextColor = PrimaryBlue,
unselectedIconColor = TextGray,
unselectedTextColor = TextGray,
indicatorColor = PrimaryBlue.copy(alpha = 0.1f)
)
)
}
}
}
app/src/main/java/com/example/posthog/ui/components/StatsCard.kt
package com.example.posthog.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.posthog.ui.theme.LightGray
import com.example.posthog.ui.theme.TextDark
import com.example.posthog.ui.theme.TextGray
@Composable
fun StatsCard(
title: String,
value: String,
modifier: Modifier = Modifier
) {
Column(
modifier = modifier
.fillMaxWidth()
.background(
color = LightGray,
shape = RoundedCornerShape(4.dp)
)
.padding(16.dp)
) {
Text(
text = title,
color = TextGray,
fontSize = 14.sp
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = value,
color = TextDark,
fontSize = 24.sp,
fontWeight = FontWeight.Bold
)
}
}
app/src/main/java/com/example/posthog/ui/screens/BurritoScreen.kt
package com.example.posthog.ui.screens
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.posthog.ui.components.StatsCard
import com.example.posthog.ui.theme.BackgroundGray
import com.example.posthog.ui.theme.SuccessGreen
import com.example.posthog.ui.theme.TextDark
import com.example.posthog.ui.theme.TextGray
import com.example.posthog.ui.theme.White
import kotlinx.coroutines.delay
@Composable
fun BurritoScreen(
burritoCount: Int,
onConsiderBurrito: () -> Unit
) {
var showSuccess by remember { mutableStateOf(false) }
LaunchedEffect(showSuccess) {
if (showSuccess) {
delay(2000)
showSuccess = false
}
}
Box(
modifier = Modifier
.fillMaxSize()
.background(BackgroundGray)
.padding(horizontal = 16.dp)
.verticalScroll(rememberScrollState()),
contentAlignment = Alignment.TopCenter
) {
Column(
modifier = Modifier
.widthIn(max = 600.dp)
.padding(vertical = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
// Main content card
Column(
modifier = Modifier
.fillMaxWidth()
.shadow(
elevation = 4.dp,
shape = RoundedCornerShape(8.dp),
ambientColor = TextDark.copy(alpha = 0.1f),
spotColor = TextDark.copy(alpha = 0.1f)
)
.background(
color = White,
shape = RoundedCornerShape(8.dp)
)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Burrito consideration zone",
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "Take a moment to truly consider the burrito.",
fontSize = 16.sp,
color = TextGray,
textAlign = TextAlign.Center,
lineHeight = 26.sp
)
Spacer(modifier = Modifier.height(24.dp))
Button(
onClick = {
onConsiderBurrito()
showSuccess = true
},
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
colors = ButtonDefaults.buttonColors(
containerColor = SuccessGreen
),
shape = RoundedCornerShape(4.dp)
) {
Text(
text = "Consider the Burrito",
fontSize = 18.sp,
color = White
)
}
if (showSuccess) {
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "You have considered the burrito. Well done!",
color = SuccessGreen,
fontSize = 16.sp,
textAlign = TextAlign.Center
)
}
Spacer(modifier = Modifier.height(24.dp))
Text(
text = "Consideration stats",
fontSize = 20.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark,
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(16.dp))
StatsCard(
title = "Total Burrito Considerations",
value = burritoCount.toString()
)
}
}
}
}
app/src/main/java/com/example/posthog/ui/screens/HomeScreen.kt
package com.example.posthog.ui.screens
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.posthog.ui.theme.BackgroundGray
import com.example.posthog.ui.theme.BorderGray
import com.example.posthog.ui.theme.PrimaryBlue
import com.example.posthog.ui.theme.TextDark
import com.example.posthog.ui.theme.TextGray
import com.example.posthog.ui.theme.White
@Composable
fun HomeScreen(
isAuthenticated: Boolean,
username: String?,
onLogin: (String) -> Unit
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(BackgroundGray)
.padding(horizontal = 16.dp)
.verticalScroll(rememberScrollState()),
contentAlignment = if (isAuthenticated) Alignment.TopCenter else Alignment.Center
) {
Column(
modifier = Modifier
.widthIn(max = 600.dp)
.padding(vertical = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (isAuthenticated && username != null) {
LoggedInContent(username = username)
} else {
LoginForm(onLogin = onLogin)
}
}
}
}
@Composable
private fun LoggedInContent(username: String) {
ContentCard {
Text(
text = "Welcome back, $username!",
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "Ready to consider some burritos?",
fontSize = 16.sp,
color = TextGray,
lineHeight = 26.sp
)
}
}
@Composable
private fun LoginForm(onLogin: (String) -> Unit) {
var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
ContentCard {
Text(
text = "Welcome to Burrito Consideration App",
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(24.dp))
// Username field
Column(modifier = Modifier.fillMaxWidth()) {
Text(
text = "Username",
fontSize = 16.sp,
fontWeight = FontWeight.Medium,
color = TextDark,
modifier = Modifier.padding(bottom = 8.dp)
)
OutlinedTextField(
value = username,
onValueChange = { username = it },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
shape = RoundedCornerShape(4.dp),
colors = OutlinedTextFieldDefaults.colors(
unfocusedBorderColor = BorderGray,
focusedBorderColor = PrimaryBlue,
unfocusedContainerColor = White,
focusedContainerColor = White
)
)
}
Spacer(modifier = Modifier.height(16.dp))
// Password field
Column(modifier = Modifier.fillMaxWidth()) {
Text(
text = "Password",
fontSize = 16.sp,
fontWeight = FontWeight.Medium,
color = TextDark,
modifier = Modifier.padding(bottom = 8.dp)
)
OutlinedTextField(
value = password,
onValueChange = { password = it },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
shape = RoundedCornerShape(4.dp),
colors = OutlinedTextFieldDefaults.colors(
unfocusedBorderColor = BorderGray,
focusedBorderColor = PrimaryBlue,
unfocusedContainerColor = White,
focusedContainerColor = White
)
)
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = {
if (username.isNotBlank()) {
onLogin(username)
}
},
modifier = Modifier
.fillMaxWidth()
.height(48.dp),
colors = ButtonDefaults.buttonColors(
containerColor = PrimaryBlue
),
shape = RoundedCornerShape(4.dp)
) {
Text(
text = "Sign In",
fontSize = 16.sp,
color = White
)
}
Spacer(modifier = Modifier.height(24.dp))
Text(
text = "Note: This is a demo app. Enter any username to sign in.",
fontSize = 14.sp,
color = TextGray,
textAlign = TextAlign.Center,
lineHeight = 21.sp
)
}
}
@Composable
private fun ContentCard(
content: @Composable () -> Unit
) {
Column(
modifier = Modifier
.fillMaxWidth()
.shadow(
elevation = 4.dp,
shape = RoundedCornerShape(8.dp),
ambientColor = TextDark.copy(alpha = 0.1f),
spotColor = TextDark.copy(alpha = 0.1f)
)
.background(
color = White,
shape = RoundedCornerShape(8.dp)
)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
content()
}
}
app/src/main/java/com/example/posthog/ui/screens/ProfileScreen.kt
package com.example.posthog.ui.screens
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.posthog.ui.components.StatsCard
import com.example.posthog.ui.theme.BackgroundGray
import com.example.posthog.ui.theme.TextDark
import com.example.posthog.ui.theme.TextGray
import com.example.posthog.ui.theme.White
@Composable
fun ProfileScreen(
username: String,
burritoCount: Int
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(BackgroundGray)
.padding(horizontal = 16.dp)
.verticalScroll(rememberScrollState()),
contentAlignment = Alignment.TopCenter
) {
Column(
modifier = Modifier
.widthIn(max = 600.dp)
.padding(vertical = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
// Main content card
Column(
modifier = Modifier
.fillMaxWidth()
.shadow(
elevation = 4.dp,
shape = RoundedCornerShape(8.dp),
ambientColor = TextDark.copy(alpha = 0.1f),
spotColor = TextDark.copy(alpha = 0.1f)
)
.background(
color = White,
shape = RoundedCornerShape(8.dp)
)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "User Profile",
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark
)
Spacer(modifier = Modifier.height(24.dp))
// Your Information section
Text(
text = "Your Information",
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark,
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(16.dp))
// Username display
Column(modifier = Modifier.fillMaxWidth()) {
Text(
text = "Username",
fontSize = 14.sp,
color = TextGray
)
Text(
text = username,
fontSize = 20.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark
)
}
Spacer(modifier = Modifier.height(24.dp))
// Stats card
StatsCard(
title = "Total Burrito Considerations",
value = burritoCount.toString()
)
Spacer(modifier = Modifier.height(24.dp))
// Your Burrito Journey section
Text(
text = "Your Burrito Journey",
fontSize = 20.sp,
fontWeight = FontWeight.SemiBold,
color = TextDark,
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = getJourneyMessage(burritoCount),
fontSize = 16.sp,
color = TextGray,
textAlign = TextAlign.Start,
lineHeight = 26.sp,
modifier = Modifier.fillMaxWidth()
)
}
}
}
}
private fun getJourneyMessage(count: Int): String = when {
count == 0 -> "You haven't considered any burritos yet. Start your journey!"
count == 1 -> "You've considered the burrito potential once. The journey begins!"
count in 2..4 -> "You're getting the hang of burrito consideration!"
count in 5..9 -> "You're becoming a burrito consideration expert!"
else -> "You are a true burrito consideration master!"
}
app/src/main/java/com/example/posthog/ui/theme/Color.kt
package com.example.posthog.ui.theme
import androidx.compose.ui.graphics.Color
val PrimaryBlue = Color(0xFF0070F3)
val PrimaryBlueHover = Color(0xFF0051CC)
val SuccessGreen = Color(0xFF28A745)
val SuccessGreenHover = Color(0xFF218838)
val ErrorRed = Color(0xFFDC3545)
val ErrorRedHover = Color(0xFFC82333)
val DarkHeader = Color(0xFF333333)
val DarkHeaderHover = Color(0xFF555555)
val LightGray = Color(0xFFF8F9FA)
val BorderGray = Color(0xFFDDDDDD)
val TextGray = Color(0xFF666666)
val BackgroundGray = Color(0xFFF5F5F5)
val TextDark = Color(0xFF333333)
val White = Color(0xFFFFFFFF)
app/src/main/java/com/example/posthog/ui/theme/Theme.kt
package com.example.posthog.ui.theme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
private val LightColorScheme = lightColorScheme(
primary = PrimaryBlue,
secondary = SuccessGreen,
tertiary = DarkHeader,
background = BackgroundGray,
surface = White,
onPrimary = White,
onSecondary = White,
onTertiary = White,
onBackground = TextDark,
onSurface = TextDark
)
@Composable
fun PostHogTheme(
content: @Composable () -> Unit
) {
MaterialTheme(
colorScheme = LightColorScheme,
typography = Typography,
content = content
)
}app/src/main/java/com/example/posthog/ui/theme/Type.kt
package com.example.posthog.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
// Typography based on design specification
// Uses system font stack (FontFamily.Default maps to Roboto on Android)
val Typography = Typography(
// H1 - Page titles (32sp)
displayLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 32.sp,
lineHeight = 40.sp,
letterSpacing = 0.sp
),
// H2 - Section titles (24sp)
displayMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 24.sp,
lineHeight = 32.sp,
letterSpacing = 0.sp
),
// H3 - Subsection titles (20sp)
displaySmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 20.sp,
lineHeight = 26.sp,
letterSpacing = 0.sp
),
// Body text (16sp with 1.6 line height = 25.6sp)
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 26.sp,
letterSpacing = 0.sp
),
// Small/Note text (14sp)
bodySmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
lineHeight = 21.sp,
letterSpacing = 0.sp
),
// Labels (16sp, medium weight)
labelLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.sp
),
// Button text - Burrito button (18sp)
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 18.sp,
lineHeight = 24.sp,
letterSpacing = 0.sp
),
// Button text - Primary/Logout (16sp/14sp)
titleMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.sp
),
titleSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
lineHeight = 20.sp,
letterSpacing = 0.sp
)
)app/src/main/java/com/example/posthog/viewmodel/AuthViewModel.kt
package com.example.posthog.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.example.posthog.data.User
import com.example.posthog.data.UserRepository
import com.posthog.PostHog
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
class AuthViewModel(application: Application) : AndroidViewModel(application) {
private val repository = UserRepository(application)
private val _currentUser = MutableStateFlow<User?>(null)
val currentUser: StateFlow<User?> = _currentUser.asStateFlow()
private val _isAuthenticated = MutableStateFlow(false)
val isAuthenticated: StateFlow<Boolean> = _isAuthenticated.asStateFlow()
init {
loadCurrentUser()
}
private fun loadCurrentUser() {
viewModelScope.launch {
val user = repository.getCurrentUser()
_currentUser.value = user
_isAuthenticated.value = user != null
}
}
fun login(username: String) {
viewModelScope.launch {
val existingUser = repository.getUser(username)
val user = existingUser ?: User(username = username, burritoConsiderations = 0)
repository.saveUser(user)
_currentUser.value = user
_isAuthenticated.value = true
PostHog.identify(username)
PostHog.capture(event = "user_logged_in")
}
}
fun logout() {
viewModelScope.launch {
PostHog.capture("user_logged_out")
PostHog.reset()
repository.clearCurrentUser()
_currentUser.value = null
_isAuthenticated.value = false
}
}
fun incrementBurritoCount() {
viewModelScope.launch {
val user = _currentUser.value ?: return@launch
val updatedUser = user.copy(burritoConsiderations = user.burritoConsiderations + 1)
repository.saveUser(updatedUser)
_currentUser.value = updatedUser
PostHog.capture(
event = "burrito_considered",
properties = mapOf(
"total_considerations" to updatedUser.burritoConsiderations,
"username" to updatedUser.username
)
)
}
}
}
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an MCP server, Needs Python, Needs Node.js
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- PostHog
- Publisher
- PostHog (Official)
- Source
- PostHog/skills · skills/omnibus/instrument-product-analytics · commit a5d30e7
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by PostHog or PostHog.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download instrument-product-analytics.zip