Skip to content

fix: remove ignored batch event fields#176

Merged
marandaneto merged 1 commit into
mainfrom
remove-ignored-batch-fields
Jun 18, 2026
Merged

fix: remove ignored batch event fields#176
marandaneto merged 1 commit into
mainfrom
remove-ignored-batch-fields

Conversation

@marandaneto

@marandaneto marandaneto commented Jun 18, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

The backend /batch/ endpoint ignores several legacy top-level fields on individual events (type, library, library_version, library_consumer, and send_feature_flags). Keeping them in SDK payloads adds noise and can confuse which fields are canonical.

This change strips those deprecated top-level fields before sending events and keeps the backend-supported canonical SDK metadata in event properties instead. For backwards compatibility, legacy top-level library, library_version, and library_consumer values are still used as event-property fallbacks when the canonical $lib, $lib_version, or $lib_consumer values are absent. Top-level type is ignored and not used as a fallback. The HTTP User-Agent now always uses the official PostHog::LIBRARY / PostHog::VERSION constants regardless of event metadata.

💚 How did you test it?

  • composer run api:check
  • php -l on changed PHP files
  • ./vendor/bin/phpunit --testsuite posthog-php (tests pass: 339 tests / 3391 assertions; command exits non-zero because PHPUnit reports no code coverage driver)
  • git diff --check

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

An AI coding agent made the implementation and validation changes at the direction of the maintainer. The backend batch schema was checked first, then the SDK was updated to stop sending ignored per-event top-level fields while preserving canonical $lib, $lib_version, and $lib_consumer properties. Backwards compatibility was preserved for legacy top-level SDK metadata values as event-property fallbacks when canonical values are absent; type remains a no-op. Existing payload assertions and file-consumer expectations were updated to match the canonical shape.

@marandaneto marandaneto self-assigned this Jun 18, 2026
@marandaneto marandaneto requested review from eli-r-ph and removed request for eli-r-ph June 18, 2026 09:32
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
lib/Client.php:349-353
**`groups: []` still leaks out of `identify()` and `alias()` payloads**

The `message()` helper (line 1690-1692) always injects `"groups" => []` as a default, and `capture()` explicitly unsets it at line 291. But `identify()` and `alias()` have no matching `unset($message["groups"])`, so every identify/alias event still ships `"groups":[]` to the batch endpoint — the very noise this PR aims to eliminate. The same one-liner added to `capture()` would fix both methods.

Reviews (1): Last reviewed commit: "fix: remove ignored batch event fields" | Re-trigger Greptile

Comment thread lib/Client.php
@marandaneto marandaneto force-pushed the remove-ignored-batch-fields branch 4 times, most recently from 5859a1c to 1458fc0 Compare June 18, 2026 10:01
@marandaneto marandaneto marked this pull request as ready for review June 18, 2026 10:02
@marandaneto marandaneto requested a review from a team as a code owner June 18, 2026 10:02
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "fix: remove ignored batch event fields" | Re-trigger Greptile

@marandaneto marandaneto force-pushed the remove-ignored-batch-fields branch from 1458fc0 to 60442c6 Compare June 18, 2026 11:41
@marandaneto marandaneto merged commit b7b6cf0 into main Jun 18, 2026
20 checks passed
@marandaneto marandaneto deleted the remove-ignored-batch-fields branch June 18, 2026 11:44
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