Skip to content

fix: support groups key for capture events#174

Merged
marandaneto merged 4 commits into
mainfrom
fix/issue-71-groups
Jun 18, 2026
Merged

fix: support groups key for capture events#174
marandaneto merged 4 commits into
mainfrom
fix/issue-71-groups

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Fixes #71.

capture() documents and examples have allowed passing group context with the groups key, but PostHog ingestion associates events with groups via the $groups event property. This PR preserves backwards compatibility by promoting an explicitly supplied groups key to $groups before enqueueing the capture event, while keeping existing $groups behavior unchanged.

💚 How did you test it?

  • ./vendor/bin/phpunit --no-coverage test/PostHogTest.php --filter '/testCaptureCopiesGroupsKeyToDollarGroupsProperty|testCaptureKeepsDollarGroupsCompatibility/'
  • ./vendor/bin/phpunit --no-coverage
  • composer api:check
  • ./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=0 lib/Client.php test/PostHogTest.php
  • 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)

This PR was implemented with the pi coding agent. We investigated the PostHog ingestion path and confirmed that event grouping is read from properties.$groups; top-level groups is not consumed by backend event ingestion. The chosen fix keeps the existing public groups capture input working by promoting it to $groups, without changing feature flag groups behavior or removing existing $groups compatibility.

@marandaneto marandaneto self-assigned this Jun 17, 2026
@marandaneto marandaneto marked this pull request as ready for review June 17, 2026 16:21
@marandaneto marandaneto requested a review from a team as a code owner June 17, 2026 16:21
@greptile-apps

greptile-apps Bot commented Jun 17, 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
test/PostHogTest.php:460-502
**Prefer a parameterised test over two separate methods**

The two new methods (`testCaptureCopiesGroupsKeyToDollarGroupsProperty` and `testCaptureKeepsDollarGroupsCompatibility`) cover the same logical scenario — capture with a groups key ends up in `properties['$groups']` — and differ only in which input key is used (`groups` vs `$groups`). Per the project's stated preference for parameterised tests, these should be collapsed into a single `@dataProvider`-driven method. Separate methods make it harder to add coverage for additional variants (e.g. both keys supplied simultaneously) without more copy-paste.

Reviews (1): Last reviewed commit: "fix: support groups key for capture even..." | Re-trigger Greptile

Comment thread test/PostHogTest.php
@marandaneto marandaneto merged commit 6e8b141 into main Jun 18, 2026
20 checks passed
@marandaneto marandaneto deleted the fix/issue-71-groups branch June 18, 2026 15:35
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.

Groups are not working

2 participants