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.
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.
1. Facebook API Data (Campaign Performance Metrics)
2. Alpha Insights Order Attribution (Your Actual Orders)
Alpha Insights uses a query parameter system to track which campaign a customer came from:
wpd_ai_landing_page)_wpd_ai_landing_page order meta_wpd_ai_referral_source order meta_wpd_ai_meta_campaign_id order metaFacebook 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
CRITICAL: To enable order attribution, you MUST add the meta_cid parameter to all your Facebook ad URLs.
Add this to every Facebook ad destination URL:
meta_cid={{campaign.id}}
In Facebook Ads Manager:
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}}
{{campaign.id}} with the actual campaign ID (e.g., 23851234567890123)https://yourstore.com/products?meta_cid=23851234567890123wpd_ai_landing_pagemeta_cid=23851234567890123 from the landing page23851234567890123 saved to order meta: _wpd_ai_meta_campaign_idCode 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)
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.
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:
meta_cid parameter in the landing page URLmeta_cid, the order is attributed to that campaignWhy 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.
Alpha Insights can automatically check recent orders and assign campaign IDs retroactively:
Method: set_order_campaign_id_via_query_param()
What it does:
meta_cid in their landing page URL_wpd_ai_meta_campaign_id order metaWhen 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.
An order will NOT be attributed to a specific campaign if:
meta_cid parametermeta_cid value is not numeric (malformed)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.
Once orders are attributed to Facebook campaigns, you can view them in Alpha Insights reports to analyze performance and profitability.
The primary way to view attributed orders is through the dedicated Facebook Ads report:
Access: Alpha Insights → Reports → Facebook Ads
What you'll see:
meta_cidReport Features:
Key Metrics:
campaign_order_count - Total number of orders attributed to campaignscampaign_order_revenue - Net sales from attributed orderscampaign_order_profit - Gross profit (before ad spend)campaign_actual_profit - Net profit (after ad spend)campaign_revenue_roas - Revenue ROAS based on attributed ordersClick on any campaign in the Facebook Ads report to see detailed attribution:
You can also create custom reports to analyze Facebook attribution:
Access: Alpha Insights → Reports → Create New Report
Select Entity: Facebook Campaigns
Available Data:
facebook_campaigns:campaigns - Campaign-level metricsfacebook_campaigns:orders - Individual attributed ordersfacebook_campaigns:products - Products sold via campaignsExample Use Cases:
For troubleshooting or verification, you can view attribution data on individual orders:
Access: WooCommerce → Orders → [Order ID]
Alpha Insights adds an attribution panel showing:
meta_cidUse this for:
The React data warehouse provides programmatic access to attributed orders:
facebook_campaignsfacebook_campaigns:orders_wpd_ai_meta_campaign_id meta keyAvailable Columns: All standard order columns plus campaign-specific metrics
Symptom: Campaign has ad spend but no orders showing in Alpha Insights campaign reports
Possible Causes & Solutions:
?meta_cid={{campaign.id}} to all ad URLsmeta_cid exactly (case-sensitive, underscore not hyphen)meta-cid or metacid or fb_cid won't workmeta_cid={{campaign.id}}meta_cidSymptom: Order attributed to wrong campaign
Possible Causes:
meta_cid landing page)Manual Override: You can manually change the attributed campaign in WooCommerce → Orders → Order Details → Alpha Insights attribution panel → Select different campaign from dropdown
Symptom: Old orders don't have landing page or campaign attribution
Explanation:
Consistency is key:
meta_cid={{campaign.id}} to every single ad you createAvoid using multiple campaign ID parameters:
?meta_cid={{campaign.id}}&campaign_id={{campaign.id}}meta_cid—additional parameters won't improve trackingHow to test:
meta_cid={{campaign.id}}meta_cid appears in query parametersKeep a spreadsheet tracking:
This helps troubleshoot attribution issues later.
Regularly check how many orders are categorized as "unknown":
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.
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
File: wpd-alpha-insights-event-tracking.js
Key Functions:
wpd_ai_landing_pageEntity: facebook_campaigns
Available Indexes:
campaigns - Campaign performance metricsorders - Orders attributed to campaignsproducts - Products sold via campaignsQuery 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')
| 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 |
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.
Facebook order attribution in Alpha Insights works by:
meta_cid={{campaign.id}} parameter in all Facebook ad URLsKey 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.