feat(surveys): add opt-in requireDeviceTypeTargeting config - #680
Conversation
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>
|
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 |
|
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 Also, if you want to make sure your survey displays only on mobile, doesn't the option |
💡 Motivation and Context
Android currently treats surveys with missing or empty
conditions.deviceTypesas 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.requireDeviceTypeTargetingflag so apps can require explicit device-type targeting before a survey is eligible.When
false(default): preserve existing behavior — missing/emptydeviceTypesstill match.When
true:conditions.deviceTypesdoes not matchconditions.deviceTypesdoes not matchMobile,Tablet, orTV💚 How did you test it?
PostHogSurveysDeviceTypeTargetingTestcovering default allow, require-deny for missing/empty, matching and non-matching explicit device types, and existing match operators (EXACT,IS_NOT,I_CONTAINS):posthog-android:testDebugUnitTest --tests "com.posthog.android.surveys.PostHogSurveysDeviceTypeTargetingTest":posthog:test,:posthog:apiDump, andmake checkFormat📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with Cursor agent assistance. Approach follows an opt-in SDK config on
PostHogSurveysConfigrather 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