Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getFeatureFlagPayload wasn't sending the event #226

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- fix: getFeatureFlagPayload wasn't sending the $feature_flag_called event ([#226](https://github.com/PostHog/posthog-android/pull/226))

## 3.11.2 - 2025-02-04

- fix: touches fall back to single touches if out of bounds ([#221](https://github.com/PostHog/posthog-android/pull/221))
Expand Down
6 changes: 5 additions & 1 deletion posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,11 @@ public class PostHog private constructor(
if (!isEnabled()) {
return defaultValue
}
return featureFlags?.getFeatureFlagPayload(key, defaultValue) ?: defaultValue
val value = featureFlags?.getFeatureFlagPayload(key, defaultValue) ?: defaultValue

sendFeatureFlagCalled(key, value)

return value
}

public override fun flush() {
Expand Down
40 changes: 40 additions & 0 deletions posthog/src/test/java/com/posthog/PostHogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,46 @@ internal class PostHogTest {
sut.close()
}

@Test
fun `getFeatureFlagPayload captures feature flag event if enabled`() {
val file = File("src/test/resources/json/basic-decide-with-non-active-flags.json")
val responseDecideApi = file.readText()

val http =
mockHttp(
response =
MockResponse()
.setBody(responseDecideApi),
)
http.enqueue(
MockResponse()
.setBody(""),
)
val url = http.url("/")

val sut = getSut(url.toString(), preloadFeatureFlags = false)

sut.reloadFeatureFlags()

featureFlagsExecutor.shutdownAndAwaitTermination()

// remove from the http queue
http.takeRequest()

assertTrue(sut.getFeatureFlagPayload("thePayload") as Boolean)

queueExecutor.shutdownAndAwaitTermination()

val request = http.takeRequest()
val content = request.body.unGzip()
val batch = serializer.deserialize<PostHogBatchEvent>(content.reader())

val theEvent = batch.batch.first()
assertEquals("\$feature_flag_called", theEvent.event)

sut.close()
}

@Test
fun `isFeatureEnabled captures feature flag event if enabled`() {
val file = File("src/test/resources/json/basic-decide-with-non-active-flags.json")
Expand Down
Loading