How to automate paid campaign optimization for a consumer health brand

Published

TLDR

Reconcile spend and conversions, test bounded budget proposals, and measure the change against an approved control.

Build a daily campaign review that joins ad spend to an agreed conversion outcome, accounts for reporting delays and refunds, and proposes bounded budget changes. Compare the proposed policy against the incumbent at the same spend or within a randomized experiment before treating a metric change as incremental lift.

Define which conversions and costs count

Pick one campaign family, one conversion action, and a consistent currency and time basis. Keep ad-platform attributed outcomes separate from order-system outcomes. A platform and the business can report different totals because they use different timing and attribution rules. Google Ads documents conversion-action segmentation and experiment reporting. Report conversion actions separately before aggregating and avoid adding campaign totals to their segmented breakdowns. Google Ads conversion reporting · Google Ads experiment reporting

Turn campaign reporting into a controlled decision

StepWhat the team does todayHow to automate itAccepted result
Pull spend and outcomesA media analyst exports campaign spend and orders from separate tools.Ingest campaign IDs, spend, date, currency, and agreed outcomes into dated snapshots. Preserve platform and commerce views.Reproducible spend and outcome data with source coverage.
Reconcile dates and valueStaff distinguish attribution delay from missing conversion data and account for refunds.Restate open attribution windows with versioned facts. Apply the approved net-value rule and hold stale or partial partitions.Comparable campaign slices with freshness and confidence flags.
Calculate decision metricsThe analyst estimates CPA and contribution and decides what needs attention.Compute spend per accepted conversion and net contribution from approved inputs. Treat a zero denominator as insufficient evidence.Candidate changes with support and uncertainty.
Apply budget limitsThe media lead reviews proposed reallocations and budget commitments.Simulate a capped change and reject changes outside campaign or account guardrails. AI can explain the flagged drivers.Approved change with current budget, proposed budget, and decision owner.
Validate and measureThe buyer checks the change in the ad platform and evaluates the result.Save change receipts, compare against the approved control, and monitor spend and outcome guardrails.Outcome report and rollback trigger.

What to automate

Pull spend and outcomes

Create dated snapshots of ad-platform spend and agreed outcome records. Keep platform attribution and commerce outcome tables separate at the approved campaign, date and currency grain. Track expected source partitions and fetch time. If a campaign mapping or partition is missing, send the break to the media analyst and keep the affected slice out of decision inputs.

Reconcile dates and value

Use an agreed conversion maturity window and compare like dates and currencies. Refresh open windows as late events or refunds arrive and preserve the previous snapshot. Apply the approved net-value rule in code. Mark any incomplete or immature window in the daily dataset so a delayed outcome cannot look like weaker performance.

Calculate decision metrics

Build a table of spend, accepted mature conversions, cost per conversion and net contribution with explicit denominators and input IDs. Return an evidence status for a zero denominator or small volume. Compare qualified rows with the agreed baseline and rank review candidates. Ask AI to summarize approved metrics and evidence, then have the analyst verify the summary.

Apply budget limits

Simulate the proposed budget using current campaign limits, a daily account cap and the allowed step size. Validate total budget after any transfer. Route a blocked proposal and its rule to the media lead. For an eligible proposal, present the existing budget, suggested amount, reason, evidence window and approval owner before an operator applies it.

Validate and measure

Record the approved proposal and save the change receipt and readback from the platform. Watch spend and outcome guardrails after deployment and route breaches to the media buyer. Compare the treated and control outcomes on the agreed test basis. Keep the previous approved allocation and record when the owner decides to revert, extend or end the experiment.

Test delayed conversions and an unchanged budget

In a synthetic fixture, campaign A spent $600 with 20 mature conversions, for a $30 CPA. Campaign B spent $400 with eight mature conversions, for a $50 CPA. A provisional policy may suggest moving $40 from B to A while keeping total daily spend at $1,000. Confirm no proposal is issued if B's outcome data is still inside the immature window. Confirm that a refund, zero-conversion day, or repeated run follows the same rules. Measure incremental conversions and contribution in an experiment if the campaign supports it. The CPA difference alone does not quantify the effect of changing budgets.

Implement the pacing job and budget approval checkpoint

Keep a table at platform × account × campaign × reporting_day × revision with billed spend, impressions and attributed conversions. Separate platform account timezone, finance period, currency and attribution window. Snapshot late metric updates instead of treating one pull as final.

  1. Pull metrics with a scoped reader and record the configured attribution and timezone. Compare cumulative spend at the current day with a time-weighted approved budget curve. Mark data stale based on source availability and treat zero conversions separately from a broken API pull.
  2. Calculate an action proposal only when the allowed inputs are current and the change fits approved campaign, spend and performance limits. A proposal stores old budget, candidate budget, expected version, trigger reason, policy, timestamp and owner.
  3. Get the owner’s approval and re-read the platform values. Apply only when the current budget still matches the proposed base and the run has a unique approved action key. After an unknown response, inspect effective platform settings and history before another update.
  4. Measure effects with the agreed attribution window and comparator. Keep proposals, applied changes, platform delivery and realized performance in separate tables. An AI assistant can explain a discrepancy from metrics and policy but should never bypass the spend control.
from decimal import Decimal

def pacing(spent, period_budget, elapsed_fraction):
    expected = Decimal(period_budget) * Decimal(elapsed_fraction)
    if not expected:
        return None
    return Decimal(spent) / expected

assert pacing(450, 1_000, "0.5") == Decimal("0.9")
assert pacing(650, 1_000, "0.5") == Decimal("1.3")
assert pacing(0, 1_000, "0") is None

With a synthetic review band of 0.85–1.15, 0.9 is in band and 1.3 merits a review. A pacing signal alone does not authorize a budget change.

Implement the work step by step

The performance marketing lead decides whether a bounded spend change improves incremental contribution under the same budget and channel limits. The workflow begins with daily spend and matured outcome coverage. Ends with logged approved budget decisions and experiment evidence. Excludes healthcare targeting design.

Collect and reconcile

  • Pull campaign spend and attributes. Paginate approved query, preserve API metadata and avoid mixed-grain totals. Read Ad reporting API, account and campaign dictionaries. Record Dated spend facts to marketing analyst. Owner Media analyst. Confirm new campaign IDs and exception policies. Check Reconcile spend to account/date source totals.
  • Pull accepted conversion and refund data. Map approved action IDs, retain refund adjustments, timestamp snapshots. Read Ad conversion action, commerce orders, refunds. Record Separate attributed and net-order outcome views. Owner Marketing analyst. Approve net-value definition and action changes. Check Do not add platform and commerce outcomes together.
  • Close or hold the attribution window. Restate open windows by vintage and flag stale sources. Read Conversion lag distribution, cutoff policy, data health. Record Mature or held campaign partitions to analyst. Owner Marketing analyst. Approve lag assumptions and reopening policy. Check No decision when required results are immature.

Evaluate

  • Calculate CPA and contribution. Compute decimal cost and margin on approved basis, enforce minimum sample. AI can draft campaign variance explanation from computed facts. Read Cost, mature outcomes, unit economics. Record Eligible candidates with denominators to media lead. Owner Marketing analyst. Confirm outlier budget dependencies. Check A zero denominator is unknown, not a zero CPA.
  • Triage missing outcome or budget breach. Open deduplicated case keyed to campaign and data window. AI can summarize metrics and linked evidence. Read Exceptions, change logs, source status. Record Held action and ownership record. Owner Media analyst. Resolve tracking or eligibility break before releasing change. Check No stale metrics lead to spend edits.

Control and measure

  • Review and apply capped action. Simulate spend totals, enforce allowlists and caps, verify returned setting. AI can draft rationale from validated metrics. Read Budget proposal, account limits, ad platform. Record Action receipt and rollback plan. Owner Media lead. Authorize spend under assigned controls. Check Account ceiling holds under concurrent edits.
  • Update experiment and watch guardrails. Capture exposure, confidence intervals and unchanged control policy. Alert breaches. AI can draft summary of uncertainty. Read Experiment reports, agreed treatment/control. Record Outcome review and owner response. Owner Marketing analyst. Decide rollback, termination or expanded test. Check No causal lift estimate from a pre/post CPA comparison alone.

Parallel run. Shadow at least two mature conversion windows. Exercise immature data, refund and zero denominator. If authorized, test a budget-neutral policy against incumbent.

Build it yourself with AI

Create synthetic campaign_spend.csv and outcomes.csv, plus an approval policy that records the decision window, spend caps and minimum evidence. Keep an initial dry-run version that produces proposals.csv and a decision log. The assistant can write and review the prototype using fictional aggregates.

  1. Agree on the decision inputs

    Turn the policy into a data contract. Distinguish outcome date, report date, maturity status, refund treatment and currency. Show which inputs are blocking. Mark a zero or immature denominator as insufficient evidence.

  2. Implement a proposal with hard caps

    Write a Python proposal generator. Use campaign A with 600 spent and 20 mature conversions and B with 400 spent and eight mature conversions. Expect cost per conversion of 30 and 50. Set fictional current budgets to 600 and 400, and test a suggested transfer of 40 from B to A. Verify proposed budgets of 640 and 360, a total of 1000, and no proposal if either input is immature. Add refund and zero-conversion fixtures.

  3. Draft the experiment decision

    Given the computed proposal and experiment settings, write a review note with the current allocation, proposed allocation, approval owner, control group, measurement window and rollback trigger. Cite the metric rows. Label any effect estimate as a hypothesis for the experiment.

Compare daily dry runs with the existing decision process and investigate any disagreement in window or currency. Have the media lead approve the bounds and an operator apply the first change in the existing tool. Log the receipt and use the configured guardrails to decide whether to revert.

Need help automating this?

See how Mage brings campaign data together and prepares pacing recommendations for review. See Mage's campaign optimization and pacing solution.

AuthorsMage Team