Skip to content

Instantly share code, notes, and snippets.

@it-can
Last active October 4, 2025 16:33
Show Gist options
  • Save it-can/188acc89637160d21ab9a37e1bbf0b2c to your computer and use it in GitHub Desktop.
Save it-can/188acc89637160d21ab9a37e1bbf0b2c to your computer and use it in GitHub Desktop.

Revisions

  1. it-can revised this gist Apr 4, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion checkout-succes.blade.php
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,6 @@
    transaction_id: "ORDER ID",
    value: AMOUNT
    currency: 'EUR',
    user_data: user_data_info
    user_data: JSON.stringify(user_data_info)
    });
    </script>
  2. it-can revised this gist Mar 14, 2025. 1 changed file with 0 additions and 0 deletions.
    Binary file added google-ads-settings2.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  3. it-can revised this gist Mar 14, 2025. 1 changed file with 21 additions and 21 deletions.
    42 changes: 21 additions & 21 deletions checkout-succes.blade.php
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,23 @@
    <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' }}
    }
    };
    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: user_data_info
    });
    </script>
    // Google Ads conversion tracking
    zaraz.track("conversion", {
    transaction_id: "ORDER ID",
    value: AMOUNT
    currency: 'EUR',
    user_data: user_data_info
    });
    </script>
  4. it-can revised this gist Mar 14, 2025. 2 changed files with 0 additions and 0 deletions.
    Binary file added google-ads-settings.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  5. it-can revised this gist Mar 14, 2025. 1 changed file with 0 additions and 0 deletions.
    Binary file added Scherm­afbeelding 2025-03-14 om 19.16.10.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  6. it-can revised this gist Mar 14, 2025. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,26 @@
    <?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
    {
  7. it-can revised this gist Mar 14, 2025. 2 changed files with 0 additions and 0 deletions.
    Binary file added cloudflare-zaraz-conversion-action.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added cloudflare-zaraz-trigger.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  8. it-can renamed this gist Mar 14, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. it-can revised this gist Mar 14, 2025. No changes.
  10. it-can created this gist Mar 14, 2025.
    23 changes: 23 additions & 0 deletions checkout-succes.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <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: user_data_info
    });
    </script>
    36 changes: 36 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <?php

    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);
    }
    }