Skip to content

feat(surveys): add opt-in requireDeviceTypeTargeting config - #680

Open
dmamujee wants to merge 1 commit into
PostHog:mainfrom
dmamujee:davidmamujee/bra3-187-add-deny-by-default-device-targeting-option-to-posthog
Open

feat(surveys): add opt-in requireDeviceTypeTargeting config#680
dmamujee wants to merge 1 commit into
PostHog:mainfrom
dmamujee:davidmamujee/bra3-187-add-deny-by-default-device-targeting-option-to-posthog

Conversation

@dmamujee

@dmamujee dmamujee commented Aug 6, 2026

Copy link
Copy Markdown

💡 Motivation and Context

Android currently treats surveys with missing or empty conditions.deviceTypes as matching every device. That makes it easy for surveys intended for other platforms (for example web surveys that only set URL/selector conditions) to become eligible on Android, because those web-only conditions are not evaluated by the Android SDK.

This change adds an opt-in PostHogSurveysConfig.requireDeviceTypeTargeting flag so apps can require explicit device-type targeting before a survey is eligible.

When false (default): preserve existing behavior — missing/empty deviceTypes still match.

When true:

  • Missing conditions.deviceTypes does not match
  • Empty conditions.deviceTypes does not match
  • Non-empty conditions continue to use the existing match operators against Mobile, Tablet, or TV

💚 How did you test it?

  • Added PostHogSurveysDeviceTypeTargetingTest covering default allow, require-deny for missing/empty, matching and non-matching explicit device types, and existing match operators (EXACT, IS_NOT, I_CONTAINS)
  • Ran :posthog-android:testDebugUnitTest --tests "com.posthog.android.surveys.PostHogSurveysDeviceTypeTargetingTest"
  • Ran :posthog:test, :posthog:apiDump, and make checkFormat

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with Cursor agent assistance. Approach follows an opt-in SDK config on PostHogSurveysConfig rather than a custom survey predicate, so eligibility stays in the existing device-type matching layer and default behavior remains unchanged for other consumers.

Made with Cursor

Allow apps to exclude surveys that lack explicit device-type
targeting, while preserving the default allow-when-unspecified
behavior for existing consumers.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dmamujee
dmamujee requested a review from a team as a code owner August 6, 2026 20:28
@dustinbyrne

Copy link
Copy Markdown
Contributor

thanks for the pull request @dmamujee!

at first glance this looks reasonable. i'm curious if @PostHog/team-surveys has an opinion on this? i could see this being classified as a bug, in which case we might want to just fix it without the additional configuration option

@marandaneto
marandaneto requested a review from a team August 7, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants