Trafficking campaigns in Campaign Manager 360 (CM360) is often the most time-consuming part of a media planner’s day. When you’re managing a YouTube Tracker Campaign—where you need individual 1×1 placements for every line item—the manual work is not only slow, it’s prone to human error.
At marketer.tools, we believe that if you have to do it twice, you should automate it. Welcome to Part 1 of our Automating CM360 series. Today, we aren’t just clicking buttons; we are using R to build an Automation. This script allows you to launch a full YouTube Tracker Campaign in seconds, ensuring every 1×1 placement and tracking ad is built perfectly every time.
Why Use an Automation Script for YouTube Tracker Campaign?
When running YouTube ads, “Tracking Placements” (1×1 pixels) are essential for cross-environment measurement. By using a script instead of the UI, you ensure:
- Consistency: Every placement, ad, and creative follows the exact same naming convention.
- Speed: You can build the entire hierarchy—Landing Page to Ad—with one execution.
- Accuracy: No more 1×1 placements accidentally set to the wrong dimensions or status.
Phase 1: Configuring Your Google Cloud Gateway
Before your script can talk to CM360, you must establish a secure connection via the Google Cloud Platform (GCP). Follow these 25 steps to generate your authentication credentials:
- Navigate to the Google Cloud Console.
- In the top navigation bar, click on Select a project.
- Click the New Project button in the top right.
- Enter a Project name (e.g., “CM360 Automator”).
- Click Create.
- Once the project is ready, select it from the top dropdown.
- Click APIs & Services on the home screen sidebar.
- Click on Library.
- In the search bar, type “Campaign”.
- Select Campaign Manager 360 API from the list.
- Click the Campaign Manager 360 API box.
- Click the blue Enable button.
- Once enabled, click OAuth consent screen on the left sidebar.
- Click the Get Started button.
- Enter your preferred App name (e.g., “CM360 Automation R-Script”).
- Under User support email, select your email address.
- Under Audience, select External and click Next.
- In the Developer contact information, enter your email address again.
- Click Next, review the summary, and click Continue/Create.
- Now, click the Credentials tab on the left sidebar.
- Click Create Credentials > OAuth client ID.
- In the Application type dropdown, select Desktop app.
- Give it a name (e.g., “R-Studio Connection”) and click Create.
- A window will appear with your Client ID; click Download JSON. Save this file securely on your computer.
- Final Step: Go back to the OAuth consent screen, find the Test users section, click Add Users, and enter the email address that has access to your CM360 account. Click Save.
Phase 2: The YouTube Tracker Automation Script
This script follows the required CM360 hierarchy. To ensure the API doesn’t throw an error, we build from the bottom up: the Landing Page must be created first so it can be assigned as the default for the Campaign.
The R Code
Copy this code into RStudio. Simply update the placeholders in Section 3 with your actual CM360 Profile, Advertiser, and Site IDs.
# ---
# Title: CM360 YouTube Campaign Setup Automator
# Series: Automating CM360 (Part 1)
# Use Case: YouTube Tracking Campaign Automation
# Author: Marketer.tools
# ---
# 1. LOAD REQUIRED LIBRARIES
if (!require("googleAuthR")) install.packages("googleAuthR")
if (!require("httr")) install.packages("httr")
if (!require("jsonlite")) install.packages("jsonlite")
library(googleAuthR)
library(httr)
library(jsonlite)
# 2. AUTHENTICATION
# Path to the JSON file you downloaded in Step 24
gar_set_client("PATH/TO/YOUR/client_secret.json")
gar_auth(scopes = "https://www.googleapis.com/auth/dfatrafficking")
# 3. GLOBAL VARIABLES (Update these with your IDs)
profile_id <- "YOUR_PROFILE_ID"
advertiser_id <- "YOUR_ADVERTISER_ID"
site_id <- "YOUR_SITE_ID" # The ID for your YouTube Site
campaign_name <- "YT_Tracking_Campaign_2026"
start_date <- "2026-01-10"
end_date <- "2026-12-31"
# --- API HELPER FUNCTION ---
cm360_post <- function(endpoint, body) {
url <- paste0("https://dfareporting.googleapis.com/dfareporting/v4/userprofiles/", profile_id, "/", endpoint)
res <- gar_api_generator(url, "POST", data_parse_function = function(x) x)(the_body = body)
return(res)
}
# --- AUTOMATION LOGIC ---
# 1. SETUP LANDING PAGE
message("Status: Creating Landing Page...")
lp_body <- list(
name = "YouTube Promo Page",
url = "https://marketer.tools",
advertiserId = advertiser_id
)
landing_page <- cm360_post("advertiserLandingPages", lp_body)
lp_id <- landing_page$id
# 2. SETUP CAMPAIGN
message("Status: Creating Campaign...")
campaign_body <- list(
name = campaign_name,
advertiserId = advertiser_id,
status = "ACTIVE",
startDate = start_date,
endDate = end_date,
defaultLandingPageId = lp_id
)
campaign <- cm360_post("campaigns", campaign_body)
campaign_id <- campaign$id
# 3. SETUP PLACEMENT (1x1 for YouTube Tracking)
message("Status: Setting up 1x1 Placement...")
placement_body <- list(
name = paste0(campaign_name, "_1x1_Placement"),
campaignId = campaign_id,
siteId = site_id,
size = list(width = 1, height = 1),
paymentSource = "PLACEMENT_AGENCY_PAID",
compatibility = "DISPLAY",
status = "PAYMENT_ACCEPTED",
tagFormats = list("PLACEMENT_TAG_STANDARD"),
pricingSchedule = list(
startDate = start_date,
endDate = end_date,
pricingType = "PRICING_TYPE_CPM"
)
)
placement <- cm360_post("placements", placement_body)
placement_id <- placement$id
# 4. CREATE TRACKING CREATIVE
message("Status: Creating Tracking Creative...")
creative_body <- list(
name = "YT_Tracking_Creative",
advertiserId = advertiser_id,
type = "TRACKING_TEXT",
active = TRUE,
size = list(width = 1, height = 1)
)
creative <- cm360_post("creatives", creative_body)
creative_id <- creative$id
# 5. LINK CREATIVE TO CAMPAIGN
message("Status: Linking Creative to Campaign...")
assoc_url <- paste0("https://dfareporting.googleapis.com/dfareporting/v4/userprofiles/",
profile_id, "/campaigns/", campaign_id, "/campaignCreativeAssociations")
gar_api_generator(assoc_url, "POST", data_parse_function = function(x) x)(the_body = list(creativeId = creative_id))
# 6. CREATE TRACKING AD & ASSIGNMENTS
message("Status: Finalizing Tracking Ad & Linking Placement...")
ad_body <- list(
name = "YT_Tracking_Ad",
campaignId = campaign_id,
type = "AD_SERVING_TRACKING",
active = TRUE,
startTime = paste0(start_date, "T00:00:00Z"),
endTime = paste0(end_date, "T23:59:59Z"),
placementAssignments = list(list(placementId = placement_id, active = TRUE)),
creativeRotation = list(
type = "CREATIVE_ROTATION_TYPE_RANDOM",
creativeAssignments = list(
list(creativeId = creative_id, active = TRUE, sequence = 1,
clickThroughUrl = list(defaultLandingPage = TRUE))
)
)
)
ad <- cm360_post("ads", ad_body)
message("--- SUCCESS ---")
message("Campaign Created with ID: ", campaign_id)
message("Placement Created with ID: ", placement_id)
Conclusion
You’ve successfully built your first automated tracking setup. By moving away from manual trafficking, you’ve reduced your workload and ensured data integrity. Stay tuned to marketer.tools for the next part of this series!
If you are having issues with the code, please email us at help@marketertools.com—we will try to help you.
Critical Note: API Dependencies
Hierarchy Matters: In the CM360 API, you cannot create a Campaign without an existing defaultLandingPageId. Unlike the manual UI where you can add a URL later, the API will reject your request (400 Error) if the landing page doesn’t exist yet. Always follow the Landing Page > Campaign > Placement order used in the script below to ensure success.
Explore Our Tool Library
- Campaign Pacing Tool
- Annual Advertising Media Pacing Calculator
- A/B Test Sample Size Calculator
- Media Mix Planner
- Break-Even ROAS Calculator: The Ultimate Profitability Tool for E-commerce
- PPC/Google Ads Keywords: Free Match Type Wrapper & Cleaner
- Incrementality Calculator: CPA & ROAS
- The Ultimate GA4 UTM Builder: Stop Losing Traffic to “Unassigned”
- Quantify Your Value: The Ultimate Landing Page ROI Calculator for Agencies
Frequently Asked Questions (FAQ)
1. What is a YouTube Tracker Campaign in CM360?
A YouTube Tracker Campaign is a specific setup in Campaign Manager 360 designed to measure impressions and clicks for ads served on YouTube. Instead of standard display banners, this setup uses 1×1 tracking placements (pixels) to capture data from the YouTube environment.
2. Why do I need to create the Landing Page first in the script?
CM360 has a strict data hierarchy. When creating a campaign via the API, the system requires a defaultLandingPageId. If you try to create the campaign first, the API will return a 400 error. Creating the Landing Page first allows the script to pass that ID into the campaign setup automatically.
3. Can I use this R script for standard display campaigns?
Yes. While this script is optimized for a YouTube Tracker Campaign (using 1×1 dimensions), you can easily modify the size variables and the compatibility field in Step 3 of the script to support standard display or video placements.
4. What permissions do I need to run this script?
To execute these commands, the email address you authenticate with must have Trafficker permissions or higher within your CM360 User Profile. Additionally, you must ensure the “Campaign Manager 360 API” is enabled in your Google Cloud Project.
5. Is my CM360 data secure when using this script?
Yes. This script uses the official Google SDK (googleAuthR). Your credentials (the JSON file) stay on your local machine, and the authentication happens directly between your system and Google’s servers. No data is sent to marketer.tools or any third-party server.
