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

feat(flags): Enjoy the benefits of /decide?v=4. $feature_flag_called events contain more details such as flag version #1838

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ test.beforeEach(async ({ context }) => {
// webkit isn't capturing this failed request in the pre-wrapped fetch performance observer records
// [/https:\/\/localhost:\d+\/array\/test%20token\/config.js/, 'script'],
[
/https:\/\/localhost:\d+\/decide\/\?v=3&ip=1&_=\d+&ver=1\.\d\d\d\.\d+&compression=base64/,
/https:\/\/localhost:\d+\/decide\/\?v=4&ip=1&_=\d+&ver=1\.\d\d\d\.\d+&compression=base64/,
'fetch',
],
// webkit isn't capturing this failed request in the pre-wrapped fetch performance observer records
Expand All @@ -158,7 +158,7 @@ test.beforeEach(async ({ context }) => {
[/https:\/\/localhost:\d+\/static\/array.js/, 'script'],
[/https:\/\/localhost:\d+\/array\/test%20token\/config.js/, 'script'],
[
/https:\/\/localhost:\d+\/decide\/\?v=3&ip=1&_=\d+&ver=1\.\d\d\d\.\d+&compression=base64/,
/https:\/\/localhost:\d+\/decide\/\?v=4&ip=1&_=\d+&ver=1\.\d\d\d\.\d+&compression=base64/,
'fetch',
],
[
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/posthog-core.loaded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('loaded() with flags', () => {
expect(instance._send_request).toHaveBeenCalledTimes(1)

expect(instance._send_request.mock.calls[0][0]).toMatchObject({
url: 'https://us.i.posthog.com/decide/?v=3',
url: 'https://us.i.posthog.com/decide/?v=4',
data: {
groups: { org: 'bazinga' },
},
Expand All @@ -64,7 +64,7 @@ describe('loaded() with flags', () => {
expect(instance._send_request).toHaveBeenCalledTimes(1)

expect(instance._send_request.mock.calls[0][0]).toMatchObject({
url: 'https://us.i.posthog.com/decide/?v=3',
url: 'https://us.i.posthog.com/decide/?v=4',
data: {
groups: { org: 'bazinga' },
},
Expand All @@ -77,7 +77,7 @@ describe('loaded() with flags', () => {
expect(instance._send_request).toHaveBeenCalledTimes(2)

expect(instance._send_request.mock.calls[1][0]).toMatchObject({
url: 'https://us.i.posthog.com/decide/?v=3',
url: 'https://us.i.posthog.com/decide/?v=4',
data: {
groups: { org: 'bazinga2' },
},
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ describe('posthog core', () => {
})

expect(sendRequestMock.mock.calls[0][0]).toMatchObject({
url: 'http://localhost/decide/?v=3',
url: 'http://localhost/decide/?v=4',
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/utils/request-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('request-router', () => {
[' https://app.posthog.com ', 'https://us.i.posthog.com/'],
['https://example.com/', 'https://example.com/'],
])('should sanitize the api_host values for "%s"', (apiHost, expected) => {
expect(router(apiHost).endpointFor('api', '/decide?v=3')).toEqual(`${expected}decide?v=3`)
expect(router(apiHost).endpointFor('api', '/decide?v=4')).toEqual(`${expected}decide?v=4`)
})

it('should use the ui_host if provided', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/entrypoints/array.full.es5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// it doesn't include recorder which doesn't support IE11,
// and it doesn't include web-vitals which doesn't support IE11

import 'core-js/features/object/from-entries'

import './surveys'
import './exception-autocapture'
import './tracing-headers'
Expand Down
4 changes: 2 additions & 2 deletions src/posthog-featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export class PostHogFeatureFlags {
this._requestInFlight = true
this.instance._send_request({
method: 'POST',
url: this.instance.requestRouter.endpointFor('api', '/decide/?v=3'),
url: this.instance.requestRouter.endpointFor('api', '/decide/?v=4'),
data,
compression: this.instance.config.disable_compression ? undefined : Compression.Base64,
timeout: this.instance.config.feature_flag_request_timeout_ms,
Expand Down Expand Up @@ -557,7 +557,7 @@ export class PostHogFeatureFlags {
const token = this.instance.config.token
this.instance._send_request({
method: 'POST',
url: this.instance.requestRouter.endpointFor('api', '/decide/?v=3'),
url: this.instance.requestRouter.endpointFor('api', '/decide/?v=4'),
data: {
distinct_id: this.instance.get_distinct_id(),
token,
Expand Down
Loading