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: Add Support For Feature Flag Payloads #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

elliottlawson
Copy link

@elliottlawson elliottlawson commented Aug 4, 2023

This PR enables support for retrieving the payloads of feature flags, by leveraging the .../decide/?v=3 query parameter.

The decide version can now be customized by passing a version number in the options parameter when initializing PostHog. This enables the decide call to return the featureFlagPayloads object in the payload. The version defaults to 2 if no value is specified.

Usage:

PostHog::init(
    apiKey: '...',
    options: [
        'decide_version' => 3,
    ],
);

PostHog::getFeatureFlagPayload('payload-flag', 'distinct-id');

 

Tests

Tests are included for the following scenarios

  • Feature flag disabled - payload should be null
  • Feature flag enabled - json payload
  • Feature flag enabled - integer payload
  • Feature flag enabled - string payload

Copy link
Contributor

@neilkakkar neilkakkar left a comment

Choose a reason for hiding this comment

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

I just realised my review from a few months ago is still sitting in 'pending' and you can't actually see it 🤦 - sorry about this!

@@ -87,6 +92,7 @@ public function __construct(
$this->featureFlags = [];
$this->groupTypeMapping = [];
$this->distinctIdsFeatureFlagsReported = new SizeLimitedHash(SIZE_LIMIT);
$this->decideVersion = $options["decide_version"] ?? '2';
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey Elliot, instead of making this an option, force update everything to version 3, I'll make a major version release for PHP with your PR, since we are meant to move off of v2 anyway.

* @param array $groupProperties
* @return mixed
*/
public function getFeatureFlagPayload(
Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing blocking a merge here is support for local evaluation -> since getFeatureFlag supports local evaluation, the payload should too.

You can copy the exact code from python: https://github.com/PostHog/posthog-python/blob/master/posthog/client.py#L602 - and compare the get_feature_flag function to the PHP equivalent - they're exactly the same (with some language specific quirks)

You can also then copy all the tests below this line: https://github.com/PostHog/posthog-python/pull/81/files#diff-0e2fa9949bd8d80eecebfa2ff9b994a1bc528fbb003c7e80d104e6d5b3c5f07fR1379-R1384 to make sure it works fine.

Let me know if any questions! :) If this is too much for your bandwidth, let me know too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants