## Facebook Campaign Tracking and ROAS Analysis

Once Facebook Ads is connected, Alpha Insights automatically tracks your campaign performance and calculates profitability metrics. This guide shows you how to view campaign data, understand metrics from Facebook's API, and analyze your ad performance.

### Accessing Facebook Campaign Data

#### Campaign List View

The primary way to view your Facebook campaigns:

1. Go to Alpha Insights → Facebook Campaigns in your WordPress admin
2. See all campaigns in a sortable table with key metrics
3. Columns display: Campaign Name, Start Date, Ad Spend, Website Views (Outbound Clicks), Leads, Orders, Conversion Rate, Revenue, and ROAS
4. Click any campaign title to view detailed campaign data
5. Use the Ad Account filter at the top to filter by specific ad accounts (if you've connected multiple over time)
6. Click column headers to sort by that metric

#### Expenses View

View daily ad spend as expenses:

1. Go to Alpha Insights → Expenses
2. Filter by "Facebook Ads" category to see only ad spend
3. Each entry represents one day of ad spend
4. These expenses are automatically included in your profit calculations

#### Dashboard View

See ad spend in context of overall business performance:

1. Go to Alpha Insights → Dashboard
2. Facebook ad spend is included in your total expenses
3. Affects your overall profit calculations automatically

### Understanding Campaign Metrics

Important: These metrics come directly from Facebook Marketing API and represent Facebook's tracking of campaign performance.

#### Ad Spend

What it is: Total amount spent on this campaign (from Facebook's data)

Example: $1,250 spent on "Summer Sale" campaign

Source: Synced from Facebook Marketing API

Updates: Based on your API call schedule (Daily, Every 12 Hours, or Every 6 Hours)

Currency: Automatically converted to your store currency if different from ad account currency

#### Impressions

What it is: Number of times your ads were shown

Source: Facebook Marketing API

#### Clicks

What it is: Total clicks on your ads (all clicks, including likes, shares, etc.)

Source: Facebook Marketing API

#### Website Views (Outbound Clicks)

What it is: Number of clicks that left Facebook and went to your website

Source: Facebook Marketing API field: `outbound_clicks`

Why it matters: This is the actual traffic sent to your site, used for conversion rate calculations

#### Leads

What it is: Number of lead form submissions from this campaign

Source: Facebook Marketing API (action_type: `lead`)

Note: Only applicable if your campaign uses Facebook lead forms

#### Orders (Purchases)

What it is: Number of purchases Facebook tracked from this campaign

Source: Facebook Marketing API (action_type: `purchase`)

How tracked: Via Facebook Pixel on your site tracking purchase events

Note: This is Facebook's attribution, which may differ from Alpha Insights' order matching using `meta_cid` parameter

#### Revenue (Purchase Value)

What it is: Total purchase value Facebook tracked from this campaign

Source: Facebook Marketing API (action_values for `purchase` action type)

How tracked: Via Facebook Pixel purchase event value

Currency: Automatically converted to your store currency if needed

#### ROAS (Return on Ad Spend)

What it is: Revenue generated per dollar spent on ads (as reported by Facebook)

Formula: `Purchase Value ÷ Ad Spend`

Example: $4,800 revenue ÷ $1,250 spend = 3.84 ROAS

What it means: For every $1 spent, Facebook tracked $3.84 in purchase value

Interpreting ROAS:

- Below 1.0: Losing money - revenue less than ad spend
- 1.0 - 2.0: Breaking even to slight profit (before product costs)
- 2.0 - 3.0: Moderate profitability
- 3.0 - 5.0: Good profitability, sustainable campaigns
- Above 5.0: Excellent! These campaigns are winners

Code Reference: Calculated at line 976 of `WPDAI_Facebook_API.php`

#### Profit (Facebook's Simple Calculation)

What it is: Simple profit calculated from Facebook's data

Formula: `Purchase Value - Ad Spend`

Example: $4,800 - $1,250 = $3,550 profit

Important Note: This is a simplified profit that does NOT account for:

- Product costs (COGS)
- Shipping costs
- Payment processing fees
- Other business expenses

Why it matters: This gives you a quick profitability indicator, but for true profit analysis, you should use Alpha Insights' full profit reports which factor in all costs.

Code Reference: Calculated at line 979 of `WPDAI_Facebook_API.php`

#### Conversion Rate

What it is: Percentage of website visitors (from ads) who made a purchase

Formula: `(Purchases ÷ Outbound Clicks) × 100`

Example: (48 ÷ 2,400) × 100 = 2.0% conversion rate

Why it matters: Shows how effective your landing page and offer are at converting traffic

Note: Uses Outbound Clicks (website views) not total clicks, giving you accurate site conversion rate

Code Reference: Calculated at line 970 of `WPDAI_Facebook_API.php` using `wpd_calculate_percentage()` helper function

### Viewing Campaign Details

#### Individual Campaign Page

Click any campaign title in the Facebook Campaigns list to view detailed campaign data:

Campaign Information Displayed:

- Account Name: Which Facebook ad account this campaign belongs to
- Campaign ID: Facebook's unique identifier for this campaign
- Campaign Spend: Total ad spend in account currency
- Campaign Impressions: Total number of impressions
- Campaign Clicks: Total clicks on ads
- Outbound Clicks: Clicks that visited your website
- Campaign Start: Date campaign began
- Campaign Stop: Most recent date with activity
- Days Active: Number of days campaign has been running
- Campaign ROAS: Return on ad spend
- Campaign Revenue: Total purchase value tracked
- Campaign Purchases: Number of purchases
- Campaign Leads: Number of leads (if applicable)
- Last Updated: When this data was last synced from Facebook

#### Daily Campaign Data

Alpha Insights stores day-by-day performance data for each campaign (stored in `_wpd_daily_data` meta field):

Daily Metrics Tracked:

- Date
- Daily spend (raw and converted)
- Outbound clicks
- Add to cart actions
- Purchases
- Purchase value
- Leads
- Daily ROAS
- Impressions

Note: Daily data is available in the database and can be used for custom reports or analytics. The individual campaign page shows aggregate totals.

### Analyzing Campaign Performance

#### Sorting and Filtering Campaigns

On the Facebook Campaigns list page, you can:

- Sort by any column: Click column headers to sort campaigns by that metric (Start Date, Ad Spend, Website Views, Leads, Orders, Conversion Rate, Revenue, or ROAS)
- Filter by Ad Account: Use the dropdown at the top to filter campaigns by specific ad account
- Search campaigns: Use the search box to find specific campaigns by name

#### Identifying Top Performers

To find your best campaigns:

1. Go to Facebook Campaigns
2. Click the ROAS column header to sort by ROAS (highest first)
3. Look for campaigns with ROAS > 3.0 and significant revenue
4. These are your winners - consider scaling budget in Facebook Ads Manager

#### Identifying Poor Performers

To find underperforming campaigns:

1. Go to Facebook Campaigns
2. Click the ROAS column header twice to sort ascending (lowest first)
3. Look for campaigns with ROAS < 2.0 or negative profit
4. Consider pausing these campaigns or optimizing them in Facebook Ads Manager

#### Understanding the Data Storage

Database Schema:

- Post Type: `facebook_campaign`
- Taxonomy: `ad_account` (for categorizing by ad account)
- Meta Fields: Campaign data stored in various meta fields prefixed with `_wpd_campaign_` and `_wpd_totals_data`, `_wpd_daily_data`

### Optimizing Based on Data

#### Scaling Winners

Identify: Campaigns with ROAS >4.0 and positive profit

What Alpha Insights shows you:

- Which campaigns have the highest ROAS
- Which campaigns drive the most revenue
- Conversion rates by campaign
- Days active for each campaign

Action in Facebook Ads Manager:

1. Note the campaign characteristics (audience, creative theme, offer)
2. Increase budget gradually (10-20% increases)
3. Monitor Alpha Insights to see if ROAS maintains as you scale
4. Create similar campaigns (lookalike audiences from winners)

#### Pausing Losers

Identify: Campaigns with ROAS < 2.0 or negative profit

What Alpha Insights shows you:

- Campaigns sorted by lowest ROAS
- Total spend on unprofitable campaigns
- Conversion rates (identify traffic vs. conversion issues)

Action in Facebook Ads Manager:

1. Pause the campaign to stop spending
2. Analyze why it failed:
   - Low outbound clicks? → Ad creative problem
   - High clicks, low conversions? → Landing page or offer problem
   - Zero purchases? → Wrong audience
3. Don't repeat same mistakes in future campaigns

#### Optimizing Moderate Performers

Identify: Campaigns with ROAS 2.5-3.5

What Alpha Insights shows you:

- Conversion rate data (identify where the funnel breaks)
- Daily performance trends (some days better than others?)
- Comparison to other campaigns

Actions to test in Facebook Ads Manager:

- Narrow audience: Target more specific interests or demographics
- Improve creative: Test new images, videos, or ad copy
- Adjust offer: Add urgency, better discount, or bonus
- Optimize landing page: A/B test to improve conversion rate
- Exclude low performers: Use placement or audience exclusions

#### Analyzing Performance Trends

Using Daily Data:

Alpha Insights stores daily performance data for each campaign. While not visible in the default UI, this data is available in the database (`_wpd_daily_data` meta field) and can be used to identify:

- Which days of the week perform best
- Performance trends over time (improving or declining?)
- Seasonal patterns
- Impact of budget changes on performance

Data Fields Available Per Day:

- Date
- Spend
- Outbound clicks
- Add to cart events
- Purchases
- Purchase value
- Leads
- ROAS
- Impressions

### Understanding Attribution in Alpha Insights

#### Two Types of Data: Facebook's vs. Your Store's

1. Facebook's Attribution (what you see in campaign metrics):

- Purchases, Revenue, and ROAS shown in Alpha Insights come from Facebook Marketing API
- These are tracked by Facebook Pixel on your site
- Facebook uses their own attribution model (typically 7-day click, 1-day view)
- This data shows what Facebook thinks their campaigns achieved

2. Alpha Insights' Order Attribution (using meta_cid parameter):

- Alpha Insights can match your actual WooCommerce orders to specific campaigns
- Uses the `meta_cid={{campaign.id}}` parameter in your ad URLs
- When customers visit via an ad with this parameter, it's stored with their order
- This enables true profit calculations per campaign in your Alpha Insights reports

#### How to Set Up Order Attribution

Add this to your Facebook ad URLs:

    meta_cid={{campaign.id}}

Full URL example:

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

What happens:

1. Facebook replaces `{{campaign.id}}` with the actual campaign ID
2. Alpha Insights captures the `meta_cid` parameter from the landing page URL
3. When the visitor places an order, the campaign ID is stored in order meta: `_wpd_ai_meta_campaign_id`
4. You can then run reports showing actual orders and profit by campaign

Code Reference: Order campaign ID attribution happens in `set_order_campaign_id_via_query_param()` method (lines 417-473 of `WPDAI_Facebook_API.php`)

#### Important Notes About Attribution

- No configurable attribution window: Orders are matched based on the landing page parameter, not time-based windows
- Matches happen on order creation: The campaign ID is captured when customers first land on your site
- Last 30 days by default: The `set_order_campaign_id_via_query_param()` method checks the last 30 days of orders by default
- Facebook's data vs. your data: Numbers may differ between Facebook's reported purchases and your actual order attribution

### Troubleshooting Campaign Data

#### Issue: Campaign shows but no purchase data

Possible reasons:

- Campaign just launched (no purchases tracked yet)
- Facebook Pixel not installed or not tracking purchase events
- Purchases happening but not being sent to Facebook

Check:

1. Verify Facebook Pixel is installed on your site
2. Check Pixel is tracking purchase events in Facebook Events Manager
3. Wait for next sync (data updates based on your API call schedule)
4. For Alpha Insights order attribution, verify `meta_cid={{campaign.id}}` is in your ad URLs

#### Issue: Revenue doesn't match Facebook Ads Manager

Why they differ:

- Facebook uses "view-through" attribution (saw ad but didn't click), Alpha Insights shows only what Facebook's API reports
- Different time zones between your WordPress site and Facebook
- Sync timing - data may not be fully processed yet
- Currency conversion if your ad account uses different currency than your store

This is normal! Small discrepancies (5-10%) are expected. Large differences indicate a tracking issue.

#### Issue: Spend amounts don't match Facebook Ads Manager

Check:

- Verify you're comparing the same date ranges
- Check if currency conversion is being applied (look for "currency_converted" field = 1 in campaign data)
- Wait for next sync - Facebook data isn't always immediately finalized
- Click Refresh All Campaign Data to force a sync

### Best Practices

#### Review Campaign Performance Regularly

1. Weekly: Review campaigns in Alpha Insights → Facebook Campaigns
2. Sort by ROAS to identify top and bottom performers
3. Make budget adjustments in Facebook Ads Manager based on data
4. Monitor how changes affect performance in subsequent syncs

#### Set ROAS Goals by Campaign Type

Different campaign objectives should have different targets:

- Prospecting (cold audiences): ROAS 2.5-3.5 acceptable
- Retargeting: ROAS 5.0-8.0 expected
- Lookalike audiences: ROAS 3.5-5.0 typical

Remember: These are Facebook's tracked ROAS numbers. Your actual profit may differ after accounting for COGS and other expenses.

#### Use Campaign Tracking Consistently

For best results with Alpha Insights order attribution:

    meta_cid={{campaign.id}}

Add this parameter to ALL Facebook ad URLs to enable order-level tracking and profit calculations per campaign.

#### Understand Data Limitations

- Historical limit: Facebook API provides up to 37 months of historical data
- Pixel accuracy: Purchase data depends on Facebook Pixel tracking accuracy
- Campaign-level only: Data is aggregated at campaign level, not ad-level
- Simple profit formula: Facebook profit shown is Revenue - Ad Spend only (doesn't include COGS or other costs)