Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/quiet-wolves-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"posthog-php": patch
---

Stop duplicating `distinct_id` inside `/flags` person properties.
4 changes: 2 additions & 2 deletions .github/workflows/sdk-compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:
jobs:
compliance:
name: PostHog SDK compliance tests
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@68498bcf3ae95ac941476e6ca3d42d6086e1c7fd
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@02c049e529001d02f37a534745678e057d371fb0
with:
adapter-dockerfile: "sdk_compliance_adapter/Dockerfile"
adapter-context: "."
test-harness-version: "0.9.0"
test-harness-version: "0.10.0"
11 changes: 1 addition & 10 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ private function doGetFeatureFlagResult(
}

[$personProperties, $groupProperties] = $this->addLocalPersonAndGroupProperties(
$distinctId,
$groups,
$personProperties,
$groupProperties
Expand Down Expand Up @@ -822,7 +821,6 @@ public function getAllFlags(
}

[$personProperties, $groupProperties] = $this->addLocalPersonAndGroupProperties(
$distinctId,
$groups,
$personProperties,
$groupProperties
Expand Down Expand Up @@ -906,7 +904,6 @@ public function evaluateFlags(
}

[$personProperties, $groupProperties] = $this->addLocalPersonAndGroupProperties(
$distinctId,
$groups,
$personProperties,
$groupProperties
Expand Down Expand Up @@ -2086,16 +2083,10 @@ private function message($msg)
}

private function addLocalPersonAndGroupProperties(
string $distinctId,
array $groups,
array $personProperties,
array $groupProperties
): array {
$allPersonProperties = array_merge(
["distinct_id" => $distinctId],
$personProperties
);

$allGroupProperties = [];
if (count($groups) > 0) {
foreach ($groups as $groupName => $groupValue) {
Expand All @@ -2106,6 +2097,6 @@ private function addLocalPersonAndGroupProperties(
}
}

return [$allPersonProperties, $allGroupProperties];
return [$personProperties, $allGroupProperties];
}
}
2 changes: 1 addition & 1 deletion sdk_compliance_adapter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- test-network

test-harness:
image: ghcr.io/posthog/sdk-test-harness:0.9.0
image: ghcr.io/posthog/sdk-test-harness:0.10.0
command: ["run", "--adapter-url", "http://sdk-adapter:8080", "--mock-url", "http://test-harness:8081"]
networks:
- test-network
Expand Down
2 changes: 1 addition & 1 deletion test/FeatureFlagLocalEvaluationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ public function testFeatureFlagsLocalEvaluationForNegatedCohorts()
array(
0 => array(
"path" => "/flags/?v=2",
'payload' => '{"api_key":"random_key","distinct_id":"some-distinct-id","groups":{},"person_properties":{"distinct_id":"some-distinct-id","region":"USA","other":"thing"},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["beta-feature"]}',
'payload' => '{"api_key":"random_key","distinct_id":"some-distinct-id","groups":{},"person_properties":{"region":"USA","other":"thing"},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["beta-feature"]}',
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand Down
14 changes: 7 additions & 7 deletions test/FeatureFlagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function testIsFeatureEnabled($response)
),
1 => array(
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{"distinct_id":"user-id"},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["having_fun"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["having_fun"]}', self::FAKE_API_KEY),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand All @@ -271,7 +271,7 @@ public function testIsFeatureEnabledCapturesFeatureFlagCalledEventWithAdditional
array(
0 => array(
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{"distinct_id":"user-id"},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["simple-test"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["simple-test"]}', self::FAKE_API_KEY),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand All @@ -294,7 +294,7 @@ public function testWhitespacePersonalApiKeyFallsBackToFlagsEndpoint()
[
[
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{"distinct_id":"user-id"},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["simple-test"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["simple-test"]}', self::FAKE_API_KEY),
"extraHeaders" => [0 => 'User-Agent: posthog-php/' . PostHog::VERSION],
"requestOptions" => ["timeout" => 3000, "shouldRetry" => false],
],
Expand Down Expand Up @@ -323,7 +323,7 @@ public function testIsFeatureEnabledGroups($response)
1 => array(
"path" => "/flags/?v=2",
"payload" => sprintf(
'{"api_key":"%s","distinct_id":"user-id","groups":{"company":"id:5"},"person_properties":{"distinct_id":"user-id"},"group_properties":{"company":{"$group_key":"id:5"}},"geoip_disable":false,"flag_keys_to_evaluate":["having_fun"]}',
'{"api_key":"%s","distinct_id":"user-id","groups":{"company":"id:5"},"person_properties":{},"group_properties":{"company":{"$group_key":"id:5"}},"geoip_disable":false,"flag_keys_to_evaluate":["having_fun"]}',
self::FAKE_API_KEY
),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
Expand Down Expand Up @@ -351,7 +351,7 @@ public function testGetFeatureFlag($response)
),
1 => array(
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{"distinct_id":"user-id"},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["multivariate-test"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["multivariate-test"]}', self::FAKE_API_KEY),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand All @@ -371,7 +371,7 @@ public function testGetFeatureFlagCapturesFeatureFlagCalledEventWithAdditionalMe
array(
0 => array(
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{"distinct_id":"user-id"},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["multivariate-test"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"user-id","groups":{},"person_properties":{},"group_properties":{},"geoip_disable":false,"flag_keys_to_evaluate":["multivariate-test"]}', self::FAKE_API_KEY),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand Down Expand Up @@ -420,7 +420,7 @@ public function testGetFeatureFlagGroups($response)
1 => array(
"path" => "/flags/?v=2",
"payload" => sprintf(
'{"api_key":"%s","distinct_id":"user-id","groups":{"company":"id:5"},"person_properties":{"distinct_id":"user-id"},"group_properties":{"company":{"$group_key":"id:5"}},"geoip_disable":false,"flag_keys_to_evaluate":["multivariate-test"]}',
'{"api_key":"%s","distinct_id":"user-id","groups":{"company":"id:5"},"person_properties":{},"group_properties":{"company":{"$group_key":"id:5"}},"geoip_disable":false,"flag_keys_to_evaluate":["multivariate-test"]}',
self::FAKE_API_KEY
),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
Expand Down
6 changes: 3 additions & 3 deletions test/PostHogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ public function testDefaultPropertiesGetAddedProperly(): void
),
1 => array(
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"some_id","groups":{"company":"id:5","instance":"app.posthog.com"},"person_properties":{"distinct_id":"some_id","x1":"y1"},"group_properties":{"company":{"$group_key":"id:5","x":"y"},"instance":{"$group_key":"app.posthog.com"}},"geoip_disable":false,"flag_keys_to_evaluate":["random_key"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"some_id","groups":{"company":"id:5","instance":"app.posthog.com"},"person_properties":{"x1":"y1"},"group_properties":{"company":{"$group_key":"id:5","x":"y"},"instance":{"$group_key":"app.posthog.com"}},"geoip_disable":false,"flag_keys_to_evaluate":["random_key"]}', self::FAKE_API_KEY),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public function testDefaultPropertiesGetAddedProperly(): void
array(
0 => array(
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"some_id","groups":{"company":"id:5"},"person_properties":{"distinct_id":"some_id"},"group_properties":{"company":{"$group_key":"id:5"}},"geoip_disable":false,"flag_keys_to_evaluate":["random_key"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"some_id","groups":{"company":"id:5"},"person_properties":{},"group_properties":{"company":{"$group_key":"id:5"}},"geoip_disable":false,"flag_keys_to_evaluate":["random_key"]}', self::FAKE_API_KEY),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand All @@ -1352,7 +1352,7 @@ public function testDefaultPropertiesGetAddedProperly(): void
array(
0 => array(
"path" => "/flags/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"some_id","groups":{"company":"id:5","instance":"app.posthog.com"},"person_properties":{"distinct_id":"some_id","x1":"y1"},"group_properties":{"company":{"$group_key":"id:5","x":"y"},"instance":{"$group_key":"app.posthog.com"}},"geoip_disable":false,"flag_keys_to_evaluate":["random_key"]}', self::FAKE_API_KEY),
"payload" => sprintf('{"api_key":"%s","distinct_id":"some_id","groups":{"company":"id:5","instance":"app.posthog.com"},"person_properties":{"x1":"y1"},"group_properties":{"company":{"$group_key":"id:5","x":"y"},"instance":{"$group_key":"app.posthog.com"}},"geoip_disable":false,"flag_keys_to_evaluate":["random_key"]}', self::FAKE_API_KEY),
"extraHeaders" => array(0 => 'User-Agent: posthog-php/' . PostHog::VERSION),
"requestOptions" => array("timeout" => 3000, "shouldRetry" => false),
),
Expand Down
Loading