Repository navigation
feat(analytics): hierarchical groups support - #476
tylerjroach wants to merge 33 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g requests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l groups projects Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The reviewed update appears safe to merge. Reviews (26) · Last reviewed commit: "fix: capture the identity before setGrou..." · Reviewed by Greptile |
… user delete on opt out On hierarchical groups projects in JavaScript mode, a /groups write keyed by $company_id now uses its own group id as $company_id instead of the currently identified company, so a saved getCompany() handle keeps writing to its company after identify or reset. Opting out now clears pending /groups updates before queuing the user delete, so only the delete is flushed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hierarchical groups opt-out clears the /groups queue before queuing the user delete. A batch already sending then removed the first records from the new queue when it finished, which could drop the delete unsent. The queue now counts clears, and a batch sent before a clear leaves the queue alone. Only the hierarchical groups opt-out clears a queue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A batch rejected with a 400 removed the first queued record even after a clear, which could drop the hierarchical groups opt-out delete. It now leaves the queue alone when a clear happened while it was sending, as a sent batch already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
identify with an identity object called the bridge in a later Promise callback, so a track() made right after it reached the native SDK first and was recorded under the previous identity. Call it in the executor, as the string overload does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…elete optOutTracking set the opt-out flag only after clearing the /groups queue and sending the $user_id profile delete, so calls made meanwhile were still tracked and a profile update could be sent alongside the delete. The flag is now set first, and the delete is queued and sent through a core path that skips the opt-out checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Original ID Merge projects, and projects with ID Merge off, still identify users by distinct id, so the getter stays supported. Its docs now say not to use it on hierarchical groups projects and to prefer the identity getter where possible. Deprecation suppressions added for it are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eholder Demo and example apps must not ship a real project token. Set YOUR_HG_PROJECT_TOKEN to a project with hierarchical groups enabled to run the page, as the other demo pages do with their own placeholder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…vents On a hierarchical groups project the user is identified by $user_id and $company_id, which the request already carries, so the first-time event body no longer sends a distinct_id. Other projects send it as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a hierarchical groups project an identified user is $user_id and $company_id, so events leave out distinct_id rather than send the bare user id. Anonymous events still send the $device: distinct id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ingestion rejects $identify without a distinct_id, and a hierarchical groups project ties the device to the user from the $device_id, $user_id and $company_id every later event carries. So identify (and optInTrackingWithIdentity) track no $identify there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK owns the device id, so the identity apps pass to identify() has only userId and companyId. getIdentity() returns a ReportedMixpanelIdentity that adds deviceId. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ould refuse Opting in with an identity identify() would refuse (no company on a hierarchical groups project, a company on any other project, or no user id) used to opt the user in and track $opt_in anonymously, dropping only the identity. Invalid input now leaves the whole call undone, as the JS SDK does: the error is logged and the user stays opted out. identify and opt-in share one identity check so they cannot disagree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
identify() sends arrays down the distinct id path, so they reject as they did before. The company id is only loaded, saved and cleared for tokens initialized with hierarchicalGroups, so other projects make the same storage calls as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- identify(identity) and optInTrackingWithIdentity refuse a user id starting with $device: and treat whitespace-only ids as missing (JavaScript mode) - JavaScript mode refuses registerSuperProperties, registerSuperPropertiesOnce, unregisterSuperProperty, setGroup and removeGroup calls naming $company_id on hierarchical groups projects - track warns when the identified company replaces a caller's $company_id and removes a caller's $company_id, with a warning, before a company is identified - the iOS bridge resolves identify(identity) when the Swift identify completes - setGroup(key, null) sets the group to null on hierarchical groups projects, and removeGroup(key, null) clears it; the Android bridge passes a real null - user profile updates made before identify are queued, persisted and sent to the identified user's profile, and cleared on reset and opt out Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…coverable Profile calls on a hierarchical groups project now run one at a time behind the pending transfer that identify starts, and each is bound to the user and company current when it was made, so updates made right after identify land after the older pending ones and a second identify can't take them. Pending updates are saved to /groups before they leave the pending queue, which now removes only the moved records, and initialize resumes a transfer left by an identify that was saved but didn't finish. Pending updates that can't be serialized are dropped with the same errors as the other queues. Identified events also drop a distinct_id from event or super properties. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With $user_id and $company_id in the context, the flags service builds the user from them and replaces any distinct_id, so flags requests now leave it out, as first-time events do. Before identify, and with hierarchical groups off, the context is unchanged. Saved flags are now matched on $user_id and $company_id as well, since an identified context no longer carries a distinct_id to match on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A user there is identified by company and user id, so the distinct id should not be used: reading it now logs a warning pointing to the identity, and still returns the SDK's best match. The SDK's own reads skip the warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
identify only reloaded flags, so a first-time event variant activated for the previous user or company stayed active. Reset the flags instead, as reset() does, and expose the refetch to flag readers right away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The constructor that takes a device id is @RestrictTo(LIBRARY_GROUP), and this wrapper is one of the Mixpanel libraries it is meant for. Suppress RestrictedApi where it is called so Android lint does not flag it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
optInTracking() never accepted a distinct id on master, and hierarchical
groups work should not add new API patterns. Apps opt in with
optInTracking() and then call identify({userId, companyId}).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rahul-mixpanel
left a comment
There was a problem hiding this comment.
HG review. HG-off is safe apart from one change: JS-mode identify() now fully resets flags on every project. Event, /engage and /groups payloads, the public API and stored state are unchanged when HG is off. On HG, first-time events 400 for $device_id and custom-group flags (needs the flags team), and ids aren't checked for | or the $company: prefix. Jest: 710 passed. tsc is clean.
Note: native pins. The native CI jobs fail only because the pinned SDKs predate HG. This can merge once these are published and pinned:
- Android: a mixpanel-android release with #1026 (
MixpanelOptions.Builder.hierarchicalGroups,identify(MixpanelIdentity),getIdentity(), andmixpanel-android-common1.2.0MixpanelIdentity). The bridge relies on common coming throughapi; if that changes toimplementation, declare it here. - iOS: a Mixpanel-swift release with #798 (
MixpanelOptions(hierarchicalGroups:),identify(identity:completion:),identity, andMixpanelSwiftCommon ~> 2.1). Bump the podspec andios/Package.swifttogether.
Every bridge call already matches the HG branches' signatures.
- identify({userId, companyId}) on a hierarchical groups project logs and drops
an identity whose user or company id contains |.
- index.d.ts: identify() accepts string | MixpanelIdentity.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move the $company_id group key constant into mixpanel-constants.js and use it
from mixpanel-main.js, index.js and mixpanel-flags-js.js.
- Note that the combined $company:{c}|$user:{u} distinct id is best-effort.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Native pins: deferred until the mixpanel-android and Mixpanel-swift HG releases are published; the podspec and |
rahul-mixpanel
left a comment
There was a problem hiding this comment.
Re-review of a28787c. The | check, the union identify() typing, the getDistinctId() doc note and the shared $company_id constant all look good. Jest: 713 passed. tsc is clean. No new issues in the delta, and nothing changes for non-HG projects. Still open:
- Land #477 before this PR, so this diff no longer carries the flags reset on
identify(). - The first-time-event 400 is a flags-service dependency; please link the ticket.
- Native pins are still waiting on the mixpanel-android and Mixpanel-swift HG releases, as agreed.
USER_ID_GROUP_KEY moves next to COMPANY_ID_GROUP_KEY in mixpanel-constants.js and replaces the local constant and the literal in the flags module. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…archical groups The hierarchical groups removeGroup awaited unregisterSuperProperty before sending its $unset, so an identify made right after could retarget the removal to the new user. The super property update is no longer awaited, as master's removeGroup and mixpanel-js do, so the $unset captures the user and company when removeGroup is called. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rahul-mixpanel
left a comment
There was a problem hiding this comment.
Re-reviewed 5efba25. The removeGroup identity-capture fix and the shared $user_id constant look good, Jest (714) and tsc pass, and nothing changes for non-HG projects. One fix before I approve: setGroup has the same race (inline). Merge order stays the same: #477 first, then the native HG pins.
…hical groups The hierarchical groups setGroup awaited registerSuperProperties before sending its $set, so an identify made right after could retarget the update to the new user. The $set now starts before the super property write is awaited, so it captures the user and company when setGroup is called, as removeGroup does since 5efba25. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rahul-mixpanel
left a comment
There was a problem hiding this comment.
Re-reviewed 93268c2. setGroup now reads the user and company before the super-property write is awaited, which matches removeGroup, and the new test covers an identify that isn't awaited. Jest passes (715). LGTM. Merge order is unchanged: #477 first, then the native HG pins.
Adds hierarchical groups (HG) support: a
MixpanelIdentitycarrying 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
🤖 Generated with Claude Code