Open wuservices opened 3 months ago
I did some reverse engineering, and it looks like you can build the em
parameter like this:
async function emailToBase64UrlSafeSha256(email) {
const emailBytes = new TextEncoder().encode(email)
const hashBuffer = await crypto.subtle.digest('SHA-256', emailBytes)
const base64String = btoa(String.fromCharCode(...new Uint8Array(hashBuffer)))
return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
}
async function buildEmParam(email) {
const prefix = 'tv.1~em.'
try {
return prefix + await emailToBase64UrlSafeSha256(email)
} catch(e) {
return prefix + 'e2'
}
}
There are a few other error codes with other validations, but the main idea is there's some prefix, and base 64 URL safe SHA-256 of the lowercase email.
It also appears that another param was added ec_mode=m
. Not sure what that means though. The version I had from GTM was also sending cv=11
and fmt=3
, so I'm not sure if there will be any issues with cv=9
.
Thanks @wuservices ! we're looking into this, actually trying to get some insights from Google on how exactly this should be implemented. hopefully will be implemented in next few weeks.
@bjesus That's great news, and I'm glad you can work with them so we're not just guessing. Supporting other fields besides email would be great too.
FWIW I was able to use this logic with a Worker Variable and reconfigured Google Ads Enhanced Conversations to gtag and the alert on our account went away.
I saw that there was also an API based option and I was wondering if that was a better match for Zaraz to send server side, or why not use the API for all Google Ads logic instead of the client?
ec_mode=m. Not sure what that means though.
@wuservices , I think it refer to the enhanced conversions implementation mode, with "m" = "manual". If I choose the "code" implementation, ec_mode=c.
Allow additional attributes to be passed in and hashed for enhanced conversions. This will improve matching for ads by passing in known data about the user.
The Google documentation defines what fields can be passed in, and they could be pre-hashed with SHA256. The exact data format of the API request isn't clear from the docs, but in the validate your implementation section, it mentions the
em
parameter will be added: