Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/lazy-pandas-wander.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'posthog': minor
'posthog-android': minor
---

Session replay now respects the freshly-fetched session-recording remote config at cold start. Previously a returning user whose cached flag said "on" could record an opening window even when the server's config said "off". Snapshots captured before the first remote config response are buffered; once the config resolves they are migrated to the send pipeline if the session is recordable (kept buffering until the minimum-duration window is met), or dropped if the flag is off or the session is sampled out. A fresh "off" now also stops an in-progress recording instead of waiting for the next session rotation, and a mid-session resume re-emits a full-snapshot keyframe. When the first remote config can't be fetched (e.g. the device is offline), recording falls back to the disk-cached flag rather than discarding the session.

API: `PostHogIntegration.onRemoteConfig()` now takes a `loaded: Boolean = true` parameter (true when a live remote config was applied, false on a terminal fetch failure), replacing the separate `onRemoteConfigFailed()` callback. Integrations that implement `PostHogIntegration` and override these methods should migrate to the single `onRemoteConfig(loaded)`.
4 changes: 2 additions & 2 deletions posthog-android/api/posthog-android.api
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class com/posthog/android/replay/PostHogReplayIntegration : com/pos
public fun install (Lcom/posthog/PostHogInterface;)V
public fun isActive ()Z
public fun onEvent (Ljava/lang/String;Ljava/util/Map;)V
public fun onRemoteConfig ()V
public fun onRemoteConfig (Z)V
public fun onSessionIdChanged ()V
public fun start (Z)V
public fun stop ()V
Expand Down Expand Up @@ -127,7 +127,7 @@ public final class com/posthog/android/surveys/PostHogSurveysIntegration : com/p
public fun <init> (Landroid/content/Context;Lcom/posthog/PostHogConfig;)V
public fun install (Lcom/posthog/PostHogInterface;)V
public fun onEvent (Ljava/lang/String;Ljava/util/Map;)V
public fun onRemoteConfig ()V
public fun onRemoteConfig (Z)V
public fun onSurveysLoaded (Ljava/util/List;)V
public fun uninstall ()V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ internal interface PostHogReplayBufferDelegate {
*/
val isBuffering: Boolean

/**
* Whether session recording is currently active. The queue drops snapshots routed to the
* persisted queue while this is false, so a snapshot captured just before recording stopped
* (e.g. a fresh remote config rejecting the cached flag) cannot leak to the network.
*/
val isActive: Boolean

/**
* Called after a snapshot was added to the buffer.
* The delegate should check threshold conditions and schedule
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ internal class PostHogReplayQueue internal constructor(

override fun add(event: PostHogEvent) {
if (bufferDelegate?.isBuffering != true) {
innerQueue.add(event)
if (shouldPersist()) {
innerQueue.add(event)
}
return
}

Expand All @@ -66,12 +68,17 @@ internal class PostHogReplayQueue internal constructor(
bufferQueue.add(event)
config.logger.log("Buffered replay event '${event.event}'. Buffer depth: ${bufferQueue.depth}")
bufferDelegate?.onReplayBufferSnapshot(this)
} else {
} else if (shouldPersist()) {
innerQueue.add(event)
}
}
}

// A delegate that reports recording inactive means a snapshot slipped through after recording
// stopped (e.g. a fresh-false remote config); drop it rather than persist/send it. With no
// delegate (recording not yet wired) the queue persists as before.
private fun shouldPersist(): Boolean = bufferDelegate?.isActive != false

override fun flush() {
if (bufferDelegate?.isBuffering == true) {
config.logger.log("Replay queue flush suppressed β€” still buffering")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ internal class PostHogLogCatIntegration(private val config: PostHogAndroidConfig
logcatThread?.start()
}

override fun onRemoteConfig() {
override fun onRemoteConfig(loaded: Boolean) {
// Only react to a live config; a failed attempt applies no fresh values.
if (!loaded) {
return
}
val captureLogcat = config.remoteConfigHolder?.isConsoleLogRecordingEnabled() ?: true
if (captureLogcat) {
postHog?.let { install(it) }
Expand Down
Loading
Loading