Last active
          October 4, 2025 16:33 
        
      - 
      
- 
        Save it-can/188acc89637160d21ab9a37e1bbf0b2c to your computer and use it in GitHub Desktop. 
    Cloudflare Zaraz Google Ads conversion tracking with "enhanced conversions"
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <script> | |
| var user_data_info = { | |
| sha256_email_address: '{{ normalizeAndHashEmailAddress($invoice->email) }}', | |
| sha256_phone_number: '{{ normalizeAndHash(formatPhoneE164($invoice->billing_telephone)) }}', | |
| address: { | |
| sha256_first_name: '{{ normalizeAndHash($firstname ?? '') }}', | |
| sha256_last_name: '{{ normalizeAndHash($lastname ?? '') }}', | |
| sha256_street: '{{ normalizeAndHash($invoice->billing_address . ' ' . $invoice->billing_address_nr) }}', | |
| postal_code: '{{ $invoice->billing_zipcode }}', | |
| city: '{{ $invoice->billing_city }}', | |
| country: '{{ $invoice->billing_country }}', | |
| new_customer: {{ $new_customer ? 'true' : 'false' }} | |
| } | |
| }; | |
| // Google Ads conversion tracking | |
| zaraz.track("conversion", { | |
| transaction_id: "ORDER ID", | |
| value: AMOUNT | |
| currency: 'EUR', | |
| user_data: JSON.stringify(user_data_info) | |
| }); | |
| </script> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| if (! function_exists('formatPhoneE164')) { | |
| /** | |
| * Format phonenumber to E164 (i use this library https://github.com/Propaganistas/Laravel-Phone) | |
| * | |
| * | |
| * @return mixed|string | |
| */ | |
| function formatPhoneE164($value) | |
| { | |
| $value = Str::lower(trim($value)); | |
| try { | |
| return (new PhoneNumber($value, 'NL')) | |
| ->formatE164(); | |
| } catch (Exception $e) { | |
| } | |
| return $value; | |
| } | |
| } | |
| if (! function_exists('normalizeAndHash')) { | |
| function normalizeAndHash(string $value, bool $trimIntermediateSpaces = false): string | |
| { | |
| // Normalizes by first converting all characters to lowercase, then trimming spaces. | |
| $normalized = strtolower($value); | |
| if ($trimIntermediateSpaces) { | |
| // Removes leading, trailing, and intermediate spaces. | |
| $normalized = str_replace(' ', '', $normalized); | |
| } else { | |
| // Removes only leading and trailing spaces. | |
| $normalized = trim($normalized); | |
| } | |
| return hash('sha256', strtolower(trim($normalized))); | |
| } | |
| } | |
| if (! function_exists('normalizeAndHashEmailAddress')) { | |
| function normalizeAndHashEmailAddress(string $emailAddress): string | |
| { | |
| $normalizedEmail = strtolower($emailAddress); | |
| $emailParts = explode('@', $normalizedEmail); | |
| if (count($emailParts) > 1 && preg_match('/^(gmail|googlemail)\.com\s*/', $emailParts[1])) { | |
| // Removes any '.' characters from the portion of the email address before the domain | |
| // if the domain is gmail.com or googlemail.com. | |
| $emailParts[0] = str_replace('.', '', $emailParts[0]); | |
| $normalizedEmail = sprintf('%s@%s', $emailParts[0], $emailParts[1]); | |
| } | |
| return normalizeAndHash($normalizedEmail, true); | |
| } | |
| } | 
Hi @it-can , is this still working for you? We're also trying to implement Enhanced conversions for Google Ads through Zaraz. But not sure how we can push the data in correct way. We have not yet tried this.
@imranshuvo i tested it and worked for me... but we are now back at using googletagmanager.com, instead of zaraz and hopefully when we can custom GoogleTag in cloudflare we will switch to that
- trigger google ads on your conversion event, make sure you set in settings proper labels (conversion id and label and conversion linker)
- pass custom fields: currency, revenue, transaction_id, user_data.email, user_data.phone with event property
- make sure you send Consent Mode from event property _zarazGoogleConsentV2String
What's missing in steps above is passing these values from zaraz to gads, which is step 2
To confirm, see in zaraz debugger call to googleadservices.com/pagead/conversion/, as described here:
https://support.google.com/google-ads/answer/13258081?hl=en#zippy=%2Cvalidate-your-implementation-using-chrome-developer-tools
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            




This seems to be working for me, but still in testing phase... please let me know if you had succes