Add PostHog analytics integration for Android and iOS
Implement comprehensive analytics tracking across both platforms: Android (Kotlin): - Add PostHog SDK dependency and initialization in MainActivity - Create expect/actual pattern for cross-platform analytics (commonMain/androidMain/iosMain/jvmMain/jsMain/wasmJsMain) - Track screen views: registration, login, residences, tasks, contractors, documents, notifications, profile - Track key events: user_registered, user_signed_in, residence_created, task_created, contractor_created, document_created - Track paywall events: contractor_paywall_shown, documents_paywall_shown - Track sharing events: residence_shared, contractor_shared - Track theme_changed event iOS (Swift): - Add PostHog iOS SDK via SPM - Create PostHogAnalytics wrapper and AnalyticsEvents constants - Initialize SDK in iOSApp with session replay support - Track same screen views and events as Android - Track user identification after login/registration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,9 @@ kotlin {
|
||||
// implementation(libs.ktor.client.logging)
|
||||
implementation(libs.kotlinx.coroutines.android)
|
||||
implementation(libs.google.billing)
|
||||
|
||||
// PostHog Analytics
|
||||
implementation("com.posthog:posthog-android:3.8.2")
|
||||
}
|
||||
iosMain.dependencies {
|
||||
implementation(libs.ktor.client.darwin)
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.example.casera.data.DataManager
|
||||
import com.example.casera.data.PersistenceManager
|
||||
import com.example.casera.models.CaseraPackageType
|
||||
import com.example.casera.models.detectCaseraPackageType
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MainActivity : ComponentActivity(), SingletonImageLoader.Factory {
|
||||
@@ -71,6 +72,9 @@ class MainActivity : ComponentActivity(), SingletonImageLoader.Factory {
|
||||
// Initialize BillingManager for subscription management
|
||||
billingManager = BillingManager.getInstance(applicationContext)
|
||||
|
||||
// Initialize PostHog Analytics
|
||||
PostHogAnalytics.initialize(application, debug = true) // Set debug=false for release
|
||||
|
||||
// Handle deep link, notification navigation, and file import from intent
|
||||
handleDeepLink(intent)
|
||||
handleNotificationNavigation(intent)
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.example.casera.analytics
|
||||
|
||||
import android.app.Application
|
||||
import com.posthog.PostHog
|
||||
import com.posthog.android.PostHogAndroid
|
||||
import com.posthog.android.PostHogAndroidConfig
|
||||
|
||||
/**
|
||||
* Android implementation of PostHog Analytics.
|
||||
*/
|
||||
actual object PostHogAnalytics {
|
||||
// TODO: Replace with your actual PostHog API key
|
||||
private const val API_KEY = "YOUR_POSTHOG_API_KEY"
|
||||
private const val HOST = "https://us.i.posthog.com"
|
||||
|
||||
private var isInitialized = false
|
||||
private var application: Application? = null
|
||||
|
||||
/**
|
||||
* Initialize PostHog SDK with Application context.
|
||||
* Call this in MainActivity.onCreate() before using other methods.
|
||||
*/
|
||||
fun initialize(application: Application, debug: Boolean = false) {
|
||||
if (isInitialized) return
|
||||
this.application = application
|
||||
|
||||
val config = PostHogAndroidConfig(API_KEY, HOST).apply {
|
||||
captureScreenViews = false // We'll track screens manually
|
||||
captureApplicationLifecycleEvents = true
|
||||
captureDeepLinks = true
|
||||
this.debug = debug
|
||||
|
||||
// Session Replay
|
||||
sessionReplay = true
|
||||
sessionReplayConfig.maskAllTextInputs = true
|
||||
sessionReplayConfig.maskAllImages = false
|
||||
}
|
||||
|
||||
PostHogAndroid.setup(application, config)
|
||||
isInitialized = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize from common code (no-op on Android, use initialize(Application) instead)
|
||||
*/
|
||||
actual fun initialize() {
|
||||
// No-op - Android requires Application context, use initialize(Application) instead
|
||||
}
|
||||
|
||||
actual fun identify(userId: String, properties: Map<String, Any>?) {
|
||||
if (!isInitialized) return
|
||||
PostHog.identify(userId, userProperties = properties)
|
||||
}
|
||||
|
||||
actual fun capture(event: String, properties: Map<String, Any>?) {
|
||||
if (!isInitialized) return
|
||||
PostHog.capture(event, properties = properties)
|
||||
}
|
||||
|
||||
actual fun screen(screenName: String, properties: Map<String, Any>?) {
|
||||
if (!isInitialized) return
|
||||
PostHog.screen(screenName, properties = properties)
|
||||
}
|
||||
|
||||
actual fun reset() {
|
||||
if (!isInitialized) return
|
||||
PostHog.reset()
|
||||
}
|
||||
|
||||
actual fun flush() {
|
||||
if (!isInitialized) return
|
||||
PostHog.flush()
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.example.casera.models.Contractor
|
||||
import com.example.casera.sharing.ContractorSharingManager
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
|
||||
@Composable
|
||||
actual fun rememberShareContractor(): (Contractor) -> Unit {
|
||||
@@ -13,6 +15,8 @@ actual fun rememberShareContractor(): (Contractor) -> Unit {
|
||||
return { contractor: Contractor ->
|
||||
val intent = ContractorSharingManager.createShareIntent(context, contractor)
|
||||
if (intent != null) {
|
||||
// Track contractor shared event
|
||||
PostHogAnalytics.capture(AnalyticsEvents.CONTRACTOR_SHARED)
|
||||
context.startActivity(Intent.createChooser(intent, "Share Contractor"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.example.casera.models.Residence
|
||||
import com.example.casera.sharing.ResidenceSharingManager
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
@@ -25,6 +27,11 @@ actual fun rememberShareResidence(): Pair<ResidenceSharingState, (Residence) ->
|
||||
val intent = ResidenceSharingManager.createShareIntent(context, residence)
|
||||
if (intent != null) {
|
||||
state = ResidenceSharingState(isLoading = false)
|
||||
// Track residence shared event
|
||||
PostHogAnalytics.capture(
|
||||
AnalyticsEvents.RESIDENCE_SHARED,
|
||||
mapOf("method" to "file")
|
||||
)
|
||||
context.startActivity(Intent.createChooser(intent, "Share Residence"))
|
||||
} else {
|
||||
state = ResidenceSharingState(
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.example.casera.analytics
|
||||
|
||||
/**
|
||||
* Common analytics interface for cross-platform event tracking.
|
||||
* Platform-specific implementations use PostHog SDKs.
|
||||
*/
|
||||
expect object PostHogAnalytics {
|
||||
fun initialize()
|
||||
fun identify(userId: String, properties: Map<String, Any>? = null)
|
||||
fun capture(event: String, properties: Map<String, Any>? = null)
|
||||
fun screen(screenName: String, properties: Map<String, Any>? = null)
|
||||
fun reset()
|
||||
fun flush()
|
||||
}
|
||||
|
||||
/**
|
||||
* Analytics event names - use these constants for consistency across the app
|
||||
*/
|
||||
object AnalyticsEvents {
|
||||
// Authentication
|
||||
const val REGISTRATION_SCREEN_SHOWN = "registration_screen_shown"
|
||||
const val USER_REGISTERED = "user_registered"
|
||||
const val USER_SIGNED_IN = "user_signed_in"
|
||||
const val USER_SIGNED_IN_APPLE = "user_signed_in_apple"
|
||||
|
||||
// Residence
|
||||
const val RESIDENCE_SCREEN_SHOWN = "residence_screen_shown"
|
||||
const val NEW_RESIDENCE_SCREEN_SHOWN = "new_residence_screen_shown"
|
||||
const val RESIDENCE_CREATED = "residence_created"
|
||||
const val RESIDENCE_LIMIT_REACHED = "residence_limit_reached"
|
||||
|
||||
// Task
|
||||
const val TASK_SCREEN_SHOWN = "task_screen_shown"
|
||||
const val NEW_TASK_SCREEN_SHOWN = "new_task_screen_shown"
|
||||
const val TASK_CREATED = "task_created"
|
||||
|
||||
// Contractor
|
||||
const val CONTRACTOR_SCREEN_SHOWN = "contractor_screen_shown"
|
||||
const val NEW_CONTRACTOR_SCREEN_SHOWN = "new_contractor_screen_shown"
|
||||
const val CONTRACTOR_CREATED = "contractor_created"
|
||||
const val CONTRACTOR_PAYWALL_SHOWN = "contractor_paywall_shown"
|
||||
|
||||
// Documents
|
||||
const val DOCUMENTS_SCREEN_SHOWN = "documents_screen_shown"
|
||||
const val NEW_DOCUMENT_SCREEN_SHOWN = "new_document_screen_shown"
|
||||
const val DOCUMENT_CREATED = "document_created"
|
||||
const val DOCUMENTS_PAYWALL_SHOWN = "documents_paywall_shown"
|
||||
|
||||
// Sharing
|
||||
const val SHARE_RESIDENCE_SCREEN_SHOWN = "share_residence_screen_shown"
|
||||
const val RESIDENCE_SHARED = "residence_shared"
|
||||
const val SHARE_RESIDENCE_PAYWALL_SHOWN = "share_residence_paywall_shown"
|
||||
const val SHARE_CONTRACTOR_SCREEN_SHOWN = "share_contractor_screen_shown"
|
||||
const val CONTRACTOR_SHARED = "contractor_shared"
|
||||
const val SHARE_CONTRACTOR_PAYWALL_SHOWN = "share_contractor_paywall_shown"
|
||||
|
||||
// Settings
|
||||
const val NOTIFICATION_SETTINGS_SCREEN_SHOWN = "notification_settings_screen_shown"
|
||||
const val SETTINGS_SCREEN_SHOWN = "settings_screen_shown"
|
||||
const val THEME_CHANGED = "theme_changed"
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import com.example.casera.models.ContractorUpdateRequest
|
||||
import com.example.casera.models.Residence
|
||||
import com.example.casera.network.ApiResult
|
||||
import com.example.casera.repository.LookupsRepository
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -53,8 +55,11 @@ fun AddContractorDialog(
|
||||
var expandedResidenceMenu by remember { mutableStateOf(false) }
|
||||
val contractorSpecialties by LookupsRepository.contractorSpecialties.collectAsState()
|
||||
|
||||
// Load residences for picker
|
||||
// Track screen view and load residences for picker
|
||||
LaunchedEffect(Unit) {
|
||||
if (contractorId == null) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.NEW_CONTRACTOR_SCREEN_SHOWN)
|
||||
}
|
||||
residenceViewModel.loadResidences()
|
||||
}
|
||||
|
||||
@@ -91,6 +96,7 @@ fun AddContractorDialog(
|
||||
|
||||
LaunchedEffect(createState) {
|
||||
if (createState is ApiResult.Success) {
|
||||
PostHogAnalytics.capture(AnalyticsEvents.CONTRACTOR_CREATED)
|
||||
onContractorSaved()
|
||||
viewModel.resetCreateState()
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.example.casera.models.TaskCategory
|
||||
import com.example.casera.models.TaskCreateRequest
|
||||
import com.example.casera.models.TaskFrequency
|
||||
import com.example.casera.models.TaskPriority
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -110,6 +112,11 @@ fun AddTaskDialog(
|
||||
showSuggestions = false
|
||||
}
|
||||
|
||||
// Track screen view
|
||||
LaunchedEffect(Unit) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.NEW_TASK_SCREEN_SHOWN)
|
||||
}
|
||||
|
||||
// Set defaults when data loads
|
||||
LaunchedEffect(frequencies) {
|
||||
if (frequencies.isNotEmpty()) {
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.example.casera.network.ApiResult
|
||||
import com.example.casera.repository.LookupsRepository
|
||||
import com.example.casera.ui.subscription.UpgradeFeatureScreen
|
||||
import com.example.casera.utils.SubscriptionHelper
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -58,6 +60,7 @@ fun ContractorsScreen(
|
||||
var isRefreshing by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.CONTRACTOR_SCREEN_SHOWN)
|
||||
viewModel.loadContractors()
|
||||
}
|
||||
|
||||
@@ -182,6 +185,10 @@ fun ContractorsScreen(
|
||||
if (canAdd.allowed) {
|
||||
showAddDialog = true
|
||||
} else {
|
||||
PostHogAnalytics.capture(
|
||||
AnalyticsEvents.CONTRACTOR_PAYWALL_SHOWN,
|
||||
mapOf("current_count" to currentCount)
|
||||
)
|
||||
showUpgradeDialog = true
|
||||
}
|
||||
},
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.example.casera.network.ApiResult
|
||||
import com.example.casera.platform.ImageData
|
||||
import com.example.casera.platform.rememberImagePicker
|
||||
import com.example.casera.platform.rememberCameraPicker
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -103,6 +105,17 @@ fun DocumentFormScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// Track screen view
|
||||
LaunchedEffect(Unit) {
|
||||
if (!isEditMode) {
|
||||
val type = if (initialDocumentType == "warranty") "warranty" else "document"
|
||||
PostHogAnalytics.screen(
|
||||
AnalyticsEvents.NEW_DOCUMENT_SCREEN_SHOWN,
|
||||
mapOf("type" to type)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Load residences if needed
|
||||
LaunchedEffect(needsResidenceSelection) {
|
||||
if (needsResidenceSelection) {
|
||||
@@ -148,6 +161,14 @@ fun DocumentFormScreen(
|
||||
// Handle success
|
||||
LaunchedEffect(operationState) {
|
||||
if (operationState is ApiResult.Success) {
|
||||
if (!isEditMode) {
|
||||
// Track document creation
|
||||
val type = if (selectedDocumentType == "warranty") "warranty" else "document"
|
||||
PostHogAnalytics.capture(
|
||||
AnalyticsEvents.DOCUMENT_CREATED,
|
||||
mapOf("type" to type)
|
||||
)
|
||||
}
|
||||
if (isEditMode) {
|
||||
documentViewModel.resetUpdateState()
|
||||
} else {
|
||||
|
||||
@@ -16,6 +16,8 @@ import com.example.casera.ui.subscription.UpgradeFeatureScreen
|
||||
import com.example.casera.utils.SubscriptionHelper
|
||||
import com.example.casera.viewmodel.DocumentViewModel
|
||||
import com.example.casera.models.*
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -47,6 +49,8 @@ fun DocumentsScreen(
|
||||
var showUpgradeDialog by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
// Track screen view
|
||||
PostHogAnalytics.screen(AnalyticsEvents.DOCUMENTS_SCREEN_SHOWN)
|
||||
// Load warranties by default (documentType="warranty")
|
||||
documentViewModel.loadDocuments(
|
||||
residenceId = residenceId,
|
||||
@@ -180,6 +184,10 @@ fun DocumentsScreen(
|
||||
// Pass residenceId even if null - AddDocumentScreen will handle it
|
||||
onNavigateToAddDocument(residenceId ?: -1, documentType)
|
||||
} else {
|
||||
PostHogAnalytics.capture(
|
||||
AnalyticsEvents.DOCUMENTS_PAYWALL_SHOWN,
|
||||
mapOf("current_count" to currentCount)
|
||||
)
|
||||
showUpgradeDialog = true
|
||||
}
|
||||
},
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.example.casera.ui.components.auth.AuthHeader
|
||||
import com.example.casera.ui.components.common.ErrorCard
|
||||
import com.example.casera.viewmodel.AuthViewModel
|
||||
import com.example.casera.network.ApiResult
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -52,6 +54,9 @@ fun LoginScreen(
|
||||
when (loginState) {
|
||||
is ApiResult.Success -> {
|
||||
val user = (loginState as ApiResult.Success).data.user
|
||||
// Track successful login
|
||||
PostHogAnalytics.capture(AnalyticsEvents.USER_SIGNED_IN, mapOf("method" to "email"))
|
||||
PostHogAnalytics.identify(user.id.toString(), mapOf("email" to (user.email ?: ""), "username" to (user.username ?: "")))
|
||||
onLoginSuccess(user)
|
||||
}
|
||||
else -> {}
|
||||
|
||||
@@ -19,6 +19,8 @@ import com.example.casera.ui.theme.AppRadius
|
||||
import com.example.casera.ui.theme.AppSpacing
|
||||
import com.example.casera.util.DateUtils
|
||||
import com.example.casera.viewmodel.NotificationPreferencesViewModel
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -56,8 +58,9 @@ fun NotificationPreferencesScreen(
|
||||
val defaultTaskOverdueLocalHour = 9 // 9 AM local
|
||||
val defaultDailyDigestLocalHour = 8 // 8 AM local
|
||||
|
||||
// Load preferences on first render
|
||||
// Track screen view and load preferences on first render
|
||||
LaunchedEffect(Unit) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.NOTIFICATION_SETTINGS_SCREEN_SHOWN)
|
||||
viewModel.loadPreferences()
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.example.casera.storage.TokenStorage
|
||||
import com.example.casera.cache.SubscriptionCache
|
||||
import com.example.casera.ui.subscription.UpgradePromptDialog
|
||||
import androidx.compose.runtime.getValue
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -66,8 +68,9 @@ fun ProfileScreen(
|
||||
errorTitle = stringResource(Res.string.profile_update_failed)
|
||||
)
|
||||
|
||||
// Load current user data
|
||||
// Track screen view and load current user data
|
||||
LaunchedEffect(Unit) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.SETTINGS_SCREEN_SHOWN)
|
||||
val token = TokenStorage.getToken()
|
||||
if (token != null) {
|
||||
val authApi = com.example.casera.network.AuthApi()
|
||||
@@ -528,6 +531,11 @@ fun ProfileScreen(
|
||||
currentTheme = currentTheme,
|
||||
onThemeSelected = { theme ->
|
||||
ThemeManager.setTheme(theme)
|
||||
// Track theme change
|
||||
PostHogAnalytics.capture(
|
||||
AnalyticsEvents.THEME_CHANGED,
|
||||
mapOf("theme" to theme.id)
|
||||
)
|
||||
showThemePicker = false
|
||||
},
|
||||
onDismiss = { showThemePicker = false }
|
||||
|
||||
@@ -19,6 +19,8 @@ import com.example.casera.ui.components.auth.AuthHeader
|
||||
import com.example.casera.ui.components.common.ErrorCard
|
||||
import com.example.casera.viewmodel.AuthViewModel
|
||||
import com.example.casera.network.ApiResult
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -44,9 +46,18 @@ fun RegisterScreen(
|
||||
errorTitle = stringResource(Res.string.error_generic)
|
||||
)
|
||||
|
||||
// Track screen view
|
||||
LaunchedEffect(Unit) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.REGISTRATION_SCREEN_SHOWN)
|
||||
}
|
||||
|
||||
LaunchedEffect(createState) {
|
||||
when (createState) {
|
||||
is ApiResult.Success -> {
|
||||
// Track successful registration
|
||||
val user = (createState as ApiResult.Success).data.user
|
||||
PostHogAnalytics.capture(AnalyticsEvents.USER_REGISTERED, mapOf("method" to "email"))
|
||||
PostHogAnalytics.identify(user.id.toString(), mapOf("email" to (user.email ?: ""), "username" to (user.username ?: "")))
|
||||
viewModel.resetRegisterState()
|
||||
onRegisterSuccess()
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ import com.example.casera.cache.SubscriptionCache
|
||||
import com.example.casera.data.DataManager
|
||||
import com.example.casera.util.DateUtils
|
||||
import com.example.casera.platform.rememberShareResidence
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -126,6 +128,11 @@ fun ResidenceDetailScreen(
|
||||
LaunchedEffect(taskAddNewTaskState) {
|
||||
when (taskAddNewTaskState) {
|
||||
is ApiResult.Success -> {
|
||||
// Track task creation
|
||||
PostHogAnalytics.capture(
|
||||
AnalyticsEvents.TASK_CREATED,
|
||||
mapOf("residence_id" to residenceId)
|
||||
)
|
||||
showNewTaskDialog = false
|
||||
taskViewModel.resetAddTaskState()
|
||||
residenceViewModel.loadResidenceTasks(residenceId)
|
||||
|
||||
@@ -24,6 +24,8 @@ import com.example.casera.models.ResidenceUser
|
||||
import com.example.casera.network.ApiResult
|
||||
import com.example.casera.network.ResidenceApi
|
||||
import com.example.casera.storage.TokenStorage
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
@@ -102,6 +104,13 @@ fun ResidenceFormScreen(
|
||||
// Validation errors
|
||||
var nameError by remember { mutableStateOf("") }
|
||||
|
||||
// Track screen view
|
||||
LaunchedEffect(Unit) {
|
||||
if (!isEditMode) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.NEW_RESIDENCE_SCREEN_SHOWN)
|
||||
}
|
||||
}
|
||||
|
||||
// Handle operation state changes
|
||||
LaunchedEffect(operationState) {
|
||||
when (operationState) {
|
||||
@@ -109,6 +118,10 @@ fun ResidenceFormScreen(
|
||||
if (isEditMode) {
|
||||
viewModel.resetUpdateState()
|
||||
} else {
|
||||
// Track residence created
|
||||
PostHogAnalytics.capture(AnalyticsEvents.RESIDENCE_CREATED, mapOf(
|
||||
"residence_type" to (propertyType?.name ?: "unknown")
|
||||
))
|
||||
viewModel.resetCreateState()
|
||||
}
|
||||
onSuccess()
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.example.casera.network.ApiResult
|
||||
import com.example.casera.utils.SubscriptionHelper
|
||||
import com.example.casera.ui.subscription.UpgradePromptDialog
|
||||
import com.example.casera.cache.SubscriptionCache
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -59,7 +61,9 @@ fun ResidencesScreen(
|
||||
return Pair(check.allowed, check.triggerKey)
|
||||
}
|
||||
|
||||
// Track screen view
|
||||
LaunchedEffect(Unit) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.RESIDENCE_SCREEN_SHOWN)
|
||||
viewModel.loadMyResidences()
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import com.example.casera.ui.utils.hexToColor
|
||||
import com.example.casera.viewmodel.TaskCompletionViewModel
|
||||
import com.example.casera.viewmodel.TaskViewModel
|
||||
import com.example.casera.network.ApiResult
|
||||
import com.example.casera.analytics.PostHogAnalytics
|
||||
import com.example.casera.analytics.AnalyticsEvents
|
||||
import casera.composeapp.generated.resources.*
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
@@ -47,6 +49,7 @@ fun TasksScreen(
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
PostHogAnalytics.screen(AnalyticsEvents.TASK_SCREEN_SHOWN)
|
||||
viewModel.loadTasks()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.casera.analytics
|
||||
|
||||
/**
|
||||
* iOS implementation of PostHog Analytics.
|
||||
* Note: The actual PostHog SDK calls are made from Swift code.
|
||||
* This is a stub that does nothing - iOS uses the native Swift wrapper directly.
|
||||
*/
|
||||
actual object PostHogAnalytics {
|
||||
actual fun initialize() {
|
||||
// iOS initialization is done in Swift via PostHogAnalytics.swift
|
||||
}
|
||||
|
||||
actual fun identify(userId: String, properties: Map<String, Any>?) {
|
||||
// iOS uses Swift PostHogAnalytics.shared.identify() directly
|
||||
}
|
||||
|
||||
actual fun capture(event: String, properties: Map<String, Any>?) {
|
||||
// iOS uses Swift PostHogAnalytics.shared.capture() directly
|
||||
}
|
||||
|
||||
actual fun screen(screenName: String, properties: Map<String, Any>?) {
|
||||
// iOS uses Swift PostHogAnalytics.shared.screen() directly
|
||||
}
|
||||
|
||||
actual fun reset() {
|
||||
// iOS uses Swift PostHogAnalytics.shared.reset() directly
|
||||
}
|
||||
|
||||
actual fun flush() {
|
||||
// iOS uses Swift PostHogAnalytics.shared.flush() directly
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.example.casera.analytics
|
||||
|
||||
/**
|
||||
* JS/Web implementation of PostHog Analytics.
|
||||
* Currently a no-op stub - could be implemented with PostHog JS SDK.
|
||||
*/
|
||||
actual object PostHogAnalytics {
|
||||
actual fun initialize() {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun identify(userId: String, properties: Map<String, Any>?) {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun capture(event: String, properties: Map<String, Any>?) {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun screen(screenName: String, properties: Map<String, Any>?) {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun reset() {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun flush() {
|
||||
// No-op for web
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.example.casera.analytics
|
||||
|
||||
/**
|
||||
* JVM/Desktop implementation of PostHog Analytics.
|
||||
* Currently a no-op stub - PostHog doesn't have a native JVM SDK.
|
||||
*/
|
||||
actual object PostHogAnalytics {
|
||||
actual fun initialize() {
|
||||
// No-op for desktop
|
||||
}
|
||||
|
||||
actual fun identify(userId: String, properties: Map<String, Any>?) {
|
||||
// No-op for desktop
|
||||
}
|
||||
|
||||
actual fun capture(event: String, properties: Map<String, Any>?) {
|
||||
// No-op for desktop
|
||||
}
|
||||
|
||||
actual fun screen(screenName: String, properties: Map<String, Any>?) {
|
||||
// No-op for desktop
|
||||
}
|
||||
|
||||
actual fun reset() {
|
||||
// No-op for desktop
|
||||
}
|
||||
|
||||
actual fun flush() {
|
||||
// No-op for desktop
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.example.casera.analytics
|
||||
|
||||
/**
|
||||
* WasmJS/Web implementation of PostHog Analytics.
|
||||
* Currently a no-op stub - could be implemented with PostHog JS SDK.
|
||||
*/
|
||||
actual object PostHogAnalytics {
|
||||
actual fun initialize() {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun identify(userId: String, properties: Map<String, Any>?) {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun capture(event: String, properties: Map<String, Any>?) {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun screen(screenName: String, properties: Map<String, Any>?) {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun reset() {
|
||||
// No-op for web
|
||||
}
|
||||
|
||||
actual fun flush() {
|
||||
// No-op for web
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user