Skip to content

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

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

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
@lucasheriques

Copy link
Copy Markdown
Contributor

hey @dmamujee thanks for the PR! I'm Lucas and I work on the Surveys product.

We have a feature request that I think might be better suited for this, potentially. Take a look here

It's about having surveys be able to target specifically SDKs/platforms (i.e. only mobile native, mobile web, etc).

would that fix your use case? because I think having a requireDeviceTypeTargeting option is a little bit odd, and I worry about how to make sure this option is available on the UI too, because it doesn't really seem to fit the current options we have.

Also, if you want to make sure your survey displays only on mobile, doesn't the option device type is Mobile is enough for you now? Can you tell more about the actual product use case you're looking for? I think we can figure out a better solution (maybe it's that feature request)

@marandaneto
marandaneto marked this pull request as draft August 9, 2026 08:16
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.

3 participants