Facebook Ads Order Attribution

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

What is Order Attribution?

Order attribution is the process of matching your WooCommerce orders to the specific Facebook advertising 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 simplified metrics from Facebook's API.

Two Types of Data in Alpha Insights

1. Facebook API Data (Campaign Performance Metrics)

2. Alpha Insights Order Attribution (Your Actual Orders)

How Facebook Order Attribution Works

The Attribution Process

Alpha Insights uses a query parameter system to track which campaign a customer came from:

  1. Customer clicks your Facebook ad containing the tracking parameter
  2. Landing page URL is captured and stored in a first-party cookie (wpd_ai_landing_page)
  3. Customer browses your store (can leave and return within cookie lifetime)
  4. Customer completes checkout and places an order
  5. Alpha Insights saves attribution data to the order:
  6. Order is permanently linked to the Facebook campaign for reporting

Visual Flow Diagram

Facebook Ad Click
     ↓
Landing Page: yourstore.com/products?meta_cid=123456789
     ↓
Cookie Stored: wpd_ai_landing_page = "yourstore.com/products?meta_cid=123456789"
     ↓
Customer Browses (session tracked, cookie persists)
     ↓
Order Created (#5001)
     ↓
Order Meta Saved:
  _wpd_ai_landing_page = "yourstore.com/products?meta_cid=123456789"
  _wpd_ai_meta_campaign_id = "123456789"
     ↓
Report: Order #5001 attributed to Campaign 123456789

Required Setup: The meta_cid Parameter

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

Parameter Format

Add this to every Facebook ad destination URL:

meta_cid={{campaign.id}}

How to Add the Parameter

In Facebook Ads Manager:

  1. Go to your ad or ad set settings
  2. Find the Website URL or Destination field
  3. Add the parameter to your URL

Example URLs:

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

With tracking parameter:
https://yourstore.com/products?meta_cid={{campaign.id}}

If URL already has parameters:
https://yourstore.com/products?utm_source=facebook&meta_cid={{campaign.id}}

What Happens Behind the Scenes

  1. Facebook automatically replaces {{campaign.id}} with the actual campaign ID (e.g., 23851234567890123)
  2. Your visitor lands on: https://yourstore.com/products?meta_cid=23851234567890123
  3. Alpha Insights JavaScript captures the landing page URL
  4. URL stored in cookie: wpd_ai_landing_page
  5. At checkout, Alpha Insights extracts meta_cid=23851234567890123 from the landing page
  6. Campaign ID 23851234567890123 saved to order meta: _wpd_ai_meta_campaign_id

Code Reference: Attribution logic is in WPDAI_Core->save_landing_page_to_order_meta() (lines 1312-1357) and WPDAI_Facebook_API->set_order_campaign_id_via_query_param() (lines 435-491)

Understanding Attribution Behavior

Cookie Lifetime and Session Tracking

Cookie Duration: 10 minutes by default

What this means:

Important: Orders are attributed based on first landing page from the cookie. If a customer clicks a Facebook ad, browses your site, leaves, then returns directly (without clicking an ad again), the order will still be attributed to the original Facebook campaign as long as they complete checkout within a reasonable timeframe.

Attribution Window

No Fixed Attribution Window: Alpha Insights doesn't use time-based attribution windows like "7-day click" or "30-day view."

How it works instead:

Why this matters: A customer could click your ad in January, and if they return in March and place an order (and still have the landing page data), it would be attributed to that campaign. In practice, cookies expire, so most attribution happens within days or weeks of the initial click.

Retroactive Attribution (Last 30 Days)

Alpha Insights can automatically check recent orders and assign campaign IDs retroactively:

Method: set_order_campaign_id_via_query_param()

What it does:

  1. Checks the last 30 days of orders
  2. Looks for orders with meta_cid in their landing page URL
  3. Extracts the campaign ID from the query parameter
  4. Saves it to _wpd_ai_meta_campaign_id order meta

When this runs:

Use case: If you just added the meta_cid parameter to your ads, this function can go back and attribute orders from the last 30 days that have the parameter in their landing page.

Orders Without Campaign Attribution

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

How these orders appear in reports:

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

Viewing Attributed Orders

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

Facebook Ads Report

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

Access: Alpha Insights → Reports → Facebook Ads

What you'll see:

Report Features:

Key Metrics:

Individual Campaign View

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

Custom Reports

You can also create custom reports to analyze Facebook attribution:

Access: Alpha Insights → Reports → Create New Report

Select Entity: Facebook 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:

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 meta_cid parameter in ad URLs
  2. Parameter added incorrectly
  3. Landing page tracking not working
  4. Orders placed before parameter was added
  5. Cookies blocked or cleared
  6. Customer took long path to purchase

Issue: Wrong Campaign Attribution

Symptom: Order attributed to wrong 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: Attribution Data Missing from Orders

Symptom: Old orders don't have landing page or campaign attribution

Explanation:

Best Practices for Accurate Attribution

1. Use meta_cid on ALL Facebook Ads

Consistency is key:

2. Don't Mix Attribution Systems

Avoid using multiple campaign ID parameters:

3. Test Your Attribution Setup

How to test:

  1. Create a test ad with meta_cid={{campaign.id}}
  2. Click your own ad (or use Facebook's "Preview" feature)
  3. Note the campaign ID in the URL when you land
  4. Place a test order on your site
  5. Go to WooCommerce → Orders → Your test order
  6. Check Alpha Insights attribution panel
  7. Verify meta_cid appears in query parameters
  8. Verify "Meta Campaign" dropdown shows the correct campaign

4. Document Your Campaign IDs

Keep a spreadsheet tracking:

This helps troubleshoot attribution issues later.

5. Monitor Unattributed Orders

Regularly check how many orders are categorized as "unknown":

Technical Implementation Details

Database Schema

Order Meta Keys:

_wpd_ai_landing_page        (Full landing URL with query params)
_wpd_ai_referral_source     (Referrer URL, e.g. facebook.com)
_wpd_ai_meta_campaign_id    (Extracted campaign ID from meta_cid)

Campaign Post Type:

Post Type: facebook_campaign
Taxonomy: ad_account
Meta Fields: _wpd_campaign_id, _wpd_campaign_name, 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 meta_cid and saves to _wpd_ai_meta_campaign_id

2. Retroactive Attribution

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

3. Query Orders by Campaign

Method: WPDAI_Data_Warehouse->get_facebook_campaign_order_data($date_from, $date_to)
Action: Fetches all orders with _wpd_ai_meta_campaign_id,
        groups by campaign ID, calculates metrics
Returns: Array of order data indexed by campaign ID

JavaScript Tracking

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

Key Functions:

Data Warehouse Integration

Entity: facebook_campaigns

Available Indexes:

Query Example (conceptual):

SELECT orders
WHERE _wpd_ai_meta_campaign_id = '123456789'
AND date_created BETWEEN '2024-01-01' AND '2024-01-31'
AND order_status IN ('completed', 'processing')

Comparing Attribution Models

Facebook Pixel Attribution vs Alpha Insights Attribution

Factor Facebook Pixel Alpha Insights
Method JavaScript pixel tracking First-party cookie + order meta
Attribution Window 7-day click, 1-day view (default) No time limit (based on landing page)
View-Through Attribution Yes (saw ad, didn't click, later purchased) No (click required)
Data Shown In Facebook Ads Manager, Alpha Insights campaign metrics Alpha Insights order reports
Includes COGS No Yes
Product-Level Detail Limited Full detail
Best For Comparing to Facebook reports, broad metrics True profit analysis, business decisions

Why Numbers Differ

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

This is normal! Each system measures differently:

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

Summary

Facebook order attribution in Alpha Insights works by:

  1. Requiring the meta_cid={{campaign.id}} parameter in all Facebook ad URLs
  2. Capturing the landing page URL when customers click ads
  3. Storing the landing page in first-party cookies
  4. Saving campaign attribution to order meta when orders are created
  5. Linking orders to campaigns for true profit reporting

Key Takeaway: Without the meta_cid parameter in your ad URLs, Alpha Insights cannot attribute orders to specific campaigns. This parameter is absolutely essential for accurate profit tracking by campaign.

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