Repository navigation
feat(groups): add disableGeoip option to groupIdentify #263
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "posthog-php": minor | ||
| --- | ||
|
|
||
| Add a client-wide disableGeoip option and per-call overrides for events and remote feature flag evaluation. Keep the default false for compatibility with existing PHP releases; set disableGeoip to true to opt into Node-style GeoIP behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Upgrade notes | ||
|
|
||
| ## GeoIP configuration | ||
|
|
||
| The SDK keeps `disableGeoip => false` by default for compatibility with existing | ||
| PHP releases. GeoIP enrichment remains enabled unless you explicitly disable it. | ||
| Ideally this default will change to `true` in the next major release, matching Node. | ||
|
|
||
| To opt into Node's default behavior now, disable GeoIP enrichment at initialization: | ||
|
|
||
| ```php | ||
| PostHog::init('project-api-key', ['disableGeoip' => true]); | ||
| ``` | ||
|
|
||
| Events then carry `properties['$geoip_disable'] = true`, and remote feature flag | ||
| requests send `geoip_disable: true`. This prevents PostHog from attributing the | ||
| server's location to users and groups. GeoIP-based feature flag targeting can also | ||
| produce different results when you enable this option. | ||
|
|
||
| The same option is available in the `Client` constructor. A per-call `disableGeoip` | ||
| option overrides the client setting for `capture()`, `identify()`, `alias()`, and | ||
| `groupIdentify()`: | ||
|
|
||
| ```php | ||
| PostHog::groupIdentify([ | ||
| 'groupType' => 'company', | ||
| 'groupKey' => 'acme', | ||
| 'properties' => ['name' => 'Acme'], | ||
| 'disableGeoip' => false, | ||
| ]); | ||
| ``` | ||
|
|
||
| `evaluateFlags()` and `Client::flags()` also accept a `disableGeoip` override. | ||
| Omitting it or passing `null` inherits the client setting. A snapshot retains its | ||
| override for exposure events, including snapshots filtered with `only()` or | ||
| `onlyAccessed()`. | ||
|
|
||
| Setting `disableGeoip` to `false` prevents the SDK from adding `$geoip_disable`; | ||
| it does not remove a manually supplied event property. When GeoIP is disabled, | ||
| the SDK sets `$geoip_disable` to `true` even if a caller supplied `false` in | ||
| properties. The `before_send` hook runs afterward and can still modify or remove | ||
| that property. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1 · Preserve compatibility with existing Client method overrides
Existing subclasses overriding
Client::evaluateFlags()withbool $disableGeoip = falsenow fail at class loading: PHP rejects the narrower parameter because the parent acceptsnull. The same break affects overrides ofClient::flags(). This makes the minor SDK update fatal for these applications; preserve the inherited signatures or reserve this change for a major release.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We acknowledge this breaks compatibility for existing subclasses overriding these methods. We’re accepting that break in this minor release as an explicit tradeoff: nullable parameters let omitted arguments inherit the client-wide GeoIP setting while preserving an explicit
falseoverride. Keepingbool $disableGeoip = falsewould lose that distinction. Given that subclassing these SDK methods is an uncommon usage pattern, we prefer consistent configuration behavior here. Affected subclasses will need to update their overrides to?bool $disableGeoip = null.