Facebook Pixel + Facebook CAPI Setup in OpenCart via GTM & Server-Side

Standard

Setting up Facebook Pixel and Facebook Conversions API (CAPI) using both client-side (GTM Web) and server-side (GTM Server) in OpenCart ensures reliable, deduplicated event tracking for Meta Ads. This setup helps overcome browser restrictions, improve attribution, and increase match rates.

🧰 Prerequisites

  • OpenCart (v3.x or 4.x)
  • Google Tag Manager (Web + Server containers)
  • Facebook Business Manager access
  • Facebook Pixel ID and Access Token
  • HTTPS-enabled domain
  • Consent mechanism (for GDPR/CCPA compliance)


🧱 Step 1: Install Facebook Pixel via GTM (Web)

  1. Go to your GTM Web Container
  2. Create a new tag:
    • Tag Type: Custom HTML
    • Trigger: All Pages

<!-- Facebook Pixel Base Code -->
<script>
  !function(f,b,e,v,n,t,s)
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
  n.queue=[];t=b.createElement(e);t.async=!0;
  t.src=v;s=b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t,s)}(window, document,'script',
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', 'YOUR_PIXEL_ID');
  fbq('track', 'PageView');
</script>
<noscript>
  <img height="1" width="1" style="display:none"
       src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"/>
</noscript>


πŸ’³ Step 2: Push Purchase Event in OpenCart

In catalog/view/theme/YOUR_THEME/template/checkout/success.twig, after order confirmation:

<script>
  dataLayer = dataLayer || [];
  dataLayer.push({
    event: "purchase",
    transaction_id: "{{ order_id }}",
    value: {{ order_total }},
    currency: "{{ currency }}",
    email: "{{ email | lower | trim | sha256 }}",
    phone: "{{ phone | regex_replace('/\D/', '') | sha256 }}",
    event_id: "fb_{{ order_id }}"
  });
</script>


🌐 Step 3: Send Server-Side Payload via Web GTM

Create a new Custom HTML tag in GTM Web:

  • Trigger: Event equals purchase

<script>
fetch('https://gtm.yourdomain.com/event', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    event_name: 'Purchase',
    event_id: '{{DL - event_id}}',
    transaction_id: '{{DL - transaction_id}}',
    value: '{{DL - value}}',
    currency: '{{DL - currency}}',
    email: '{{DL - email}}',
    phone: '{{DL - phone}}'
  })
});
</script>


πŸ“‘ Step 4: Facebook CAPI in GTM Server Container

  1. Create a new Tag:
    • Tag Type: HTTP Request
    • Trigger: Custom event with event_name = Purchase
  2. Add the following payload:

POST https://graph.facebook.com/v18.0/YOUR_PIXEL_ID/events?access_token=ACCESS_TOKEN
{
  "data": [{
    "event_name": "Purchase",
    "event_time": {{timestamp}},
    "event_id": "{{event_id}}",
    "action_source": "website",
    "user_data": {
      "em": "{{email}}",
      "ph": "{{phone}}"
    },
    "custom_data": {
      "currency": "{{currency}}",
      "value": {{value}},
      "transaction_id": "{{transaction_id}}"
    }
  }]
}


πŸ” Step 5: Deduplication & Attribution

  • Ensure event_id is the same on both browser pixel and CAPI
  • Facebook will automatically deduplicate and attribute to the first successful event


πŸ” Step 6: Consent Handling (GDPR/CCPA)

If using a consent management platform (CMP):

  • Delay dataLayer push until consent is granted
  • Use a flag like consent_granted = true in GTM to control tag firing


πŸ§ͺ Step 7: Test & Validate

Platform Tool
GTM Preview mode (Web + Server)
Facebook Events Manager β†’ Test Events tab
Chrome Facebook Pixel Helper extension


🎯 Final Benefits

  • Server-side event delivery = more resilient to browser restrictions
  • Higher match rates with hashed email/phone
  • Accurate attribution with deduplication via event_id
  • Consent-aware and privacy-safe


Google Ads Conversion Tracking in osCommerce Using GTM (Full Guide + Code)

Standard

If you’re running paid campaigns for your osCommerce store, accurately measuring conversions is essential for optimizing your Google Ads spend. Using Google Tag Manager (GTM) to implement Google Ads Conversion Tracking allows for scalable, code-free updates and clean data collection.

This guide covers every detailβ€”from data layer setup to GTM configurationβ€”for implementing dynamic, reliable Google Ads conversion tracking in osCommerce.

βœ… Why Use GTM for Google Ads Conversions?

  • Simplifies deploymentβ€”no hardcoding Google Ads snippets
  • Enables dynamic value tracking per transaction
  • Supports enhanced conversions and deduplication
  • Scales across multiple campaign types (Search, PMax, Display)

🧰 Prerequisites

  • GTM installed and firing across all osCommerce pages
  • Google Ads account with at least one conversion action set up
  • Access to checkout_success.php in osCommerce
  • Google Ads Conversion ID (AW-XXXXXX) and Conversion Label

πŸ“¦ Step 1: Set Up a Conversion Action in Google Ads

  1. Go to Google Ads β†’ Tools & Settings β†’ Conversions
  2. Click New Conversion Action β†’ Website
  3. Select category: Purchase
  4. Enter conversion name, value settings (use dynamic), and count = one
  5. Choose β€œUse Google Tag Manager”
  6. Copy the Conversion ID and Conversion Label

πŸ›’ Step 2: Push Purchase Data into the Data Layer in osCommerce

In checkout_success.php, push the order data via JavaScript.

βœ… PHP + JS Implementation:

<?php
$order = getOrderDetails($order_id);
$total = $order['total'];
$transaction_id = $order['id'];
?>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
  event: 'purchase',
  transaction_id: '<?= $transaction_id ?>',
  value: <?= $total ?>,
  currency: 'USD'
});
</script>

Replace variables with your store’s dynamic values as appropriate.


🏷️ Step 3: Create Data Layer Variables in GTM

Go to GTM β†’ Variables β†’ New β†’ Data Layer Variable, and set up:

Variable Name Data Layer Variable Name
DL - transaction_id transaction_id
DL - value value
DL - currency currency

Leave the default version as 2.


🧠 Step 4: Create a Trigger for the Purchase Event

  1. Go to GTM β†’ Triggers β†’ New
  2. Trigger Type: Custom Event
  3. Event Name: purchase
  4. Trigger Fires On: All Custom Events
  5. Name it: Trigger - Purchase Event

🏷️ Step 5: Create the Google Ads Conversion Tracking Tag

  1. Go to Tags β†’ New
  2. Choose Tag Type: Google Ads Conversion Tracking
  3. Enter:
    • Conversion ID: AW-XXXXXXX
    • Conversion Label: Your specific label
  4. Conversion Value: {{DL - value}}
  5. Transaction ID: {{DL - transaction_id}} (recommended)
  6. Currency Code: {{DL - currency}}
  7. Trigger: Trigger - Purchase Event

βœ… Tag Summary:

Field Value
Conversion ID AW-XXXXXXX
Conversion Label XXXXXXX
Value {{DL - value}}
Transaction ID {{DL - transaction_id}}
Currency {{DL - currency}}

πŸ” Step 6: Test in GTM Preview & GA Debug Tools

βœ… GTM Preview:

  1. Enable Preview Mode in GTM
  2. Complete a test purchase
  3. Confirm:
    • purchase event appears in Data Layer
    • Google Ads Conversion Tag fires

βœ… Chrome DevTools:

  1. Open Network tab β†’ Filter by ads?
  2. Look for payload sent to googleads.g.doubleclick.net

βœ… Google Tag Assistant:

  • Check for conversion tag success status

πŸ” Optional: Enhanced Conversions (First-Party User Data)

If your Google Ads account supports Enhanced Conversions:

  1. Push user data in checkout_success.php:
dataLayer.push({
user_data: {
email: "<?= $order['customer_email']; ?>",
phone_number: "<?= $order['customer_phone']; ?>"
}
});
  1. In your GTM Conversion Tag:
    • Enable β€œEnhanced Conversions”
    • Choose Use data from the data layer
    • Map variables to {{DL - user_data.email}}, etc.

🧾 Bonus: Deduplicate via Transaction ID

If you’re using both Google Ads tags and GA4 for conversions:

  • Always populate Transaction ID
  • Ensure only one conversion is recorded per order

This prevents duplicate conversions across GA4 β†’ Ads linked imports and GTM-based conversions.


πŸ“Š How to Use Conversion Data in Google Ads

  • View conversion value and cost-per-conversion metrics in campaign reports
  • Use conversions as goals for Smart Bidding (e.g., Maximize ROAS)
  • Segment by device, location, or audience for better optimization

βœ… Summary

You’ve now implemented a robust, scalable Google Ads Conversion Tracking setup in osCommerce using GTM:

  • βœ… Data Layer structure with dynamic transaction data
  • βœ… GA4-compatible Conversion Tag with value and ID
  • βœ… Clean tag firing via Custom Event Trigger
  • βœ… Optional Enhanced Conversions setup

🧠 Expert Tips

Tip Benefit
Add GTM Server-Side for better attribution Blocks ad blockers, preserves session
Use GA4 conversion import instead of tag firing Simpler deduplication, less GTM load
Validate conversion values regularly Avoid bid optimization issues
Link Google Ads ↔ GA4 for unified audiences Streamlines retargeting & reporting

Cross-Domain Conversion Tracking for osCommerce & Landing Pages using GA4 + GTM

Standard

If your marketing flow includes separate landing pages (e.g., on Unbounce, Webflow, or custom domains) that redirect users to your osCommerce store, standard GA4 tracking won’t capture the user session properly β€” leading to broken attribution and missed conversions.

This guide walks you through implementing cross-domain tracking using Google Analytics 4 (GA4) and Google Tag Manager (GTM), ensuring full-funnel visibility from click to purchase.


🎯 Why Cross-Domain Tracking Matters in osCommerce

Without Cross-Domain Tracking With Cross-Domain Tracking
Sessions split between domains Single, unified session across domains
β€œDirect” or β€œ(not set)” traffic sources Correct attribution to source/medium
Inaccurate conversions in Google Ads Accurate ROAS and assisted conversions
Incomplete funnel in GA4 Full view of user journey

βœ… Prerequisites

  • GA4 and GTM installed on:
    • Your landing page domain (e.g., promo.example.com)
    • Your osCommerce store (e.g., shop.example.com)
  • Both domains are under your control
  • GA4 configuration tag already firing on both
  • Shared GTM container or synced setups

🧭 Step 1: Configure GA4 Cross-Domain Measurement in GTM

πŸ”§ Edit Your GA4 Configuration Tag

  1. In GTM, go to Tags β†’ GA4 Configuration
  2. Click to Edit Tag
  3. Expand Fields to Set
  4. Click Add Row
Field Name Value
linker true
linker_domains shop.example.com

(On the store side, use promo.example.com instead if needed)


πŸ§ͺ Example GA4 Config Field Setting in GTM:

[
{ fieldName: "linker", value: true },
{ fieldName: "linker_domains", value: "shop.example.com" }
]

This ensures GA4 passes the _gl parameter between domains to stitch sessions together.

🌍 Step 2: Enable Auto Link Decorator in GTM

In the GA4 Configuration Tag:

  1. Expand Advanced Settings β†’ Tag Sequencing
  2. Ensure this tag fires before other event tags

Alternatively, enable automatic link decoration in the GA4 config itself:

  • Add a trigger to listen for clicks and pass the decorated link using GA4’s linker.

πŸ”— Step 3: Modify Outbound Links on Landing Pages (if needed)

GA4 should auto-decorate links pointing to your osCommerce store. But you can also manually add linker parameters using GTM or JavaScript.

βœ… Example: Manual Link Decoration (if JS injection is possible)

<script>
window.addEventListener('DOMContentLoaded', function () {
var links = document.querySelectorAll('a[href*="shop.example.com"]');
links.forEach(function (link) {
link.href = gtag.get('linker').decorate(link.href);
});
});
</script>

🧾 Step 4: Enable Cross-Domain Measurement in GA4 Admin

  1. Go to GA4 Admin β†’ Data Streams β†’ Your Web Stream
  2. Scroll to Configure tag settings
  3. Click “Configure your domains”
  4. Add:
    • promo.example.com
    • shop.example.com
  5. Save changes

This tells GA4 which domains to treat as the same session context.


🧠 Step 5: Test Cross-Domain Flow

βœ… Use GTM Preview Mode:

  1. Navigate to the landing page
  2. Click a CTA link to go to the osCommerce site
  3. Ensure the URL contains a _gl parameter (e.g. ?_gl=1*abc123...)
  4. Open DevTools β†’ Application β†’ Cookies β†’ Check that GA4 client ID remains consistent across domains

βœ… Use GA4 DebugView:

  • Confirm all events (from landing page to purchase) flow into a single session

πŸ§ͺ Bonus: Push Purchase Data on osCommerce Checkout

In checkout_success.php:

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
event: "purchase",
ecommerce: {
transaction_id: "<?= $order['id']; ?>",
value: <?= $order['total']; ?>,
currency: "USD",
items: <?= json_encode($order['products']); ?>
}
});
</script>

Create a GA4 Event tag in GTM for purchase to finalize the conversion.


πŸ” Step 6: Consent Mode & Privacy Compliance (if needed)

  • Use Consent Mode v2 in GTM if users are in GDPR/CCPA regions
  • Ensure _gl parameters are passed only after consent, or anonymize link decoration

πŸ“Š Post-Setup: How to Use the Data

In GA4:

  • Use Exploration Reports to visualize cross-domain sessions
  • Filter by page_location or page_referrer to see journeys
  • Use Attribution > Conversion Paths for assisted conversions

In Google Ads:

  • Use GA4-linked conversions
  • Create remarketing audiences based on full-funnel behavior

βœ… Summary

With this setup, you’ve enabled accurate cross-domain tracking between your landing pages and osCommerce store, enabling:

  • βœ… Unified user journey across domains
  • βœ… Accurate session attribution for Google Ads
  • βœ… Enhanced conversions and retargeting visibility

πŸ“ Optional Add-ons

  • πŸ”„ Setup server-side GTM to capture linker data with higher accuracy
  • πŸ” Use GA4 audiences to retarget product viewers via Google Ads
  • πŸ“‰ Create Looker Studio dashboards with full funnel + attribution paths

Linking GA4 Audiences with Google Ads for osCommerce Retargeting (Step-by-Step Guide)

Standard

If you’re running an osCommerce store, GA4 audience integration with Google Ads is a powerful way to retarget users based on behavior, such as viewing a product, abandoning the cart, or completing a purchase. This setup allows you to use rich event-based audiences in GA4 to fuel high-precision remarketing campaigns in Google Adsβ€”without needing custom pixels.


🎯 Why Link GA4 Audiences to Google Ads?

  • Run audience-based Google Ads campaigns without managing multiple tags
  • Use cross-platform user signals (e.g., mobile, desktop, engaged sessions)
  • Unlock Predictive Audiences like β€œlikely to purchase in 7 days”
  • Retarget users who performed specific ecommerce actions (product view, add to cart, etc.)

βœ… Prerequisites

  • Google Analytics 4 property set up
  • Google Ads account with Admin access
  • GA4 properly implemented in osCommerce via GTM
  • Audience definition strategy ready (e.g., viewed product but no purchase)

πŸ“¦ Step 1: Link GA4 with Google Ads

  1. Go to GA4 β†’ Admin β†’ Product Links
  2. Select Google Ads β†’ Link
  3. Click “Choose Google Ads accounts” β†’ Select your Ads account
  4. Enable “Enable Personalized Advertising”
  5. Optionally check: Auto-tagging and Audience sharing
  6. Click Next β†’ Then Submit

πŸ› οΈ Step 2: Verify Ecommerce Events Are Flowing in GA4

For proper audience segmentation, ensure the following events are firing:

GA4 Event Triggered On
view_item Product detail page (product_info.php)
add_to_cart Add to cart action
begin_checkout Checkout start
purchase Order success page (checkout_success.php)

You should already be pushing these events via GTM or direct dataLayer.push() calls. Example:

dataLayer.push({
event: 'view_item',
ecommerce: {
items: [{
item_id: 'SKU123',
item_name: 'T-Shirt',
price: 29.99
}]
}
});

GTM should have GA4 Event Tags with the same names firing based on custom event triggers.


🧩 Step 3: Create Audiences in GA4

Go to: GA4 β†’ Admin β†’ Audiences β†’ New Audience

βœ… Example 1: Product Viewers (No Purchase)

Conditions:

  • event_name = view_item
  • AND event_name β‰  purchase within 7 days

βœ… Example 2: Abandoned Cart

Sequence:

  1. add_to_cart occurred
  2. No purchase event within 3 days

βœ… Example 3: Engaged Visitors

  • session_duration > 60 seconds
  • AND event_count > 3

βœ… Example 4: Buyers

  • event_name = purchase

Once saved, these audiences will automatically sync to your linked Google Ads account.


πŸ“€ Step 4: Use GA4 Audiences in Google Ads

  1. Go to Google Ads β†’ Tools & Settings β†’ Audience Manager
  2. You will see your GA4 audience lists prefixed with:
    • GA4 - Product Viewers, GA4 - Abandoned Cart, etc.
  3. You can now:
    • Add them to Search, Display, YouTube, or Performance Max campaigns
    • Use them as observation or targeting segments

πŸ§ͺ Step 5: Test Audience Membership in GA4

To confirm audience membership is working:

  1. In GA4, go to Configure β†’ Audiences
  2. Click on the Audience β†’ See β€œMembership” count
  3. Use GA4 DebugView to simulate events and confirm users qualify

πŸ”„ Optional: Trigger Specific GA4 Events in osCommerce (PHP + JS)

In product_info.php:

<script>
dataLayer.push({
  event: "view_item",
  ecommerce: {
    items: [{
      item_id: "<?= $product['model']; ?>",
      item_name: "<?= $product['name']; ?>",
      price: <?= $product['price']; ?>
    }]
  }
});
</script>

Use GTM to create GA4 event tags for these events with the appropriate triggers.


πŸ” Privacy and Consent Compliance

If your site serves EU or California users:

  • Enable Consent Mode v2 in GTM
  • Use a Consent Management Platform (CMP) to gate tracking
  • Ensure “Enable Ads Personalization” in GA4 respects consent signals

πŸ“ˆ Performance-Based Audience Examples

Audience Name Google Ads Use Case
Product Viewers Dynamic Remarketing Campaigns
Cart Abandoners Display or Search retargeting
Repeat Visitors (3+ visits) Bidding strategy for engaged users
Purchasers Upsell / Cross-sell campaigns

βœ… Summary

With GA4 audience integration in Google Ads, osCommerce store owners can now:

  • βœ… Retarget based on event-driven, user-level signals
  • βœ… Personalize campaigns using dynamic product behavior
  • βœ… Leverage predictive audiences (e.g., likely to purchase soon)
  • βœ… Manage all tracking centrally via GTM + GA4

πŸ“ Optional Add-ons

  • πŸ” Dynamic Remarketing integration via GA4 audiences
  • πŸ”„ Link GA4 predictive audiences to Performance Max campaigns
  • 🧠 Server-side GA4 + Ads audience enrichment for enhanced matching

 

Dynamic Remarketing Tag Setup in osCommerce (Google Ads) via GTM β€” Full Implementation Guide

Standard

Dynamic Remarketing allows Google Ads to show personalized product ads to users based on what they viewed, added to cart, or purchased on your osCommerce store. When implemented via Google Tag Manager (GTM), this setup becomes scalable, structured, and easily customizable without direct code repetition.


βœ… Benefits of Dynamic Remarketing in osCommerce

  • Serve personalized product ads based on user behavior
  • Boost ROAS by showing exact items users interacted with
  • Recover abandoned carts with precision
  • Enable product-level reporting and bidding

🧰 Prerequisites

  • Google Ads account with Merchant Center feed linked
  • Product feed contains unique IDs matching your store’s product SKUs or model numbers
  • Google Tag Manager installed on all osCommerce pages
  • Access to modify product_info.php, shopping_cart.php, checkout_success.php, etc.
  • Your Google Ads Conversion ID (AW-XXXXXXX)

πŸ“¦ Step 1: Understand Required Parameters

Google Ads Dynamic Remarketing requires:

Parameter Description
ecomm_prodid Product ID (must match Merchant Center)
ecomm_pagetype Page type (e.g., product, cart)
ecomm_totalvalue Product or cart total price

πŸ›’ Step 2: Inject Data Layer in Key Pages (PHP + JS)

You’ll need to inject page-specific dataLayer.push() calls on your osCommerce templates.


βœ… Product Detail Page (product_info.php)

<?php
$product = getProductData($product_id); // Your PHP logic
?>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
  event: 'dynamic_remarketing',
  ecomm_pagetype: 'product',
  ecomm_prodid: '<?= $product['model'] ?>',
  ecomm_totalvalue: <?= $product['price'] ?>
});
</script>

βœ… Cart Page (shopping_cart.php)

<?php
$cart_items = getCartItems();
$ids = array_column($cart_items, 'model');
$total = array_sum(array_column($cart_items, 'price'));
?>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
  event: 'dynamic_remarketing',
  ecomm_pagetype: 'cart',
  ecomm_prodid: <?= json_encode($ids) ?>,
  ecomm_totalvalue: <?= $total ?>
});
</script>

βœ… Order Success Page (checkout_success.php)

<?php
$order = getOrderDetails($order_id);
$ids = array_column($order['products'], 'model');
$total = $order['total'];
?>
<script>
dataLayer.push({
  event: 'dynamic_remarketing',
  ecomm_pagetype: 'purchase',
  ecomm_prodid: <?= json_encode($ids) ?>,
  ecomm_totalvalue: <?= $total ?>
});
</script>

βœ… Homepage (index.php)

<script>
dataLayer.push({
  event: 'dynamic_remarketing',
  ecomm_pagetype: 'home'
});
</script>

🏷️ Step 3: Create Data Layer Variables in GTM

Go to Variables β†’ New β†’ Data Layer Variable

GTM Variable Name Data Layer Variable Name
DL - ecomm_prodid ecomm_prodid
DL - ecomm_pagetype ecomm_pagetype
DL - ecomm_totalvalue ecomm_totalvalue

Set Data Layer Version: Version 2


πŸ”§ Step 4: Configure Google Ads Remarketing Tag in GTM

  1. Go to Tags β†’ New
  2. Choose: Google Ads Remarketing Tag
  3. Enter your Conversion ID (AW-XXXXXXX)
  4. Click β€œEnable dynamic remarketing”
  5. Business Type: Retail
  6. Map the parameters:
Parameter GTM Variable
ecomm_prodid {{DL - ecomm_prodid}}
ecomm_pagetype {{DL - ecomm_pagetype}}
ecomm_totalvalue {{DL - ecomm_totalvalue}}

πŸš€ Step 5: Add a Trigger for Dynamic Remarketing Events

  1. Go to Triggers β†’ New
  2. Trigger Type: Custom Event
  3. Event Name: dynamic_remarketing
  4. Trigger fires on: All Custom Events

βœ… Step 6: Test Your Implementation

πŸ§ͺ In GTM:

  • Use Preview Mode
  • Visit a product page, cart, checkout
  • Confirm:
    • dynamic_remarketing event fires
    • Correct variables are populated in GTM

πŸ§ͺ In Google Ads:

  • Use Google Tag Assistant and Conversion Debug Tool
  • Validate parameter values
  • Verify product IDs match those in Merchant Center

πŸ”’ Optional: Use Consent Mode + GTM Server-Side

  • Use Consent Mode v2 to control firing under GDPR/CCPA
  • Route remarketing via Server-side GTM for improved match rates and privacy

πŸ“Š Suggested Use Cases for Audience Lists

Audience Type Remarketing Strategy
Viewed product but didn’t purchase Show product carousels (product ID)
Added to cart but didn’t check out Abandonment campaign with discounts
Viewed homepage only Branding or awareness push
Purchased recently Upsell or cross-sell campaigns

βœ… Summary

With this implementation, you’ve enabled Google Ads Dynamic Remarketing in osCommerce using GTM:

  • βœ… Dynamic data layer across all funnel stages
  • βœ… Remarketing tag with correct product IDs and values
  • βœ… Fully testable, scalable, and Merchant Center-compatible

πŸ“ Optional Enhancements

  • πŸ” Add custom parameters like category, brand
  • πŸ”„ Sync GA4 audiences to Google Ads for advanced targeting
  • 🧠 Use remarketing with Smart Display Campaigns or Performance Max

 

Enhanced Conversions for Google Ads via GTM in osCommerce (Full Setup + Code)

Standard

Enhanced Conversions help Google Ads recover conversion attribution lost due to privacy restrictions or third-party cookie limitations by sending hashed first-party customer data (e.g., email, phone, name) directly to Google. In osCommerce, implementing this via Google Tag Manager (GTM) ensures flexibility, privacy compliance, and minimal code repetition.

🎯 Why Use Enhanced Conversions?

  • Improves attribution accuracy
  • Boosts match rates for conversions (especially on iOS/Safari)
  • Supports smart bidding & remarketing effectiveness
  • Works with both standard and server-side GTM setups

βœ… Prerequisites

  • Google Ads Conversion Action already created
  • GTM installed on all osCommerce pages
  • checkout_success.php editable
  • Customer data (email, phone, etc.) available on order confirmation
  • GDPR/CCPA consent compliance in place (where applicable)

🧾 Step 1: Push Customer Data into the Data Layer (on Purchase)

In your checkout_success.php file, inject the customer data securely:

βœ… PHP + JavaScript Example:

<?php
$order = getOrderDetails($order_id);
?>

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
  event: 'purchase',
  transaction_id: '<?= $order['id'] ?>',
  value: <?= $order['total'] ?>,
  currency: 'USD',
  user_data: {
    email: "<?= $order['customer_email'] ?>",
    phone_number: "<?= $order['customer_phone'] ?>",
    first_name: "<?= $order['customer_firstname'] ?>",
    last_name: "<?= $order['customer_lastname'] ?>",
    address: {
      street: "<?= $order['customer_address'] ?>",
      city: "<?= $order['customer_city'] ?>",
      region: "<?= $order['customer_state'] ?>",
      postal_code: "<?= $order['customer_zip'] ?>",
      country: "<?= $order['customer_country'] ?>"
    }
  }
});
</script>

⚠️ Ensure that this is done only after explicit user consent where required.

🏷️ Step 2: Create Data Layer Variables in GTM

Go to Variables β†’ New β†’ Data Layer Variable. Create the following:

Variable Name Data Layer Variable Name
DL - email user_data.email
DL - phone_number user_data.phone_number
DL - first_name user_data.first_name
DL - last_name user_data.last_name
DL - address_street user_data.address.street
DL - address_city user_data.address.city
DL - address_region user_data.address.region
DL - address_postal_code user_data.address.postal_code
DL - address_country user_data.address.country

πŸ”§ Step 3: Create the Google Ads Conversion Tag with Enhanced Conversions

  1. Go to Tags β†’ New
  2. Choose Google Ads Conversion Tracking
  3. Enter your Conversion ID and Label
  4. Click β€œInclude Enhanced Conversions”
  5. Select: “Use data layer”
  6. Map the variables:
Enhanced Field GTM Variable
Email {{DL - email}}
Phone Number {{DL - phone_number}}
First Name {{DL - first_name}}
Last Name {{DL - last_name}}
Street Address {{DL - address_street}}
City {{DL - address_city}}
Region {{DL - address_region}}
Postal Code {{DL - address_postal_code}}
Country {{DL - address_country}}
  1. In the tag’s Conversion Value, use:
    • {{DL - value}} (set this up as a DL variable too)
  2. Trigger: Use a Custom Event Trigger for purchase

πŸ” Step 4: Configure Trigger for Purchase Event

  1. Go to Triggers β†’ New
  2. Choose: Custom Event
  3. Event name: purchase
  4. Name it: Trigger - Purchase Event

πŸ§ͺ Step 5: Test the Enhanced Conversion Setup

βœ… Use GTM Preview:

  • Navigate to the thank-you page
  • Ensure:
    • purchase event is pushed
    • Google Ads Conversion tag fires

βœ… Use Google’s Enhanced Conversions Helper:

βœ… Chrome DevTools Check:

  • Open Network tab β†’ XHR
  • Look for request to googleads.g.doubleclick.net
  • Check payload includes hashed values (e.g., em, ph)

πŸ” Step 6: Privacy & Consent Considerations

To be GDPR/CCPA-compliant:

  • Only push user_data to the data layer after user consent
  • Use a Consent Management Platform (CMP) with GTM (e.g., Cookiebot, OneTrust)
  • Integrate with Consent Mode v2 in Google

🧠 Pro Tips for osCommerce Integration

Tip Benefit
Hash data before pushing to GTM (optional) Adds extra privacy on frontend
Combine with GA4 purchase tracking One tag β†’ multiple destinations
Implement via GTM Server-Side Even higher attribution & privacy control

βœ… Summary

With this setup, you now have:

  • βœ… Accurate Google Ads purchase conversion tracking
  • βœ… Enhanced Conversions via GTM using first-party customer data
  • βœ… Scalable, privacy-compliant setup for osCommerce

πŸ“ Optional Add-ons

  • πŸ”„ Server-side GTM setup for Enhanced Conversions
  • πŸ“‰ GA4 to Google Ads audience syncing
  • πŸ›’ Dynamic Remarketing using product data in osCommerce

Google Ads Conversion Tracking in osCommerce with GTM

Standard

Setting up Google Ads Conversion Tracking in osCommerce through Google Tag Manager (GTM) allows you to accurately measure post-click performance, optimize campaigns, and unlock Smart Bidding features. This guide walks you through a robust, conversion-accurate setup tailored for osCommerce stores.

βœ… Why Track Google Ads Conversions via GTM?

  • Centralizes tag management without editing theme files
  • Enables dynamic values for conversion tracking (revenue, ID, etc.)
  • Reduces code clutter and improves accuracy
  • Facilitates advanced setups like remarketing and enhanced conversions

🧰 Prerequisites

  • Google Tag Manager installed across all osCommerce pages
  • Google Ads account with conversion actions created
  • Access to osCommerce checkout_success.php
  • Google Ads Conversion ID & Label

πŸ“¦ Step 1: Create a Conversion Action in Google Ads

  1. Go to Tools & Settings β†’ Conversions
  2. Click New conversion action β†’ Website
  3. Choose Category: Purchase or Lead
  4. Set Conversion Name, Value, and Count settings
  5. Choose Tag Setup β†’ Use Google Tag Manager
  6. Copy your Conversion ID and Conversion Label

πŸ›’ Step 2: Push Purchase Data to the Data Layer in osCommerce

In your checkout_success.php file, dynamically inject conversion data like transaction ID, total value, and currency.

βœ… PHP + JavaScript Example:

<?php
$order = getOrderDetails($order_id); // Your backend logic
$items = [];

foreach ($order['products'] as $product) {
  $items[] = [
    'id' => $product['model'],
    'name' => $product['name'],
    'price' => $product['price'],
    'quantity' => $product['quantity']
  ];
}
?>

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
  event: 'purchase',
  transaction_id: '<?= $order['id'] ?>',
  value: <?= $order['total'] ?>,
  currency: 'USD',
  items: <?= json_encode($items) ?>
});
</script>

🧠 Step 3: Create a Trigger in GTM

  1. Go to Triggers β†’ New
  2. Trigger Type: Custom Event
  3. Event Name: purchase
  4. Name it: Trigger - Purchase Event

🏷️ Step 4: Create the Google Ads Conversion Tag

  1. Go to Tags β†’ New
  2. Tag Type: Google Ads Conversion Tracking
  3. Enter your Conversion ID and Label
  4. Conversion Value:
    • Click the icon to add variable
    • Use {{DL - value}} (create this in the next step)
  5. Transaction ID: {{DL - transaction_id}} (optional but recommended)
  6. Currency Code: {{DL - currency}}
  7. Trigger: Use Trigger - Purchase Event

πŸ”§ Step 5: Create Data Layer Variables in GTM

Go to Variables β†’ New β†’ Data Layer Variable

Variable Name Data Layer Variable Name
DL - value value
DL - transaction_id transaction_id
DL - currency currency

Set Version: Version 2 and leave “Data Layer Version” untouched.

πŸ” Step 6: Test the Implementation

  1. Enable Preview Mode in GTM
  2. Go to your site and complete a test purchase
  3. Ensure:
    • The purchase event fires
    • The Google Ads Conversion Tag triggers
    • Correct values (value, currency, transaction_id) are sent
  4. Use Google Tag Assistant and Google Ads Conversion Debug Tool to verify success

πŸ” Optional: Enhanced Conversions for Web

To improve attribution and match rates, enable Enhanced Conversions:

Prerequisites:

  • First-party customer data (email, phone, etc.)
  • Consent is collected if required (GDPR/CCPA compliance)

Add to checkout_success.php:

dataLayer.push({
  user_data: {
    email: "<?= $order['customer_email'] ?>",
    phone_number: "<?= $order['customer_phone'] ?>"
  }
});

In the GTM Google Ads Conversion Tag β†’ Enable Enhanced Conversions β†’ Map variables from the Data Layer.

πŸ“Š Step 7: Monitor Conversions in Google Ads

  • Go to Tools & Settings β†’ Conversions
  • Check if conversions are being recorded (may take up to 24h)
  • Use filters to break down by campaign, ad group, and keyword

πŸ’‘ CRO Tips Post-Setup

Observation Optimization Tactic
Low conversion rate Improve checkout flow or trust UX
High cart abandonment Set up remarketing or email recovery
Delayed conversions Consider using Data-Driven Attribution
Value discrepancies Check dynamic value passing accuracy

βœ… Summary

You’ve now implemented complete Google Ads Conversion Tracking in osCommerce using GTM, including:

  • Dynamic revenue and transaction data
  • Triggered conversion tags based on purchase events
  • Scalable setup for Enhanced Conversions and remarketing

πŸ“ Optional Add-ons

  • Google Ads Remarketing Tag via GTM
  • Server-side GTM for privacy-compliant attribution
  • Google Analytics 4 + Ads linking for audience sync

 

Tracking Refunds & Returns Server-Side for Clean ROAS Reporting in OpenCart

Standard

Most eCommerce setups only send purchase data to analytics platforms, leaving out one critical part of the picture: refunds and returns. Without refund tracking, your Return on Ad Spend (ROAS) is inflated and misleading, especially when using platforms like Google Ads, Meta, and GA4.

By using Server-Side Tagging with OpenCart, we can accurately track refunded transactions and send them back to your analytics toolsβ€”ensuring true revenue-based attribution.


βœ… Why Track Refunds?

Reason Impact
Clean ROAS Exclude refunded revenue from conversions
GA4 Attribution Accuracy Maintain realistic funnel reporting
Google Ads Optimization Avoid over-optimized bids for refunded conversions
Meta Ads CAPI Refund signals improve campaign quality


🧰 Requirements

Item Description
OpenCart Version 3.x or 4.x
Server-Side GTM Configured on a first-party domain
Google Ads, Meta CAPI, GA4 Platforms integrated
Order Status Logic To determine when an order is refunded
Consent Layer (Optional) To handle GDPR/CCPA compliance


🧱 Step 1: Detect Refunded Orders in OpenCart Admin

Modify the refund trigger. In OpenCart, you can hook into order status updates.

In admin/controller/sale/order.php, locate or add code where order status is updated to β€œRefunded” (you may need to define a custom status ID, e.g., 11):

if ($order_status_id == 11) { // 11 = Refunded
$order_info = $this->model_sale_order->getOrder($order_id);
$products = $this->model_sale_order->getOrderProducts($order_id);

$items = [];
foreach ($products as $product) {
$items[] = [
'item_id' => $product['model'],
'item_name' => $product['name'],
'quantity' => $product['quantity'],
'price' => $product['price']
];
}

$refund_payload = [
'event_name' => 'refund',
'event_id' => uniqid('refund_', true),
'transaction_id' => $order_info['order_id'],
'currency' => $order_info['currency_code'],
'value' => -1 * $order_info['total'],
'items' => $items
];

$this->sendRefundToServer($refund_payload);
}


πŸ”Œ Step 2: Send Refund Event to Server-Side GTM

Add this custom helper function in the same file or a reusable module:

private function sendRefundToServer($payload) {
$ch = curl_init('https://gtm.yourdomain.com/event');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}

βœ… This will trigger every time an order is marked as refunded.


🧠 Step 3: Parse Refunds in Server GTM

In your Server Container:

  1. Use the HTTP Request Client
  2. Match incoming event where event_name = refund
  3. Extract transaction_id, items, value, currency, and event_id


πŸ“€ Step 4: Send Refund Event to GA4 via Server GTM

Create a GA4 Event Tag in ssGTM:

Parameter Value
Event Name refund
Transaction ID {{transaction_id}}
Value {{value}}
Currency {{currency}}
Items {{items}}
Event ID {{event_id}}

βœ… This removes refunded purchase value from revenue reports in GA4.


🎯 Step 5: Send Refund to Google Ads

In ssGTM:

  1. Create a Google Ads Conversion Tag
  2. Configure:
    • Conversion ID / Label
    • transaction_id: {{transaction_id}}
    • value: {{value}} (should be negative)
    • currency: {{currency}}
    • event_id: {{event_id}} (deduplication)

βœ… This tells Google Ads the conversion has been reversed.


πŸ“˜ Step 6: Send Refund Event to Meta Conversions API

Use the Meta HTTP tag or a Custom Request:

POST https://graph.facebook.com/v18.0/<PIXEL_ID>/events?access_token=<TOKEN>

{
"data": [{
"event_name": "Refund",
"event_time": {{ timestamp }},
"event_id": "{{event_id}}",
"action_source": "website",
"custom_data": {
"transaction_id": "{{transaction_id}}",
"currency": "{{currency}}",
"value": -99.00
}
}]
}

βœ… Meta will treat it as a revenue correction.


πŸ›‘οΈ Step 7: Consent-Safe Processing

If you’re passing PII (e.g., email for Enhanced Conversions), add this logic:

if ($user_consent_given) {
$payload['email'] = hash('sha256', strtolower($order_info['email']));
}

Or handle consent_granted logic in ssGTM to block tags if needed.


πŸ§ͺ Step 8: QA Your Refund Events

Tool What to Check
ssGTM Preview Inspect payload structure
GA4 DebugView Look for real-time refund event
Google Ads Conversion Tag Diagnostics Check negative conversion
Meta Events Manager β†’ Test Events View refund test data


πŸ“Š Sample Refund Data Sent

{
"event_name": "refund",
"event_id": "refund_664c49d1a3bc9",
"transaction_id": "ORD12842",
"value": -99.99,
"currency": "USD",
"items": [{
"item_id": "PROD001",
"item_name": "Winter Jacket",
"price": 99.99,
"quantity": 1
}]
}


βœ… Benefits Summary

Feature Benefit
True ROAS Calculation Filter out refunded revenue
Attribution Accuracy GA4 funnel metrics adjusted
Ads Optimization Less bias in Smart Bidding or CAPI
First-Party Secure No exposure of refund logic in frontend
Works with All Platforms Google Ads, Meta, GA4, and others


OpenCart Server-Side Tagging: Capturing Email & Phone as First-Party Data

Standard

Capturing first-party data like email and phone in a privacy-compliant way is essential for Enhanced Conversions, Meta CAPI, GA4 attribution, and audience building. With Server-Side Tagging in OpenCart, you can securely hash and forward these identifiers without exposing them in the browser.

🧰 Requirements

Tool Purpose
OpenCart 3.x/4.x Store with checkout success access
Web + Server GTM Containers Installed and linked
GA4 / Google Ads / Meta Pixel Platform integrations
HTTPS Domain For secure user data transfer
Consent Mechanism Required for lawful data capture (GDPR/CCPA)


🎯 Goal

Securely collect and pass email & phone:

  • 🧠 Hashed with SHA-256 before leaving OpenCart
  • πŸš€ Sent via GTM Web to ssGTM endpoint
  • βœ… Delivered to GA4, Google Ads (Enhanced Conversions), Meta CAPI


πŸ“¦ Step 1: Capture Email and Phone on Purchase

In catalog/controller/checkout/success.php:

$order_id = $this->session->data['order_id'];
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);

$email = strtolower(trim($order_info['email']));
$phone = preg_replace('/\D/', '', $order_info['telephone']);

$data['hashed_email'] = hash('sha256', $email);
$data['hashed_phone'] = hash('sha256', $phone);
$data['event_id'] = uniqid('ss_', true);


🧩 Step 2: Push Data to dataLayer (success.twig)

In catalog/view/theme/*/template/checkout/success.twig:

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
event: "purchase",
event_id: "{{ event_id }}",
email: "{{ hashed_email }}",
phone: "{{ hashed_phone }}"
});
</script>

βœ… The dataLayer now holds hashed identifiers and a unique event_id.


πŸ›°οΈ Step 3: Forward Data to Server-Side GTM

In GTM Web Container:

Tag Type: Custom HTML
Trigger: Event equals purchase

<script>
fetch('https://gtm.yoursite.com/event', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
event_name: 'purchase',
email: '{{DL - email}}',
phone: '{{DL - phone}}',
event_id: '{{DL - event_id}}'
})
});
</script>


🧠 Step 4: Setup Clients in Server-Side GTM

Enable these clients:

  • GA4 Client – For enhanced attribution
  • Google Ads Client – For Enhanced Conversions
  • Meta CAPI Client – For matching and optimization

Use event_id, email, phone, and other fields from the request body.


🎯 Step 5: Server-Side Tags Configuration

πŸ“ŒGA4 Tag

Parameter Variable
email {{email}}
phone {{phone}}
event_id {{event_id}}
Event Name purchase

GA4 does not directly use email/phone yet, but this data can be logged or used for custom endpoints.


πŸ“Œ Google Ads Enhanced Conversions Tag

Parameter Value
Conversion ID / Label From Google Ads
Email / Phone {{email}}, {{phone}} (hashed)
Event ID {{event_id}}
Event Name purchase

Google Ads uses hashed values for user matching and deduplication.


πŸ“Œ Meta Conversions API Tag

{
"event_name": "Purchase",
"event_time": {{ timestamp }},
"event_id": "{{event_id}}",
"user_data": {
"em": "{{email}}",
"ph": "{{phone}}"
},
"custom_data": {
"currency": "USD",
"value": 49.99
}
}


πŸ” Step 6: Consent Compliance

Only include email/phone in your dataLayer if consent is granted:

{% if consent_granted %}
<script>
dataLayer.push({
event: "purchase",
email: "{{ hashed_email }}",
phone: "{{ hashed_phone }}",
event_id: "{{ event_id }}"
});
</script>
{% endif %}

Replace consent_granted with your platform’s consent variable.


πŸ§ͺ Step 7: QA & Validation

Tool Use
GTM Preview (Web & Server) Validate email, phone, event_id
GA4 DebugView Track server events
Google Ads Conversion Diagnostics Match rate and Enhanced Conversion
Meta Events Manager β†’ Test Events See hashed PII payloads


🧠 Pro Tips

Tip Why
Always hash on the backend Protects user data from browser leakage
Deduplicate with event_id Avoids double counting
Reuse same email for audience match Helps cross-session attribution
Use logging in ssGTM Debug data without sending to platforms


πŸ“Š Example Attribution Path

User completes purchase
↓
OpenCart hashes email & phone server-side
↓
Pushes to dataLayer with event_id
↓
Web GTM sends payload to ssGTM
↓
ssGTM sends:
- GA4 event with ID
- Google Ads EC with PII
- Meta CAPI with PII
↓
Platforms match user β†’ higher attribution


Server-Side Tracking for Enhanced Attribution in a Privacy-First World

Standard

In the age of iOS restrictions, browser-level privacy controls, and regulations like GDPR/CCPA, client-side tracking is no longer sufficient. If you’re still relying solely on browser-based pixels, you’re losing attribution data, revenue insights, and campaign efficiency.

Server-Side Tracking (SST) bridges this gap by moving data collection and event forwarding to a secure, first-party environment. This guide walks you through how to implement a privacy-compliant, robust server-side tracking architecture using Google Tag Manager Server-Side (ssGTM) for platforms like GA4, Google Ads, Meta CAPI, and others.

🎯 What You’ll Learn

  • Why SST is essential for modern attribution
  • How to configure a server-side endpoint
  • How to securely collect and hash first-party data
  • How to send server events to GA4, Google Ads, Meta
  • How to handle consent and deduplication


🧰 Prerequisites

Requirement Purpose
Google Tag Manager (Web + Server) Tag execution client/server side
DNS Setup (gtm.yoursite.com) First-party server endpoint
GA4 / Google Ads / Meta Pixel To receive the data
Optional: Consent Management Platform For lawful user data usage


πŸ”’ Why Server-Side Tracking is Critical

Problem (Client-Side) Solution (Server-Side)
Cookie blocking First-party endpoint
Ad blockers Server IP is not blocked
Short cookie lifetimes Extend via HTTP headers
PII risk in browser Server-side hashing
Loss of conversions Direct server delivery


🧱 Step 1: Deploy Server-Side GTM

  1. Go to tagmanager.google.com
  2. Create a Server Container
  3. Host on:
    • App Engine or Cloud Run
    • OR custom infrastructure
  4. Set DNS: gtm.yoursite.com β†’ Server IP

βœ… This creates your private server tracking endpoint.


πŸ’¬ Step 2: Send Events from Web to Server

Create a custom HTML tag in Web GTM:

<script>
fetch('https://gtm.yoursite.com/event', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
event_name: 'purchase',
transaction_id: '{{DL - transaction_id}}',
value: '{{DL - value}}',
currency: '{{DL - currency}}',
email: '{{DL - email}}',
phone: '{{DL - phone}}',
event_id: '{{DL - event_id}}',
user_agent: navigator.userAgent,
client_ip: '{{DL - client_ip}}'
})
});
</script>

βœ… You are now forwarding conversion data securely to your server.


πŸ” Step 3: Sanitize and Hash PII

In your Web layer or backend (recommended), hash sensitive data using SHA-256:

$email = hash('sha256', strtolower(trim($user_email)));
$phone = hash('sha256', preg_replace('/\D/', '', $user_phone));

βœ… This ensures compliance with Meta CAPI and Google Ads Enhanced Conversions.


🎯 Step 4: Setup Clients in Server GTM

Inside ssGTM:

  1. Enable:
    • GA4 Client
    • Google Ads Conversion Client
    • HTTP Request Client (for custom requests)
  2. Preview incoming data via Server GTM Preview Mode

βœ… Server GTM can now parse your event data.


πŸ“€ Step 5: Configure Server Tags for Each Platform


πŸ…°οΈ GA4 Event Tag

  • Tag Type: GA4 Event
  • Event Name: purchase / lead / etc.
  • Parameters: transaction_id, value, currency, event_id, etc.
  • Measurement ID: G-XXXXXX


πŸ…±οΈ Google Ads Conversion Tag

  • Tag Type: Google Ads Conversion
  • Conversion ID / Label from Ads UI
  • Include:
    • email, phone (hashed)
    • transaction_id
    • value, currency
    • event_id for deduplication


πŸ…ΎοΈ Meta Conversions API Tag

Use Meta’s CAPI template or HTTP request:

POST https://graph.facebook.com/v18.0/<PIXEL_ID>/events?access_token=<TOKEN>
{
"data": [{
"event_name": "Purchase",
"event_time": {{ timestamp }},
"event_id": "{{event_id}}",
"user_data": {
"em": "{{email}}",
"ph": "{{phone}}",
"client_ip_address": "{{client_ip}}",
"client_user_agent": "{{user_agent}}"
},
"custom_data": {
"currency": "{{currency}}",
"value": "{{value}}",
"transaction_id": "{{transaction_id}}"
}
}]
}

βœ… Add fbc and fbp cookies for improved match rate if available.


🧠 Step 6: Deduplicate Events

Always use a unique event_id per conversion event and send it:

  • In the client-side tag (browser pixel)
  • In the server-side tag (CAPI or Ads API)

Platforms like Meta and Google will automatically deduplicate.


πŸ›‘οΈ Step 7: Handle Consent States

Use a CMP or your own logic to check consent before firing server events:

if (window.gtag && gtag.get('consent', 'ad_storage') === 'granted') {
// send fetch to ssGTM
}

You can also send a consent_granted: true/false flag to ssGTM and skip server tags conditionally.


πŸ§ͺ Step 8: QA and Debug

Tool Use
GTM Preview Validate Web + Server hits
GA4 DebugView See real-time events
Meta Events Manager CAPI Test Events
Google Ads Tag Diagnostics Server conversion status


πŸ“Š Example Use Case: Purchase Attribution

User completes purchase
↓
Hashed email + phone sent to ssGTM
↓
Server GTM sends events:
β†’ GA4 (via Measurement Protocol)
β†’ Google Ads (Enhanced Conversions)
β†’ Meta CAPI
↓
All use same `event_id` β†’ deduplication & attribution


πŸ”’ Security Best Practices

  • Hash PII before it leaves the client
  • Use HTTPS and first-party domain (e.g., gtm.yoursite.com)
  • Log requests securely on your server for audits
  • Rate-limit and secure endpoints with tokens if needed


πŸš€ Optional Add-Ons

Feature Use
First-Party Cookies For GCLID, FBCLID, etc.
Header forwarding Capture UTM, IP, and User-Agent
Consent-aware flows GDPR/CCPA safe
BigQuery Export Raw event stream for analysis