mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
[backport cloud/1.42] feat: add SHA-256 hashed email to GTM dataLayer for sign_up/login events (#10638)
Backport of #10591 to `cloud/1.42` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10638-backport-cloud-1-42-feat-add-SHA-256-hashed-email-to-GTM-dataLayer-for-sign_up-login--3316d73d36508158b42feb46f7159c89) by [Unito](https://www.unito.io) Co-authored-by: Christian Byrne <cbyrne@comfy.org>
This commit is contained in:
@@ -230,6 +230,44 @@ describe('GtmTelemetryProvider', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('pushes normalized email as user_data before auth event', () => {
|
||||
const provider = createInitializedProvider()
|
||||
|
||||
provider.trackAuth({
|
||||
method: 'email',
|
||||
is_new_user: true,
|
||||
user_id: 'uid-123',
|
||||
email: ' Test@Example.com '
|
||||
})
|
||||
|
||||
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' }
|
||||
})
|
||||
|
||||
// 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)
|
||||
})
|
||||
|
||||
it('does not push user_data when email is absent', () => {
|
||||
const provider = createInitializedProvider()
|
||||
|
||||
provider.trackAuth({
|
||||
method: 'google',
|
||||
is_new_user: false,
|
||||
user_id: 'uid-456'
|
||||
})
|
||||
|
||||
const dl = window.dataLayer as Record<string, unknown>[]
|
||||
const userData = dl.find((entry) => 'user_data' in entry)
|
||||
expect(userData).toBeUndefined()
|
||||
})
|
||||
|
||||
it('does not push events when not initialized', () => {
|
||||
window.__CONFIG__ = {}
|
||||
const provider = new GtmTelemetryProvider()
|
||||
|
||||
@@ -140,6 +140,12 @@ export class GtmTelemetryProvider implements TelemetryProvider {
|
||||
...(metadata.user_id ? { user_id: metadata.user_id } : {})
|
||||
}
|
||||
|
||||
if (metadata.email) {
|
||||
window.dataLayer?.push({
|
||||
user_data: { email: metadata.email.trim().toLowerCase() }
|
||||
})
|
||||
}
|
||||
|
||||
if (metadata.is_new_user) {
|
||||
this.pushEvent('sign_up', basePayload)
|
||||
return
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface AuthMetadata {
|
||||
method?: 'email' | 'google' | 'github'
|
||||
is_new_user?: boolean
|
||||
user_id?: string
|
||||
email?: string
|
||||
referrer_url?: string
|
||||
utm_source?: string
|
||||
utm_medium?: string
|
||||
|
||||
@@ -350,7 +350,8 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
||||
useTelemetry()?.trackAuth({
|
||||
method: 'email',
|
||||
is_new_user: false,
|
||||
user_id: result.user.uid
|
||||
user_id: result.user.uid,
|
||||
email: result.user.email ?? undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -371,7 +372,8 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
||||
useTelemetry()?.trackAuth({
|
||||
method: 'email',
|
||||
is_new_user: true,
|
||||
user_id: result.user.uid
|
||||
user_id: result.user.uid,
|
||||
email: result.user.email ?? undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -392,7 +394,8 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
||||
method: 'google',
|
||||
is_new_user:
|
||||
options?.isNewUser || additionalUserInfo?.isNewUser || false,
|
||||
user_id: result.user.uid
|
||||
user_id: result.user.uid,
|
||||
email: result.user.email ?? undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -413,7 +416,8 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
||||
method: 'github',
|
||||
is_new_user:
|
||||
options?.isNewUser || additionalUserInfo?.isNewUser || false,
|
||||
user_id: result.user.uid
|
||||
user_id: result.user.uid,
|
||||
email: result.user.email ?? undefined
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user