Skip to content
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(flags): Add new debugging property $used_bootstrap_value, $feature_flag_bootstrapped_response and $feature_flag_bootstrapped_payload to $feature_flag_called event #1567

Merged
merged 15 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cypress/e2e/capture.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,31 @@ describe('Event capture', () => {
cy.phCaptures().should('include', '$feature_flag_called')
})

it('captures $feature_flag_called with bootstrapped value properties', () => {
start({
options: {
bootstrap: {
featureFlags: {
'some-feature': 'some-value',
},
featureFlagPayloads: {
'some-feature': 'some-payload',
},
},
},
})

cy.get('[data-cy-feature-flag-button]').click()

cy.phCaptures({ full: true }).then((captures) => {
const flagCallEvents = captures.filter((capture) => capture.event === '$feature_flag_called')
expect(flagCallEvents.length).to.eq(1)
const flagCallEvent = flagCallEvents[0]
expect(flagCallEvent.properties.$feature_flag_bootstrapped_response).to.equal('some-value')
expect(flagCallEvent.properties.$feature_flag_bootstrapped_payload).to.equal('some-payload')
})
})

it('captures rage clicks', () => {
start({ options: { rageclick: true } })

Expand Down
9 changes: 8 additions & 1 deletion src/posthog-featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,14 @@ export class PostHogFeatureFlags {
}
this.instance.persistence?.register({ [FLAG_CALL_REPORTED]: flagCallReported })

this.instance.capture('$feature_flag_called', { $feature_flag: key, $feature_flag_response: flagValue })
this.instance.capture('$feature_flag_called', {
$feature_flag: key,
$feature_flag_response: flagValue,
$feature_flag_payload: this.getFeatureFlagPayload(key) || null,
$feature_flag_bootstrapped_response: this.instance.config.bootstrap?.featureFlags?.[key] || null,
havenbarnes marked this conversation as resolved.
Show resolved Hide resolved
$feature_flag_bootstrapped_payload:
this.instance.config.bootstrap?.featureFlagPayloads?.[key] || null,
})
}
}
return flagValue
Expand Down
Loading