feat(surveys): add opt-in requireDeviceTypeTargeting config - #680
Open
dmamujee wants to merge 1 commit into
Open
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>
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 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