[backport cloud/1.42] [codex] merge hashed auth user data into GTM auth events (#10926)

Backport of #10778 to `cloud/1.42`

Automatically created by backport workflow.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-10926-backport-cloud-1-42-codex-merge-hashed-auth-user-data-into-GTM-auth-events-33a6d73d365081c2a7c2c7d01ba7bd1b)
by [Unito](https://www.unito.io)

Co-authored-by: Benjamin Lu <benjaminlu1107@gmail.com>
Co-authored-by: Christian Byrne <cbyrne@comfy.org>
This commit is contained in:
Comfy Org PR Bot
2026-04-14 03:59:57 +09:00
committed by GitHub
parent e0ff37b52c
commit 184bd586b5
2 changed files with 29 additions and 29 deletions

View File

@@ -230,7 +230,7 @@ describe('GtmTelemetryProvider', () => {
})
})
it('pushes normalized email as user_data before auth event', () => {
it('pushes normalized email inside the auth event payload', () => {
const provider = createInitializedProvider()
provider.trackAuth({
@@ -241,20 +241,21 @@ describe('GtmTelemetryProvider', () => {
})
const dl = window.dataLayer as Record<string, unknown>[]
const userData = dl.find((entry) => 'user_data' in entry)
expect(userData).toMatchObject({
user_data: { email: 'test@example.com' }
const authEvent = dl.find((entry) => entry.event === 'sign_up')
expect(authEvent).toMatchObject({
event: 'sign_up',
method: 'email',
user_id: 'uid-123',
user_data: {
email: 'test@example.com'
}
})
// Verify user_data is pushed before the sign_up event
const userDataIndex = dl.findIndex((entry) => 'user_data' in entry)
const signUpIndex = dl.findIndex(
(entry) => (entry as Record<string, unknown>).event === 'sign_up'
)
expect(userDataIndex).toBeLessThan(signUpIndex)
expect(
dl.some((entry) => 'user_data' in entry && !('event' in entry))
).toBe(false)
})
it('does not push user_data when email is absent', () => {
it('omits user_data when email is absent', () => {
const provider = createInitializedProvider()
provider.trackAuth({
@@ -263,9 +264,12 @@ describe('GtmTelemetryProvider', () => {
user_id: 'uid-456'
})
const dl = window.dataLayer as Record<string, unknown>[]
const userData = dl.find((entry) => 'user_data' in entry)
expect(userData).toBeUndefined()
expect(lastDataLayerEntry()).toMatchObject({
event: 'login',
method: 'google',
user_id: 'uid-456'
})
expect(lastDataLayerEntry()).not.toHaveProperty('user_data')
})
it('does not push events when not initialized', () => {

View File

@@ -135,23 +135,19 @@ export class GtmTelemetryProvider implements TelemetryProvider {
}
trackAuth(metadata: AuthMetadata): void {
const basePayload = {
const payload = {
method: metadata.method,
...(metadata.user_id ? { user_id: metadata.user_id } : {})
...(metadata.user_id ? { user_id: metadata.user_id } : {}),
...(metadata.email
? {
user_data: {
email: metadata.email.trim().toLowerCase()
}
}
: {})
}
if (metadata.email) {
window.dataLayer?.push({
user_data: { email: metadata.email.trim().toLowerCase() }
})
}
if (metadata.is_new_user) {
this.pushEvent('sign_up', basePayload)
return
}
this.pushEvent('login', basePayload)
this.pushEvent(metadata.is_new_user ? 'sign_up' : 'login', payload)
}
trackBeginCheckout(metadata: BeginCheckoutMetadata): void {