-
Notifications
You must be signed in to change notification settings - Fork 140
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
chore: small readability refactor to getActiveMatchingSurveys #1718
chore: small readability refactor to getActiveMatchingSurveys #1718
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR modifies the survey targeting logic in posthog-js by refactoring the getActiveMatchingSurveys
method for improved readability and changing how internal targeting flags are evaluated.
- Changed internal targeting flag logic in
src/posthog-surveys.ts
to use OR instead of AND, allowing surveys to show if either override check passes or feature flag is enabled - Extracted feature flag checks into new private method
isSurveyFeatureFlagEnabled
for better code organization - Simplified event/action condition checks using nullish coalescing operator
- Reordered imports for better code structure
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
const internalTargetingFlagCheck = | ||
survey.internal_targeting_flag_key && !overrideInternalTargetingFlagCheck | ||
? this.instance.featureFlags.isFeatureEnabled(survey.internal_targeting_flag_key) | ||
: true | ||
overrideInternalTargetingFlagCheck || | ||
this.isSurveyFeatureFlagEnabled(survey.internal_targeting_flag_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: This changes the behavior of internal targeting flags. Previously required flag check if no override, now passes if either condition is true. May cause surveys to show more frequently than intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is incorrect
in the first version, we had:
When overrideInternalTargetingFlagCheck
is true:
- First version: returns
true
(second part of the ternary) - Second version: returns
true
(first part of OR condition)
When overrideInternalTargetingFlagCheck
is false (i.e. we call isSurveyFeatureFlagEnabled
):
If survey.internal_targeting_flag_key
is null
:
- First version: returns
true
(second part of the ternary) - Second version: returns
true
(sinceisSurveyFeatureFlagEnabled
returns true)
If survey.internal_targeting_flag_key
is defined:
- First version: returns
isFeatureEnabled(survey.internal_targeting_flag_key)
- Second version: returns
isFeatureEnabled(survey.internal_targeting_flag_key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have unit tests for that so the change will break if not correct?
one thing to pay attention to is that the former uses &&
and you use ||
.
the other thing is that your description says: 'When overrideInternalTargetingFlagCheck is true
', but the former does '!
overrideInternalTargetingFlagCheck', so I'm not confident that it's the same without running the code, can you double check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, there are unit tests for getActiveMatchingSurveys
here, which is why I relied on them to keep the same functionality
Size Change: -2.15 kB (-0.07%) Total Size: 3.3 MB
ℹ️ View Unchanged
|
@pauldambra slowly killing off some bytes from surveys part 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
Changes
small readability refactor for
getActiveMatchingSurveys
Checklist