Google Ads Order Attribution

Understanding how Alpha Insights attributes your actual WooCommerce orders to specific Google Ads campaigns is essential for accurate profit analysis and campaign optimization. This guide explains the technical details of how order attribution works for Google Ads and how to set it up correctly.

What is Order Attribution?

Order attribution is the process of matching your WooCommerce orders to the specific Google Ads campaign that drove the customer to your store. This enables Alpha Insights to calculate true profit by campaign, accounting for actual product costs, shipping, fees, and all other expenses—not just the revenue metrics from Google's API.

Two Types of Data in Alpha Insights

1. Google Ads API Data (Campaign Performance Metrics)

2. Alpha Insights Order Attribution (Your Actual Orders)

How Google Ads Order Attribution Works

Google Ads attribution in Alpha Insights uses two methods, with the google_cid parameter being the primary and most reliable method:

Method 1: google_cid Parameter (Primary Method) ★ REQUIRED

CRITICAL: To enable order attribution, you MUST add the google_cid parameter to all your Google ad URLs.

Parameter format:

google_cid={campaignid}

How it works:

  1. You manually add google_cid={campaignid} to your ad URLs
  2. Google replaces {campaignid} with the actual campaign ID
  3. Customer clicks ad and lands on: https://yourstore.com/products?google_cid=987654321
  4. Alpha Insights captures the landing page with google_cid in first-party cookie
  5. Customer completes checkout and places order
  6. Alpha Insights extracts the campaign ID from google_cid parameter
  7. Campaign ID saved directly to order: _wpd_ai_google_campaign_id
  8. Order permanently linked to Google Ads campaign

Why this is the primary method:

Example setup:

Original URL:
https://yourstore.com/products

With tracking parameter:
https://yourstore.com/products?google_cid={campaignid}

If URL already has parameters:
https://yourstore.com/products?utm_source=google&google_cid={campaignid}

Method 2: GCLID Auto-Tagging (Supplementary Method)

GCLID (Google Click Identifier) is a unique parameter that Google automatically adds to your landing page URLs when auto-tagging is enabled. Alpha Insights can attempt to match GCLIDs to campaigns via the Google Ads API as a supplementary attribution method.

How it works:

  1. Auto-tagging enabled in Google Ads
  2. Google automatically appends GCLID to landing URLs: https://yourstore.com/products?gclid=Cj0KCQiA...
  3. Alpha Insights captures landing page with GCLID
  4. Background process queries Google Ads API to match GCLID to campaign ID
  5. Campaign ID saved to order if match found

Important limitations of GCLID method:

Recommendation: Always use the google_cid parameter as your primary attribution method. GCLID can provide supplementary attribution but should not be relied upon as the sole method.

Required Setup: Add google_cid Parameter

CRITICAL: For accurate order attribution, you MUST add the google_cid parameter to all your Google ad URLs.

How to Add google_cid to Your Ad URLs

In Google Ads:

  1. Go to your Google Ads account
  2. Navigate to Campaigns
  3. Click on the campaign you want to edit
  4. Go to Settings
  5. Expand Additional settings
  6. Click Campaign URL options
  7. In the Tracking template or Final URL suffix field, add:
    google_cid={campaignid}
  8. If using Final URL suffix: ?google_cid={campaignid}
    (use &google_cid={campaignid} if your URLs already have parameters)
  9. Click Save

Alternative: Add to individual ads

What happens:

Verification:

After adding the parameter, click one of your own ads and check the URL you land on. You should see:

https://yourstore.com/products?google_cid=1234567890

If you see the google_cid parameter with a numeric campaign ID, it's working correctly!

Optional: Enable Auto-Tagging for Supplementary GCLID Tracking

In addition to the required google_cid parameter, you can optionally enable auto-tagging for supplementary GCLID tracking:

  1. Go to Google Ads → Settings → Account settings
  2. Scroll to Tracking section
  3. Check: "Tag the URL that people click through from my ad"
  4. Click Save

Note: This is optional and provides backup attribution, but google_cid remains the primary method.

Understanding the Attribution Process

The Complete Attribution Flow

  1. Customer clicks Google ad
  2. Landing page captured
  3. Customer browses and shops
  4. Order is created at checkout
  5. Background: GCLID lookup (within 90 days)
  6. Order appears in campaign reports

Visual Flow Diagram (Primary Method: google_cid)

Google Ad Click
     ↓
Landing: yourstore.com/products?google_cid=987654321
     ↓
Cookie Stored: wpd_ai_landing_page = "yourstore.com/products?google_cid=987654321"
     ↓
Customer Browses & Adds to Cart
     ↓
Order Created (#5002)
     ↓
Order Meta Saved:
  _wpd_ai_landing_page = "yourstore.com/products?google_cid=987654321"
     ↓
Attribution Process:
  Extract google_cid from query params → Campaign ID = "987654321"
     ↓
Order Meta Updated:
  _wpd_ai_google_campaign_id = "987654321"
     ↓
Report: Order #5002 attributed to Campaign 987654321

If GCLID auto-tagging also enabled (supplementary):

Landing: yourstore.com/products?google_cid=987654321&gclid=Cj0KCQiA...
     ↓
Primary attribution: google_cid extracted immediately
Backup attribution: GCLID can be looked up via API if google_cid fails

Code Reference

Order attribution logic:

Understanding Attribution Behavior

GCLID API Lookup Process

How GCLID-to-Campaign Matching Works:

  1. Order created with GCLID in landing page
  2. Alpha Insights marks order for lookup
  3. Background process queries Google API
  4. Campaign ID returned and saved

Important Limitations:

What happens if GCLID lookup fails:

Cookie Lifetime and Session Tracking

Cookie Duration: 10 minutes by default (refreshes with activity)

What this means:

Example scenario:

  1. Customer clicks Google ad at 2:00 PM → lands with GCLID
  2. Browses products for 5 minutes
  3. Leaves site at 2:05 PM
  4. Returns directly (not via ad) at 2:08 PM
  5. Cookie still has original GCLID landing page
  6. Places order at 2:12 PM
  7. Order attributed to original Google ad campaign ✓

Attribution Window

No Fixed Attribution Window: Unlike Google's conversion tracking (which uses 30-day or 90-day windows), Alpha Insights doesn't use time-based attribution windows.

How it works instead:

Practical limitation:

Retroactive Attribution

Alpha Insights can automatically process recent orders and match GCLIDs to campaigns:

Automatic Processing Methods:

1. Query Parameter Method (google_cid)

2. GCLID API Lookup Method (Primary)

When these run:

Orders Without Campaign Attribution

An order will NOT be attributed to a specific Google Ads campaign if:

How these orders appear in reports:

Technical Note: In the data warehouse code, when querying orders by Google campaign, if no _wpd_ai_google_campaign_id is found but a GCLID exists, the order is assigned campaign_id = 'unknown' and grouped separately.

Viewing Attributed Orders

Once orders are attributed to Google Ads campaigns, you can view them in Alpha Insights reports to analyze performance and profitability.

Google Ads Report

The primary way to view attributed orders is through the dedicated Google Ads report:

Access: Alpha Insights → Reports → Google Ads

What you'll see:

Report Features:

Key Metrics:

Individual Campaign View

Click on any campaign in the Google Ads report to see detailed attribution:

Custom Reports

You can also create custom reports to analyze Google Ads attribution:

Access: Alpha Insights → Reports → Create New Report

Select Entity: Google Campaigns

Available Data:

Example Use Cases:

Order Details (Individual Order View)

For troubleshooting or verification, you can view attribution data on individual orders:

Access: WooCommerce → Orders → [Order ID]

Alpha Insights adds an attribution panel showing:

Example query parameters you might see:

google_cid: 1234567890
gclid: Cj0KCQiA8vOsBhCkARIsAGITMepH...
utm_source: google
utm_medium: cpc

Use this for:

Data Warehouse (For Developers)

The React data warehouse provides programmatic access to attributed orders:

Available Columns: All standard order columns plus campaign-specific metrics

Troubleshooting Attribution Issues

Issue: Orders Not Being Attributed

Symptom: Campaign has ad spend but no orders showing in Alpha Insights campaign reports

Possible Causes & Solutions:

  1. Missing google_cid parameter in ad URLs ★ MOST COMMON
  2. Parameter added incorrectly
  3. Landing pages don't preserve query parameters
  4. Landing page tracking not working
  5. Orders placed before parameter was added
  6. Cookies blocked or cleared

Issue: Wrong Campaign Attribution

Symptom: Order attributed to wrong Google campaign

Possible Causes:

Manual Override: You can manually change the attributed campaign in WooCommerce → Orders → Order Details → Alpha Insights attribution panel → Select different campaign from dropdown

Issue: GCLID Present But No Campaign Match

Symptom: Order has GCLID in landing page but _wpd_ai_google_campaign_id is empty

Possible Reasons:

  1. API lookup hasn't run yet
  2. API lookup failed
  3. Order date doesn't match click date
  4. GCLID expired or invalid

Best Practices for Accurate Attribution

1. Use google_cid on ALL Google Ads ★ REQUIRED

This is absolutely essential:

2. Optionally Enable Auto-Tagging for Backup

For supplementary tracking:

Recommended setup:

Primary: google_cid={campaignid} (REQUIRED)
Supplementary: Auto-tagging enabled (optional backup)

3. Test Your Attribution Setup

Testing steps:

  1. Add google_cid={campaignid} to one of your ad URLs
  2. Click your own ad (or use Preview mode)
  3. Verify google_cid appears in landing page URL with a campaign ID number
  4. Place a test order on your site
  5. Go to WooCommerce → Orders → Your test order
  6. Check Alpha Insights attribution panel
  7. Verify google_cid appears in query parameters
  8. Verify "Google Campaign" dropdown shows correct campaign
  9. Check the Google Ads report to confirm order appears under that campaign

4. Monitor Attribution Success Rate

Regularly check:

Good indicators:

Red flags:

5. Understand Data Discrepancies

Expect differences between:

Why they differ:

Which to trust? Use Alpha Insights order attribution for business decisions—it's based on your actual orders with real costs. Use Google metrics for comparison to their reported performance.

Alternative Tracking: UTM Parameters

Using Standard UTM Parameters

While not necessary with auto-tagging, you can also use UTM parameters for additional tracking:

?utm_source=google&utm_medium=cpc&utm_campaign={campaignid}

Benefits:

Limitations:

Best practice: Use auto-tagging (GCLID) for attribution, UTM parameters for traffic analysis.

Technical Implementation Details

Database Schema

Order Meta Keys:

_wpd_ai_landing_page                    (Full landing URL with GCLID/parameters)
_wpd_ai_referral_source                 (Referrer URL, e.g. google.com)
_wpd_ai_google_campaign_id              (Campaign ID from GCLID lookup or google_cid)
_wpd_ai_google_api_campaign_id_check    (Temporary flag: GCLID lookup attempted)

Campaign Post Type:

Post Type: google_ad_campaign
Taxonomy: ad_account
Meta Fields: _wpd_campaign_id, _wpd_campaign_name, _wpd_campaign_spend, etc.

Key PHP Functions

1. Save Landing Page to Order

Method: WPDAI_Core->save_landing_page_to_order_meta($order)
Hook: woocommerce_checkout_order_processed
Action: Reads cookies, saves landing page and referral to order meta,
        extracts google_cid if present and saves to _wpd_ai_google_campaign_id

2. Retroactive Attribution via Query Parameter

Method: WPDAI_Google_Ads_API->set_order_campaign_id_via_query_param($days)
Action: Queries last X days of orders with google_cid in landing page,
        extracts campaign ID, saves to order meta
Default: 30 days

3. GCLID Lookup via API

Method: WPDAI_Google_Ads_API->set_order_campaign_id_via_api_last_x_days($days, $hard_refresh)
Action: Queries orders with GCLID, looks up campaign ID via Google Ads API,
        saves campaign ID to order meta
Default: 30 days
Limit: 90 days (Google API restriction)
Throttling: 0.5 second delay between requests

4. API Campaign Lookup by GCLID

Method: WPDAI_Google_Ads_API->api_fetch_campaign_id_by_gclid($gclid, $date)
API Query: SELECT campaign.id, campaign.name FROM click_view 
           WHERE segments.date = 'YYYY-MM-DD' AND click_view.gclid = 'GCLID'
Returns: Campaign ID or false if not found

5. Query Orders by Campaign

Method: WPDAI_Data_Warehouse->get_google_campaign_order_data($date_from, $date_to)
Action: Fetches orders with _wpd_ai_google_campaign_id OR orders with GCLID,
        groups by campaign ID, calculates metrics
Returns: Array of order data indexed by campaign ID
Note: Orders with GCLID but no campaign ID are marked as "unknown"

JavaScript Tracking

File: wpd-alpha-insights-event-tracking.js

Key Functions:

Data Warehouse Integration

Entity: google_campaigns

Available Indexes:

Order Query Logic (conceptual):

// Get orders with campaign ID
SELECT orders WHERE _wpd_ai_google_campaign_id = 'campaign_123'

// Get orders with GCLID (may not have campaign ID yet)
SELECT orders WHERE _wpd_ai_landing_page LIKE '%gclid=%'

// Combined for comprehensive reporting

Comparing Attribution Models

Google Ads Conversion Tracking vs Alpha Insights Attribution

Factor Google Ads Alpha Insights
Method Conversion tracking tag GCLID + first-party cookie + order meta
Attribution Window 30 days (default, configurable) No time limit (based on landing page cookie)
View-Through Conversions Yes (optional) No (click required)
Cross-Device Tracking Yes (Google account-based) No (cookie-based, single device)
Data Shown In Google Ads interface, Alpha Insights API metrics Alpha Insights order reports
Includes COGS No Yes
Product-Level Detail Limited Full detail (product, quantity, costs)
Best For Comparing to Google reports, optimization in Google Ads True profit analysis, business decisions

Why Numbers Differ

You'll often see different order/revenue numbers between:

This is normal! Each system measures differently:

Typical discrepancy: Google Ads may report 20-40% more conversions than Alpha Insights attributes (due to cross-device and view-through conversions).

Which to trust? Use Alpha Insights order attribution for business decisions and profit analysis. Use Google Ads metrics for campaign optimization within the Google Ads platform.

Summary

Google Ads order attribution in Alpha Insights works by:

  1. Requiring the google_cid={campaignid} parameter in all ad URLs (PRIMARY METHOD)
  2. Capturing landing page URLs with google_cid when customers click ads
  3. Storing landing page data in first-party cookies
  4. Extracting campaign ID directly from google_cid parameter
  5. Saving campaign ID to order meta when orders are created
  6. Linking orders to campaigns for true profit reporting
  7. Optionally using GCLID auto-tagging as supplementary attribution

Key Takeaways:

For questions about setting up attribution or troubleshooting issues, see the Google Ads Troubleshooting Guide.