feat: add group_identify helper for creating and updating group properties by vjymisal0 · Pull Request #232 · PostHog/posthog-rs · GitHub
Skip to content

feat: add group_identify helper for creating and updating group properties - #232

Merged
marandaneto merged 3 commits into
PostHog:mainfrom
vjymisal0:feat/group-identify-helper
Aug 24, 2026
Merged

marandaneto merged 3 commits into
PostHog:mainfrom
vjymisal0:feat/group-identify-helper

Conversation

@vjymisal0

@vjymisal0 vjymisal0 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Closes #150.

Adds a first-class group_identify helper so users no longer need to hand-build the $groupidentify event:

client.group_identify(
    "company",
    "company_id_in_your_db",
    json!({
        "name": "Awesome Inc.",
        "employees": 11,
    }),
);

Available on both the async and blocking clients with the same signature.

Implementation Details & Design Decisions

  1. Payload Structure & Wire Format

    • Emits event name "$groupidentify".
    • The top-level distinct_id is set to format!("${group_type}_{group_key}") (e.g. "$company_company_id_in_your_db"), matching posthog-js (posthog-core-stateless / posthog-node), posthog-python, and the PostHog group analytics specification.
    • Properties include $group_type, $group_key, and $group_set: properties.
    • Person profile processing is preserved by default (group identification is personful).
  2. Synchronous Construction & Fire-and-Forget Delivery

    • Matching capture and alias, the helper synchronously constructs and enqueues the event on both async and blocking clients; delivery remains fire-and-forget.
    • Accepts generic group_type: impl Into<String>, group_key: impl Into<String>, and properties: impl Serialize.
    • Blank group_type or group_key cannot describe a valid group identification and are dropped with a warning, matching posthog-python.
    • Property serialization failures and values that do not serialize to a JSON object return Error::Serialization to the caller.
    • Event construction lives in Event::group_identify so both clients share the exact same payload definition and validation logic.

💚 How did you test it?

  • Added tests/test_group_identify.rs covering both async_client and blocking clients across all key scenarios:
    • Well-formed $groupidentify payload verification ($group_type, $group_key, $group_set)
    • Person profile processing is preserved
    • Generic string and struct serialization ergonomics
    • Distinct event UUID generation across repeated calls
    • Blank group_type and group_key drops
    • Disabled client no-op
  • Added unit tests in src/event.rs:
    • v0_group_identify_payload
    • group_identify_rejects_blank_keys
  • Verified:
    • cargo test --test test_group_identify (6 passed)
    • cargo test --no-default-features --test test_group_identify (6 passed)
    • cargo test --lib event (34 passed)
    • cargo test --doc (7 passed)
    • cargo clippy -- -D warnings (clean)
    • cargo fmt --check (clean)
    • api/public-api.txt snapshot updated
    • Added changeset in .sampo/changesets/add-group-identify-helper.md

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change.
  • Included changeset file (.sampo/changesets/add-group-identify-helper.md).

@vjymisal0
vjymisal0 requested a review from a team as a code owner August 23, 2026 15:23

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Automated advisory code review.

Comment thread .sampo/changesets/add-group-identify-helper.md Outdated
Comment thread src/event.rs Outdated
Comment thread src/event.rs Outdated
@marandaneto
marandaneto requested a review from a team August 24, 2026 08:33
@marandaneto

Copy link
Copy Markdown
Member

@marandaneto

Copy link
Copy Markdown
Member

@vjymisal0

Commits must have verified signatures.

you need to sign your commits and force push

@marandaneto

Copy link
Copy Markdown
Member

vijay-loopr and others added 3 commits August 24, 2026 14:05
Strip the UTF-8 BOM from the changeset front matter that was breaking
sampo release parsing, and make group_identify reject non-object
properties (PostHog silently drops $group_set otherwise) by returning
Result<(), Error> instead of swallowing serialization failures.
@marandaneto
marandaneto force-pushed the feat/group-identify-helper branch from a8bb180 to f0daad4 Compare August 24, 2026 12:05
@marandaneto
marandaneto merged commit 710ea93 into PostHog:main Aug 24, 2026
25 checks passed
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.

Add group_identify helper

3 participants