Skip to content
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

Support enhanced conversions #8

Open
wuservices opened this issue Jul 17, 2024 · 5 comments
Open

Support enhanced conversions #8

wuservices opened this issue Jul 17, 2024 · 5 comments

Comments

@wuservices
Copy link

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:

Look for a parameter “em” with a hashed string as the value. The value should start with “tv.1~em” followed by a long string of characters. If you see the "em" parameter, this means that the enhanced conversions tag is picking up and hashing the enhanced_conversion_data object.

@wuservices
Copy link
Author

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.

@bjesus
Copy link
Member

bjesus commented Aug 6, 2024

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.

@wuservices
Copy link
Author

@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?

@lcrespilho
Copy link

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.

@it-can
Copy link

it-can commented Mar 13, 2025

any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants