Repository navigation
fix: gate Mixpanel and Customer.io user identification on store readiness (cloud/1.54) #18694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ import { watch } from 'vue' | |
|
|
||
| import { useCurrentUser } from '@/composables/auth/useCurrentUser' | ||
| import { i18n } from '@/i18n' | ||
| import { reportError } from '@/platform/telemetry/reportError' | ||
| import { whenStoresReady } from '@/platform/telemetry/storeReadiness' | ||
| import type { AuthUserInfo } from '@/types/authTypes' | ||
|
|
||
| import { TelemetryEvents } from '../../types' | ||
|
|
@@ -67,20 +69,27 @@ export class CustomerIoTelemetryProvider implements TelemetryProvider { | |
| } | ||
|
|
||
| void import('@customerio/cdp-analytics-browser') | ||
| .then(({ AnalyticsBrowser, InAppPlugin }) => { | ||
| .then(async ({ AnalyticsBrowser, InAppPlugin }) => { | ||
| const analytics = AnalyticsBrowser.load({ writeKey }) | ||
| const inAppRegistration = analytics.register( | ||
| InAppPlugin({ | ||
| siteId, | ||
| events: null, | ||
| anonymousInApp: false, | ||
| _env: undefined, | ||
| _logging: undefined, | ||
| colorScheme: 'system' | ||
| const inAppRegistration = analytics | ||
| .register( | ||
| InAppPlugin({ | ||
| siteId, | ||
| events: null, | ||
| anonymousInApp: false, | ||
| _env: undefined, | ||
| _logging: undefined, | ||
| colorScheme: 'system' | ||
| }) | ||
| ) | ||
| .catch((error) => { | ||
| reportError(error, { | ||
| errorType: 'customerio_in_app_plugin_registration_failure' | ||
| }) | ||
| }) | ||
| ) | ||
| this.analytics = analytics | ||
|
|
||
| await whenStoresReady() | ||
| this.analytics = analytics | ||
| const currentUser = useCurrentUser() | ||
| const identifyResolvedUser = (user: AuthUserInfo) => { | ||
| const identity = { | ||
|
|
@@ -117,17 +126,10 @@ export class CustomerIoTelemetryProvider implements TelemetryProvider { | |
| }) | ||
|
|
||
| void this.flushQueue() | ||
| void inAppRegistration | ||
| .catch((error) => { | ||
| console.error( | ||
| 'Failed to initialize Customer.io in-app plugin:', | ||
| error | ||
| ) | ||
| }) | ||
| .finally(() => { | ||
| this.isPageViewTrackingReady = true | ||
| this.flushPageView() | ||
| }) | ||
| void inAppRegistration.finally(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π’ Low β The Raised by 2 of 8 reviewers (claude-opus-5-thinking-max adversarial, claude-opus-5-thinking-max edge-case). |
||
| this.isPageViewTrackingReady = true | ||
| this.flushPageView() | ||
| }) | ||
| }) | ||
| .catch((error) => { | ||
| console.error('Failed to load Customer.io:', error) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π‘ Medium β Making the Raised by 3 of 8 reviewers (kimi-k3-max adversarial, kimi-k3-max edge-case, claude-opus-5-thinking-max edge-case). |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ import { omit } from 'es-toolkit' | |
| import { watch } from 'vue' | ||
|
|
||
| import { useCurrentUser } from '@/composables/auth/useCurrentUser' | ||
| import { reportError } from '@/platform/telemetry/reportError' | ||
| import { whenStoresReady } from '@/platform/telemetry/storeReadiness' | ||
|
|
||
| import type { | ||
| AuthMetadata, | ||
|
|
@@ -114,11 +116,19 @@ export class MixpanelTelemetryProvider implements TelemetryProvider { | |
| loaded: () => { | ||
| this.isInitialized = true | ||
| this.flushEventQueue() // flush events that were queued while initializing | ||
| useCurrentUser().onUserResolved((user) => { | ||
| if (this.mixpanel && user.id) { | ||
| this.mixpanel.identify(user.id) | ||
| } | ||
| }) | ||
| void whenStoresReady() | ||
| .then(() => { | ||
| useCurrentUser().onUserResolved((user) => { | ||
| if (this.mixpanel && user.id) { | ||
| this.mixpanel.identify(user.id) | ||
| } | ||
| }) | ||
| }) | ||
| .catch((error) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π’ Low β Raised by 4 of 8 reviewers (claude-opus-5-thinking-max adversarial, claude-opus-5-thinking-max edge-case, kimi-k3-max adversarial, kimi-k3-max edge-case). |
||
| reportError(error, { | ||
| errorType: 'mixpanel_user_identification_failure' | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π High β
await whenStoresReady()was placed beforethis.analytics = analyticsandvoid this.flushQueue(), so the entire event pipeline β not just user identification β is now gated on Pinia: until the gate opens every event goes to the uncappedeventQueue, and because the gate has no timeout and cannot reject, a boot failure betweenmarkStoresPending()andmarkStoresReady()buffers events for the whole session with no error ever surfaced. The Mixpanel change in this same diff gets this right β it flushes first and defers onlyonUserResolvedbehind the gate. Move the assignment and the flush above the await, and/or bound the wait.Raised by 6 of 8 reviewers (gemini-3.1-pro adversarial, gemini-3.1-pro edge-case, claude-opus-5-thinking-max adversarial, claude-opus-5-thinking-max edge-case, kimi-k3-max adversarial, kimi-k3-max edge-case).