We’re tracking conversions manually based on conditional logic upon loading a page. A PHP script returns HTML containing the gtag script to the page the user is on.
Here is the code that we know is being sent:
return <<<HTML
<script>
try {
gtag('config', $GOOGLE_AD_CONVERSION_ID);
gtag('set', 'user_data', {
"email": $email_string,
"phone_number": $phone
});
function gtag_report_conversion(url) {
var callback = function () {
console.log('gtag conversion tracked');
// We don't use this
if (typeof(url) != 'undefined') {
window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': $GOOGLE_AD_CLICK_SEND_TO,
'value': $amount,
'currency': $currency_string,
'transaction_id': $transaction_id,
'event_callback': callback
});
return false;
}
gtag_report_conversion(undefined);
} catch (e) {
console.error("Error during gtag conversion", e);
}
</script>
HTML;
All variables except $amount and $phone are wrapped in quotation marks so that they are valid strings in Javascript.
I realized after I got this error that $phone also needs to be wrapped. Would that be the reason that it doesn’t recognize the email as properly formatted? The server is logging the HTML it sends, so I took a look at it, and the email field looks perfectly normal to me. Example with identifying information removed: "[email protected]".
The other possibility it gives is that the email isn’t hashed, but it says on this page: “The feature uses a secure one-way hashing algorithm called SHA256 on your first-party customer data, such as email addresses, before sending to Google”, so that implies that it shouldn’t be pre-hashed.
I would wait to ask this question until after trying out having $phone be wrapped in quotation marks, but my company is very eager to get it working ASAP. If that resolves the issue, I’ll report back about it.
Summary: is there something wrong with the way this is implemented? If so, what’s wrong with it? Or does leaving the $phone variable without quotation marks in the Javascript ruin the email part too?