Skip to content

Conversation

dustinbyrne
Copy link
Contributor

@dustinbyrne dustinbyrne commented Sep 4, 2025

Problem

The Node SDK has some inconsistent behavior with feature flag event tracking. The getFeatureFlag and isFeatureEnabled methods were not respecting the global sendFeatureFlagEvent client option when no method-level override was provided, always defaulting to true instead of using the client configuration.

Additionally, the getFeatureFlagPayload method included a non-functional sendFeatureFlagEvents option that had no effect, potentially causing confusion.

Changes

  • Modified the getFeatureFlag method to respect the global sendFeatureFlagEvent client option when no method-level sendFeatureFlagEvents option is provided
  • Tests validate bothgetFeatureFlag and isFeatureEnabled perform the correct behavior when a global client option is used and when a method-level option overrides it
  • The sendFeatureFlagEvents option in getFeatureFlagPayload method has been marked as deprecated since it has no intended effect

Resolves #2282

Release info Sub-libraries affected

Libraries affected

  • All of them
  • posthog-js (web)
  • posthog-js-lite (web lite)
  • posthog-node
  • posthog-react-native
  • @posthog/react
  • @posthog/ai
  • @posthog/nextjs-config

Checklist

  • Tests for new code
  • Accounted for the impact of any changes across different platforms
  • Accounted for backwards compatibility of any changes (no breaking changes!)
  • Took care not to unnecessarily increase the bundle size

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

`getFeatureFlag` and `isFeatureEnabled` now respect the `sendFeatureFlagEvent` client option if not
explicitly specified when called.
Copy link

vercel bot commented Sep 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
posthog-js Ready Ready Preview Sep 4, 2025 10:10pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

Copy link

github-actions bot commented Sep 4, 2025

Copy link

github-actions bot commented Sep 4, 2025

Size Change: -320 B (-0.01%)

Total Size: 5.23 MB

Filename Size Change
packages/node/dist/edge/index.cjs 109 kB -80 B (-0.07%)
packages/node/dist/edge/index.mjs 108 kB -80 B (-0.07%)
packages/node/dist/node/index.cjs 123 kB -80 B (-0.06%)
packages/node/dist/node/index.mjs 123 kB -80 B (-0.06%)
ℹ️ View Unchanged
Filename Size
packages/ai/dist/anthropic/index.cjs 16.1 kB
packages/ai/dist/anthropic/index.mjs 16 kB
packages/ai/dist/gemini/index.cjs 15.4 kB
packages/ai/dist/gemini/index.mjs 15.2 kB
packages/ai/dist/index.cjs 119 kB
packages/ai/dist/index.mjs 118 kB
packages/ai/dist/langchain/index.cjs 39.6 kB
packages/ai/dist/langchain/index.mjs 39 kB
packages/ai/dist/openai/index.cjs 29 kB
packages/ai/dist/openai/index.mjs 28.8 kB
packages/ai/dist/vercel/index.cjs 21.9 kB
packages/ai/dist/vercel/index.mjs 21.9 kB
packages/browser/dist/all-external-dependencies.js 221 kB
packages/browser/dist/array.full.es5.js 314 kB
packages/browser/dist/array.full.js 377 kB
packages/browser/dist/array.full.no-external.js 395 kB
packages/browser/dist/array.js 176 kB
packages/browser/dist/array.no-external.js 192 kB
packages/browser/dist/crisp-chat-integration.js 1.97 kB
packages/browser/dist/customizations.full.js 16.1 kB
packages/browser/dist/dead-clicks-autocapture.js 12.6 kB
packages/browser/dist/exception-autocapture.js 9.55 kB
packages/browser/dist/external-scripts-loader.js 2.81 kB
packages/browser/dist/intercom-integration.js 2.02 kB
packages/browser/dist/lazy-recorder.js 147 kB
packages/browser/dist/main.js 177 kB
packages/browser/dist/module.full.js 377 kB
packages/browser/dist/module.full.no-external.js 395 kB
packages/browser/dist/module.js 177 kB
packages/browser/dist/module.no-external.js 193 kB
packages/browser/dist/posthog-recorder.js 241 kB
packages/browser/dist/recorder-v2.js 113 kB
packages/browser/dist/recorder.js 113 kB
packages/browser/dist/surveys-preview.js 71.1 kB
packages/browser/dist/surveys.js 79.8 kB
packages/browser/dist/tracing-headers.js 1.84 kB
packages/browser/dist/web-vitals.js 10.4 kB
packages/browser/react/dist/esm/index.js 14.8 kB
packages/browser/react/dist/umd/index.js 17.5 kB
packages/core/dist/eventemitter.js 1.78 kB
packages/core/dist/eventemitter.mjs 571 B
packages/core/dist/featureFlagUtils.js 7.56 kB
packages/core/dist/featureFlagUtils.mjs 5.34 kB
packages/core/dist/gzip.js 1.95 kB
packages/core/dist/gzip.mjs 650 B
packages/core/dist/index.js 71.8 kB
packages/core/dist/index.mjs 59.2 kB
packages/core/dist/testing/index.js 2.93 kB
packages/core/dist/testing/index.mjs 79 B
packages/core/dist/testing/PostHogCoreTestClient.js 3.5 kB
packages/core/dist/testing/PostHogCoreTestClient.mjs 2.11 kB
packages/core/dist/testing/test-utils.js 2.35 kB
packages/core/dist/testing/test-utils.mjs 783 B
packages/core/dist/types.js 8.2 kB
packages/core/dist/types.mjs 5.93 kB
packages/core/dist/utils/bucketed-rate-limiter.js 3.4 kB
packages/core/dist/utils/bucketed-rate-limiter.mjs 2.02 kB
packages/core/dist/utils/index.js 9.33 kB
packages/core/dist/utils/index.mjs 1.95 kB
packages/core/dist/utils/number-utils.js 2 kB
packages/core/dist/utils/number-utils.mjs 735 B
packages/core/dist/utils/promise-queue.js 2 kB
packages/core/dist/utils/promise-queue.mjs 768 B
packages/core/dist/utils/string-utils.js 1.91 kB
packages/core/dist/utils/string-utils.mjs 414 B
packages/core/dist/utils/type-utils.js 5.2 kB
packages/core/dist/utils/type-utils.mjs 1.95 kB
packages/core/dist/vendor/uuidv7.js 8.57 kB
packages/core/dist/vendor/uuidv7.mjs 7 kB
packages/nextjs-config/dist/config.js 5.51 kB
packages/nextjs-config/dist/config.mjs 4.03 kB
packages/nextjs-config/dist/index.js 2.24 kB
packages/nextjs-config/dist/index.mjs 30 B
packages/nextjs-config/dist/utils.js 6.04 kB
packages/nextjs-config/dist/utils.mjs 3.51 kB
packages/nextjs-config/dist/utils.spec.js 723 B
packages/nextjs-config/dist/utils.spec.mjs 455 B
packages/nextjs-config/dist/webpack-plugin.js 3.69 kB
packages/nextjs-config/dist/webpack-plugin.mjs 1.98 kB
packages/react-native/dist/autocapture.js 4.68 kB
packages/react-native/dist/frameworks/wix-navigation.js 1.3 kB
packages/react-native/dist/hooks/useFeatureFlag.js 1.49 kB
packages/react-native/dist/hooks/useFeatureFlags.js 821 B
packages/react-native/dist/hooks/useNavigationTracker.js 2.46 kB
packages/react-native/dist/hooks/usePostHog.js 467 B
packages/react-native/dist/index.js 3.12 kB
packages/react-native/dist/native-deps.js 13.9 kB
packages/react-native/dist/optional/OptionalAsyncStorage.js 299 B
packages/react-native/dist/optional/OptionalExpoApplication.js 377 B
packages/react-native/dist/optional/OptionalExpoDevice.js 347 B
packages/react-native/dist/optional/OptionalExpoFileSystem.js 386 B
packages/react-native/dist/optional/OptionalExpoFileSystemLegacy.js 423 B
packages/react-native/dist/optional/OptionalExpoLocalization.js 383 B
packages/react-native/dist/optional/OptionalReactNativeDeviceInfo.js 415 B
packages/react-native/dist/optional/OptionalReactNativeLocalize.js 303 B
packages/react-native/dist/optional/OptionalReactNativeNavigation.js 415 B
packages/react-native/dist/optional/OptionalReactNativeNavigationWix.js 443 B
packages/react-native/dist/optional/OptionalReactNativeSafeArea.js 644 B
packages/react-native/dist/optional/OptionalSessionReplay.js 455 B
packages/react-native/dist/posthog-rn.js 28.7 kB
packages/react-native/dist/PostHogContext.js 329 B
packages/react-native/dist/PostHogProvider.js 4.77 kB
packages/react-native/dist/storage.js 3.39 kB
packages/react-native/dist/surveys/components/BottomSection.js 1.34 kB
packages/react-native/dist/surveys/components/Cancel.js 909 B
packages/react-native/dist/surveys/components/ConfirmationMessage.js 1.63 kB
packages/react-native/dist/surveys/components/QuestionHeader.js 1.11 kB
packages/react-native/dist/surveys/components/QuestionTypes.js 10.1 kB
packages/react-native/dist/surveys/components/SurveyModal.js 3.95 kB
packages/react-native/dist/surveys/components/Surveys.js 6.18 kB
packages/react-native/dist/surveys/getActiveMatchingSurveys.js 3.48 kB
packages/react-native/dist/surveys/icons.js 7.76 kB
packages/react-native/dist/surveys/index.js 600 B
packages/react-native/dist/surveys/PostHogSurveyProvider.js 5.61 kB
packages/react-native/dist/surveys/surveys-utils.js 8.96 kB
packages/react-native/dist/surveys/useActivatedSurveys.js 3.38 kB
packages/react-native/dist/surveys/useSurveyStorage.js 2.16 kB
packages/react-native/dist/types.js 70 B
packages/react-native/dist/version.js 129 B
packages/react/dist/esm/index.js 14.8 kB
packages/react/dist/umd/index.js 17.5 kB
packages/web/dist/index.cjs 13.8 kB
packages/web/dist/index.mjs 13.7 kB
tooling/rollup-utils/dist/index.js 1.17 kB

compressed-size-action

…load` as deprecated

This option is not used.
@dustinbyrne dustinbyrne force-pushed the fix/node-global-send-feature-flags branch from 59e96fa to dae80f8 Compare September 4, 2025 22:05
@dustinbyrne dustinbyrne requested a review from a team September 4, 2025 22:37
@dmarticus dmarticus moved this to In Review in Feature Flags Sep 4, 2025
@haacked haacked requested a review from Copilot September 4, 2025 22:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes inconsistent feature flag event tracking behavior in the Node SDK by ensuring that getFeatureFlag and isFeatureEnabled methods respect the global sendFeatureFlagEvent client option when no method-level override is provided.

  • Modified getFeatureFlag to use the client's sendFeatureFlagEvent option as default instead of always defaulting to true
  • Added comprehensive tests to verify both methods respect the global client option and allow method-level overrides
  • Deprecated the non-functional sendFeatureFlagEvents option in getFeatureFlagPayload method

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/node/src/client.ts Updates default behavior for sendFeatureFlagEvents to respect client configuration and deprecates unused option
packages/node/test/posthog-node.spec.ts Adds comprehensive test coverage for the new behavior with both global and method-level options
.changeset/thin-pets-cut.md Documents deprecation of unused sendFeatureFlagEvents option
.changeset/shaggy-eyes-attack.md Documents the fix for respecting client sendFeatureFlagEvent option

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@haacked haacked left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Sep 4, 2025
@dustinbyrne dustinbyrne merged commit 20c1b38 into main Sep 4, 2025
41 of 44 checks passed
@dustinbyrne dustinbyrne deleted the fix/node-global-send-feature-flags branch September 4, 2025 23:19
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

bug(flags): posthog-node doesn't honor the global sendFeatureFlagEvent (singular) setting.
2 participants