How to Automate Logging of Ad Campaign Spends into Google Sheets

admin1234 Avatar

## Introduction

Marketing teams running paid ad campaigns across multiple platforms often face the challenge of tracking daily or real-time spend data efficiently. Consolidating spend data manually from platforms like Facebook Ads, Google Ads, or LinkedIn Ads into a centralized location for budgeting, reporting, and optimization consumes time and risks human error. Automating this process lets marketing teams have up-to-date campaign spend data in Google Sheets — a familiar tool for analysis and sharing — without manual intervention.

In this article, we’ll build a robust, scalable automation workflow that automatically logs ad campaign spends from multiple platforms into a Google Sheet in near real-time. This empowers marketing teams and analysts with continuous visibility on ad spends, lowers manual data processing overhead, and speeds decision-making.

## Problem Scope and Target Audience

**Problem:** Marketing teams lack an automated, centralized spend tracker that syncs ad platform data in real-time or on-demand.

**Who benefits:** Marketing operations specialists, analysts, growth teams, and startup CTOs needing reliable, automated spend data aggregation.

**Goal:** Automatically fetch campaign spend data from various ad platforms and log it into Google Sheets.

## Tools and Services Used

– **Automation Platform:** n8n (open-source, flexible workflow automation)
– **Ad Platforms:**
– Facebook Ads API
– Google Ads API
– **Data Storage:** Google Sheets
– **Supporting Services:** OAuth 2.0 for authentication, Webhooks (optional for real-time triggers)

## Workflow Overview

1. **Trigger:** Periodic trigger (Cron) set for daily or hourly execution.
2. **Fetch Spend Data:** Use dedicated API nodes or HTTP requests to pull spend data from Facebook Ads and Google Ads.
3. **Transform Data:** Parse and normalize data to a common schema including Date, Campaign Name, Platform, Spend.
4. **Log Data:** Append rows into a predefined Google Sheet.

## Step-by-Step Technical Tutorial

### Step 1: Setup n8n Automation Environment

– Install n8n either locally, in a Docker container, or use n8n.cloud.
– Configure credentials for Facebook Ads API, Google Ads API, and Google Sheets.

### Step 2: Create the Trigger

– Use the **Cron node** to schedule the workflow. For example, set it to trigger daily at midnight or hourly as needed.

### Step 3: Fetch Facebook Ads Spend Data

– Add an **HTTP Request node** or **Facebook Ads API node** (if available).
– Authenticate using OAuth2 credentials.
– Use the Facebook Marketing API endpoint `/act_/insights` with fields:
– `date_preset=last_1d` or specify a date range
– `fields=campaign_name,spend,date_start`
– Handle pagination if multiple campaigns exist.

**Example Request Parameters:**
“`
GET https://graph.facebook.com/v15.0/act_/insights
?fields=campaign_name,spend,date_start
&date_preset=last_1d
&access_token=
“`

### Step 4: Fetch Google Ads Spend Data

– Use Google Ads API via **HTTP Request node** or dedicated node.
– Google Ads requires OAuth and query language (GAQL).
– Query example:
“`
SELECT campaign.name, segments.date, metrics.cost_micros
FROM campaign
WHERE segments.date DURING LAST_1_DAYS
“`
– Convert cost from micros to standard currency.

### Step 5: Normalize and Merge Data

– Add a **Function node** to transform both data sources into a common format:
– `Date`: campaign spend date
– `Campaign`: campaign name
– `Platform`: Facebook or Google
– `Spend`: float value

– Merge records into one array.

### Step 6: Write Data to Google Sheets

– Use the **Google Sheets node** set to append data.
– Connect with your Google Sheets credentials.
– Specify the target spreadsheet and worksheet.
– Map the normalized fields to the correct columns.
– Ensure data appends and does not overwrite.

### Step 7: Error Handling and Logging

– Add **Error Trigger node** or configure try/catch within n8n.
– Log errors to Slack or email to alert the marketing ops team.
– Common errors include API rate limits, expired tokens, incorrect sheet range.

### Step 8: Testing and Validation

– Manually trigger the workflow.
– Confirm data correctly appends to Google Sheets.
– Verify date ranges and spend accuracy.

## Tips for Robustness and Scalability

– Use incremental fetches with date parameters to avoid duplication.
– Utilize pagination tokens carefully to capture all data.
– Cache OAuth tokens or use refresh tokens to avoid authentication failures.
– Monitor API usage quotas for Facebook and Google Ads.
– For multiple ad accounts, loop through accounts dynamically.
– Consider adding a deduplication process in case of retries.
– For higher frequency updates, consider webhook triggers or streaming APIs (where supported).

## Adapting and Scaling the Workflow

– **Add more ad platforms:** Integrate LinkedIn Ads, Twitter Ads using their APIs.
– **Enrich data:** Pull additional metrics like impressions, clicks for deeper insights.
– **Change storage:** Switch from Google Sheets to BigQuery or databases for large volumes.
– **Dashboard integration:** Connect sheets or databases to BI tools like Google Data Studio.
– **Multi-user access:** Implement permission control on Sheets or databases.

## Summary

By automating the logging of ad campaign spends from Facebook Ads and Google Ads into Google Sheets using n8n, marketing teams gain centralized, up-to-date financial reporting without manual work. This workflow increases accuracy, saves time, and scales alongside campaigns. With robust error handling and the flexibility to add platforms or shift data stores, this approach fits startup growth needs and modern marketing operations.

## Bonus Tip

To avoid manual date management, implement dynamic date ranges using n8n’s expression editor—calculate “yesterday” automatically. Also, schedule workflows to run early morning in your timezone, ensuring full data availability from the previous day’s campaigns.