@php /** @var \App\Models\MetaCampaign|null $campaign */ /** @var \Illuminate\Support\Collection $picker */ /** @var array|null $aggregate */ $picker = $picker ?? collect(); $mode = $mode ?? ($campaign ? 'campaign' : 'global'); if ($campaign) { $m = $campaign->metrics; $impressions = $m['impressions']; $reach = $m['reach']; $clicks = $m['clicks']; $spend = $m['spend']; $revenue = $m['revenue']; $conv = $m['conversions']; $cpc = $m['cpc']; $ctr = $m['ctr']; $roas = $spend > 0 ? round($revenue / $spend, 2) : 0; $cpl = $conv > 0 ? round($spend / $conv, 2) : 0; $reachPct = $impressions ? round(($reach / max($impressions, 1)) * 100, 1) : 0; $clickPct = $impressions ? round(($clicks / max($impressions, 1)) * 100, 2) : 0; $waStarts = (int) round($clicks * 0.29); // estimated when not synced from Meta $waPctClicks = $clicks ? round(($waStarts / max($clicks, 1)) * 100, 1) : 0; $convPctWa = $waStarts ? round(($conv / max($waStarts, 1)) * 100, 1) : 0; $isActive = $campaign->status === 'ACTIVE'; $statusLbl = ucfirst(strtolower($campaign->status)); $createdLbl = $campaign->created_at?->format('M d, Y'); $updatedLbl = $campaign->updated_at?->format('M d, Y'); } else { $impressions = $reach = $clicks = $spend = $revenue = $conv = 0; $cpc = $ctr = $roas = $cpl = $reachPct = $clickPct = 0; $waStarts = $waPctClicks = $convPctWa = 0; $isActive = false; $statusLbl = '—'; $createdLbl = $updatedLbl = '—'; } $fmt = fn($n, $d = 0) => number_format($n, $d); $kfmt = function ($n) { if ($n >= 1_000_000) { return number_format($n / 1_000_000, 1) . 'm'; } if ($n >= 1_000) { return number_format($n / 1_000, 1) . 'k'; } return number_format($n); }; @endphp
@if ($mode === 'campaign') Meta Ads / Analytics{{ $campaign ? ' / ' . ($campaign->facebook_id ?: '#' . $campaign->id) : '' }} @else Meta Ads / Analytics / Workspace @endif
{{ $mode === 'campaign' ? ($campaign ? $campaign->name : 'Campaign not found') : 'All campaigns' }}
{{-- Always allow jumping to global view from campaign mode --}} @if ($mode === 'campaign') {{ __('Workspace view') }} @endif @if ($picker->count())
@endif @if ($mode === 'campaign' && $campaign) {{ $statusLbl }} Edit @endif
@if ($mode === 'global') @include('user.meta-ads._analytics-global', ['aggregate' => $aggregate, 'picker' => $picker]) @elseif (!$campaign)
{{ __('Campaign not found') }}

{{ __('It may have been deleted. Go back to the workspace view or pick another campaign above.') }}

@else
{{ __('Meta Ads campaign') }} {{ $createdLbl }}{{ $createdLbl !== $updatedLbl ? ' to ' . $updatedLbl : '' }}

{{ $campaign->name }} {{ __('analytics') }}

{{ __('Ad spend, CTR, WhatsApp conversations, lead quality, revenue attribution, and creative performance for this campaign.') }}

{{ __('ROAS') }}
{{ $fmt($roas, 2) }}x
{{ __('Spend') }}
${{ $kfmt($spend) }}
{{ __('Revenue') }}
${{ $kfmt($revenue) }}
{{ __('Leads') }}
{{ $fmt($conv) }}
{{ __('CPL') }}
${{ $fmt($cpl, 2) }}
{{ __('Status') }}
{{ $statusLbl }}
{{ __('Impressions') }}
{{ $kfmt($impressions) }}
{{ $statusLbl }} {{ __('delivery') }}
{{ __('Reach') }}
{{ $kfmt($reach) }}
{{ $impressions ? $fmt($impressions / max($reach, 1), 2) : '0.00' }}× frequency
{{ __('Clicks') }}
{{ $fmt($clicks) }}
{{ $fmt($ctr, 2) }}% CTR
{{ __('WhatsApp starts') }}
{{ $fmt($waStarts) }}
{{ $fmt($waPctClicks, 1) }}% of clicks
{{ __('Qualified leads') }}
{{ $fmt($conv) }}
{{ $fmt($convPctWa, 1) }}% of chats
{{ __('CPC') }}
${{ $fmt($cpc, 2) }}
${{ $fmt($cpl, 2) }} {{ __('per lead') }}
{{ __('Daily trend') }}

{{ __('Spend, clicks, leads') }}

Spend Clicks Leads
{{ __('Outcome mix') }}

{{ __('Click outcomes') }}

{{ __('Funnel') }}

{{ __('From impression to lead') }}

@php $funnel = [ ['Impressions', $impressions, 100], ['Reach', $reach, $reachPct], ['Clicks', $clicks, $clickPct * 10], ['WhatsApp starts', $waStarts, $waPctClicks], ['Qualified leads', $conv, $convPctWa], ]; $colors = ['bg-wa-deep', 'bg-wa-deep', 'bg-wa-teal', 'bg-accent-amber', 'bg-accent-coral']; @endphp
@foreach ($funnel as $i => [$lbl, $val, $pct]) @php $base = $impressions ?: 1; $widthPct = max(2, min(100, ($val / $base) * 100)); @endphp
{{ $lbl }}{{ $fmt($val) }} / {{ $fmt($pct, 1) }}%
@endforeach
{{ __('Targeting') }}

{{ __('Audience setup') }}

@php $targeting = is_array($campaign->targeting) ? $campaign->targeting : []; $countries = is_array($targeting['countries'] ?? null) ? implode(', ', $targeting['countries']) : '—'; $interests = is_array($targeting['interests'] ?? null) ? implode(', ', $targeting['interests']) : '—'; $ageR = isset($targeting['age_min']) && isset($targeting['age_max']) ? $targeting['age_min'] . '–' . $targeting['age_max'] : '—'; $gender = $targeting['gender'] ?? '—'; @endphp
{{ __('Countries') }}{{ $countries }}
{{ __('Age range') }}{{ $ageR }}
{{ __('Gender') }}{{ $gender ?: 'all' }}
{{ __('Interests') }}{{ $interests }}
{{ __('Recommendations') }}

{{ __('Next action') }}

@if ($roas >= 5 && $isActive)
{{ __('Scale this campaign') }}
ROAS is {{ $fmt($roas, 1) }}× — consider raising daily budget by 20%.
@elseif ($conv === 0 && $clicks > 100)
{{ __('No conversions despite traffic') }}
{{ $fmt($clicks) }} clicks but zero leads. Check landing page or CTWA flow.
@elseif ($cpc > 0.5)
{{ __('CPC is high') }}
${{ $fmt($cpc, 2) }} per click — try refining the audience or rotating creative.
@else
{{ __('Keep monitoring') }}
{{ __('Performance is within target. Sync again after 24h to compare.') }}
@endif
@csrf
@endif