duracelltomi / gtm4wp

Google Tag Manager plugin for WordPress
https://gtm4wp.com/
GNU General Public License v3.0
146 stars 96 forks source link

Enhanced conversion email/phone prepping before hashing #321

Closed StSaens closed 6 months ago

StSaens commented 8 months ago

Hi, I glanced at some code changes you made for enhanced conversion reporting. As an FYI, you can't just hash the email and assume it's done. Google has (almost hidden for whatever reason) a few steps to do before it's hashed. See: https://developers.google.com/google-ads/api/docs/conversions/enhanced-conversions/web

  1. Remove leading/trailing whitespaces.
  2. Convert the text to lowercase.
  3. Format phone numbers according to the E164 standard.
  4. Remove all periods (.) that precede the domain name in gmail.com and googlemail.com email addresses.

Maybe you have implemented this. I only glanced at some changes superficially. I don't know why they haven't signaled this in various documents more clearly, but it is what it is.

duracelltomi commented 8 months ago

Hi,

Thanks for pointing this out. I am quite sure most of those sanitizations are done while WooCommerce processes the email address.

Have you tried to place an order entering an email address that doesn't fulfill any of those requirements?

StSaens commented 8 months ago

Hi. Point 2 and 4 are for sure not done by woo.

duracelltomi commented 8 months ago

Thanks!

v1.20 will be released tomorrow, although this code seems to me a low risk change, I will add it into either 1.20.1 or 1.21

morvy commented 8 months ago

@StSaens @duracelltomi how should be an empty email handled? Now even empty string is hashed and empty string does generate a hash, so I believe this is not correct too.

I have this in my "hotfixes":

add_filter( 'gtm4wp_compile_datalayer', function($dataLayer) {
    if (empty(trim($dataLayer['customerBillingEmail']))) {
    $dataLayer['customerBillingEmailHash'] = "";
    }

    return $dataLayer;
}, 99, 1 );
duracelltomi commented 8 months ago

Partly done: https://github.com/duracelltomi/gtm4wp/commit/4aad7858a0a64196e586ccacd9a2b6ff5eb7414f

TODO:

duracelltomi commented 8 months ago

... and https://github.com/duracelltomi/gtm4wp/commit/3f141f0fca488bb9ca1804627d746807028b226e

duracelltomi commented 6 months ago

I've added better normalization into the next version: https://github.com/duracelltomi/gtm4wp/commit/a08afa9b5bf3b8f107152b5dbc14db53d880db98

However I have doubts adding phone number formatting as it seems to be a more complex code that I though. I've found this library but adding this to GTM4WP would be a large addition for one specific feature: https://github.com/giggsey/libphonenumber-for-php

Currently, I think some sort of normalization should be added into WooCommerce itself so that all plugins can benefit from the results.

StSaens commented 6 months ago

Great that the email formatting is implemented. Happy with that. Should be enough for most eCommerce shops.

With regards to the phone nr. That will mean that, unless the customer inputs it exactly right, Google won't be able to match that hash for enhanced conversion tracking. Maybe this should be clarified somewhere in gtm4wp docs.

duracelltomi commented 6 months ago

@morvy customerBillingEmailHash is not the right variable to use.

https://gtm4wp.com/google-tag-manager-for-woocommerce/enhanced-conversions-for-google-ads-with-woocommerce-how-to-setup

Variables in orderData are filtered to prevent hashing of empty strings.

I will fix this with customerBillingEmailHash too

duracelltomi commented 6 months ago

@morvy https://github.com/duracelltomi/gtm4wp/commit/42ef9d2bfc4b9816eac6dfc45745dbb81e4f001c