Skip to content

feat(analytics): hierarchical groups support - #176

Draft
tylerjroach wants to merge 20 commits into
masterfrom
hierarchical-groups
Draft

tylerjroach wants to merge 20 commits into
masterfrom
hierarchical-groups

Conversation

@tylerjroach

Copy link
Copy Markdown
Contributor

Adds hierarchical groups (HG) support: a MixpanelIdentity carrying user and company ids, HG-aware profile updates, and company-bound group writes. HG behavior is gated on the SDK's hierarchical groups init flag; projects without it behave as before.

Draft, opened for an early automated review. Not ready to merge.

Commits

  • feat(analytics): hierarchical groups support
  • feat(analytics): refuse alias on hierarchical groups projects
  • feat(flags): resolve local assignment keys from context_value_template
  • feat(analytics): raise for unsupported groups.update operations on hierarchical groups trackers
  • feat(analytics): add a company profile to for_company trackers
  • chore(analytics): point the company-only identity error at the company profile API
  • revert(analytics): drop the company profile methods from for_company clients
  • feat(analytics): infer the company for $company_id group profile updates
  • feat(analytics): restore the company profile on for_company clients
  • feat(flags): build a flag context from a Mixpanel::Identity
  • feat(analytics): refuse a user from another company on a for_company tracker
  • feat(analytics): send a user without a company as given on hierarchical groups
  • refactor: align Mixpanel::Identity naming and HG errors with the other SDKs

🤖 Generated with Claude Code

tylerjroach and others added 13 commits November 2, 2026 09:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erarchical groups trackers

$add, $append and $merge were warned about and still sent. They now raise
Mixpanel::UnsupportedOperationError before anything is sent, like the people operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y profile API

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…clients

The company profile is updated through the existing group methods instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings back the company profile methods in place of inferring the company from $company_id
group writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Identity#to_flag_context puts the ids under the keys flags read, the
groups at the top level and the custom properties under
custom_properties, so callers do not hand-write $user_id and $company_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tracker

A people update through a tracker bound with for_company used the
identity's company and ignored the bound one, so a mismatched identity
silently updated the other company's user. The bound tracker now gets its
own Mixpanel::People that raises ArgumentError and sends nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al groups

An identity with a user id but no company or device id threw on every
call. It is valid to send, like a plain distinct id, so events now send
it as given. User profile updates still need the company and fail with
the existing company-required error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r SDKs

Add Mixpanel::MixpanelIdentity as an alias of Mixpanel::Identity, the name
every other SDK uses. Make UnsupportedOperationError and CompanyRequiredError
extend MixpanelError so rescuing MixpanelError catches them; they are raised
before any send, so they still reach the caller rather than the ErrorHandler.
Mark Identity#to_properties and the People/Groups for_company helpers :nodoc:.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest update appears safe to merge.

Reviews (8) · Last reviewed commit: "fix: copy the company id passed to for_c..." · Reviewed by Greptile

Comment thread lib/mixpanel-ruby/people.rb Resolved
Comment thread lib/mixpanel-ruby/groups.rb Resolved
Comment thread Readme.rdoc Resolved
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.63899% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.23%. Comparing base (3fdee83) to head (6dfd465).

Files with missing lines Patch % Lines
lib/mixpanel-ruby/identity.rb 98.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #176      +/-   ##
==========================================
+ Coverage   97.41%   98.23%   +0.81%     
==========================================
  Files          16       17       +1     
  Lines         889     1131     +242     
==========================================
+ Hits          866     1111     +245     
+ Misses         23       20       -3     
Flag Coverage Δ
openfeature 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…hierarchical groups

On a for_company tracker, a user profile update for an identity with no
company now uses the bound company, which also wins over a $company_id
in optional_params. An empty $company_id no longer counts as a company
in the CompanyRequiredError check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tylerjroach tylerjroach changed the title Hierarchical groups support feat(analytics): hierarchical groups support Nov 4, 2026
tylerjroach and others added 5 commits November 4, 2026 16:20
Exclude "{" from the placeholder capture so a template full of "{" can't
make matching slow (CodeQL polynomial regular expression).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Public docs are the source of truth for hierarchical groups usage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restores master's TypeError for non-Hash input to Groups#update instead
of a NoMethodError; output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… integer ids on hierarchical groups

- Exposure events on hierarchical groups keep $user_id when the flag context
  has no $company_id; the skip rule ($company_id or distinct_id) is unchanged.
- Generic people and group updates on hierarchical groups refuse any
  $-prefixed operation outside $set, $set_once, $unset, $union, $remove and
  $delete, and allow non-operation keys such as $token and $company_id.
- Mixpanel::Identity and for_company accept String and Integer ids and refuse
  other types with ArgumentError; the bound company is compared as a string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread lib/mixpanel-ruby/tracker.rb Resolved
The bound tracker kept the caller's string, so changing that string later
moved the bound company. Copy and freeze it, as Identity does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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