Google Ads Enhanced Conversions with Server-Side Tagging

Standard

πŸš€ Advanced Guide: Implementing Google Ads Enhanced Conversions with Server-Side Tagging

πŸ” What Are Enhanced Conversions?

Enhanced Conversions for Google Ads allow you to send first-party customer data (e.g., email, name, phone number) to Google in a hashed format (SHA-256). This improves conversion tracking accuracy, especially in privacy-restricted environments like iOS or with cookie restrictions.

When paired with Server-Side Tagging, you gain:

  • Better data control
  • Improved user privacy compliance
  • Reduced client-side load
  • Enhanced tracking resilience

πŸ› οΈ Tools You’ll Need

  • Google Tag Manager (Web + Server Container)
  • Google Ads Account with Conversion Tracking Setup
  • Google Cloud Platform (GCP) for deploying the server container
  • Access to your website code (to extract and send user data)

πŸ“ Architecture Overview

[User Browser] β†’ [Web GTM] β†’ [Send User Data] β†’
    β†’ [Server GTM (on GCP)] β†’ [Google Ads Enhanced Conversion API]

πŸ”§ Step 1: Set Up Google Ads Enhanced Conversions

  1. Go to Google Ads β†’ Tools & Settings β†’ Conversions.
  2. Create or select a conversion action.
  3. Enable Enhanced Conversions under “Enhanced Conversions” section.
  4. Choose the API method (for server-side).
  5. Accept terms and save.

πŸ—ƒοΈ Step 2: Create Web GTM Tag to Send Data

You need to collect PII data (email, name, phone, etc.) on the client side and pass it to the server container.

🧩 Add Custom JavaScript Variable

In Web GTM, create a JavaScript Variable to extract user PII (e.g., from checkout form):

function() {
  return {
    email: document.querySelector('#email')?.value,
    phone: document.querySelector('#phone')?.value,
    first_name: document.querySelector('#first-name')?.value,
    last_name: document.querySelector('#last-name')?.value
  };
}

🏷️ Create a Custom Tag to Send Data to Server

Create a new Tag (Tag Type: HTTP Request or Custom Image) in Web GTM:

  • Tag Type: Custom Image Tag
  • URL: https://<your-server-container-url>/collect
  • Custom Parameters (Query String): plaintextCopyEdit
email={{User Data.email}}&phone={{User Data.phone}}&first_name={{User Data.first_name}}&last_name={{User Data.last_name}}&conversion_id=AW-CONVERSION_ID&event_name=purchase

Fire this tag on conversion trigger (e.g., “Purchase Complete”).

πŸ–₯️ Step 3: Deploy Server-Side GTM Container

  1. In GTM, create a Server Container.
  2. Deploy it on Google Cloud App Engine:
    • Google will guide you through provisioning the App Engine.
    • You’ll get a server URL like: https://gtm-yourproject.uc.r.appspot.com
  3. Enable Enhanced Conversions in your container.

πŸ” Step 4: Create a Custom Client in Server Container

Create a Client to parse the incoming HTTP request from the web container.

✍️ Client Code Example

// Enhanced Conversion Client in Server GTM
const parsedUrl = require('url').parse(request.url, true);
const query = parsedUrl.query;

const userData = {
  email: query.email,
  phone_number: query.phone,
  first_name: query.first_name,
  last_name: query.last_name,
  conversion_id: query.conversion_id,
  event_name: query.event_name
};

// Assign data to event object
eventData = {
  user_data: userData,
  event_name: query.event_name,
  conversion_id: query.conversion_id
};

// Send to tags
return {
  eventData,
  logType: 'INFO'
};

🧩 Step 5: Set Up Google Ads Enhanced Conversions Tag in Server GTM

  1. Go to Tags β†’ New β†’ Tag Configuration.
  2. Select Google Ads Conversion Tracking.
  3. Fill out the following:
    • Conversion ID: AW-XXXXXXXXX
    • Conversion Label: Your label from Ads
    • User Data: Map the fields from the eventData
      • Email: {{eventData.user_data.email}}
      • Phone: {{eventData.user_data.phone_number}}
      • First Name: {{eventData.user_data.first_name}}
      • Last Name: {{eventData.user_data.last_name}}
  4. Hash PII using built-in hashing functions (or pre-hash on client).

 

Note: Google requires SHA-256 hashing. Server GTM does this automatically if you pass raw values and set “Hash data” to TRUE.

πŸ§ͺ Step 6: Test and Debug

  1. Use Preview Mode in Web GTM to ensure tag fires with PII.
  2. Use Server GTM Preview to verify:
    • Client receives request
    • Event data is parsed
    • Google Ads Tag is fired with correct payload
  3. In Google Ads:
    • Go to Conversions β†’ Check Enhanced Conversions column
    • It should say “Recording (API)” after some time.

βœ… Best Practices

  • Consent Mode: Ensure PII is only sent with user consent (GDPR/CCPA).
  • Hashing: Use SHA-256 for any data that’s sent unhashed.
  • Security: Use HTTPS and authenticate requests to prevent misuse.
  • Data Layer: Use a structured data layer to manage PII cleanly.

πŸ’‘ Bonus: Optional – Use Cloud Function to Pre-Process

If you want to hash on server manually or process complex logic:

Example Google Cloud Function (Node.js)

const crypto = require('crypto');

exports.enhancedConversion = (req, res) => {
  const data = req.query;

  function hash(value) {
    return crypto.createHash('sha256').update(value.trim().toLowerCase()).digest('hex');
  }

  const hashedData = {
    email: hash(data.email),
    phone: hash(data.phone),
    first_name: hash(data.first_name),
    last_name: hash(data.last_name)
  };

  // Send to Server GTM or Google Ads API
  // Example: res.redirect(`https://gtm-server-url.com/collect?...`);

  res.status(200).send('Data processed and hashed.');
};

Deploy it and replace the Web GTM tag’s URL with your function’s URL.

πŸ“Š Conclusion

mplementing Enhanced Conversions with Server-Side Tagging helps improve attribution accuracy while enhancing user privacy. While it involves multiple components (client, server, GTM, Ads), the modular nature of GTM makes it scalable and manageable.

Leave a Reply

Your email address will not be published. Required fields are marked *