How to Get Campaign Names Automatically in Google Ads Tracking Templates (The Universal Fix)

You are pulling a crucial report. You look at your performance data, expecting to see your best-performing campaigns listed by name (Summer_Sale_2024, PMax_New_Product_Launch), but instead, you are staring at a column of cryptic numbers: 123456789, 987654321.

This is the {campaignid} curse.

If you are a performance marketer, you need granular data to flow into your analytics platform, third-party CRM (like Salesforce or HubSpot), or custom visualization dashboards. You need to know which campaign is driving revenue.

And right now, you are probably discovering the primary frustration in Google Ads advanced tracking:

There is no native {campaignname} ValueTrack parameter.

Google provides parameters for {campaignid}, {adgroupid}, {keyword}, and even {creative} (Ad ID), but it has stubbornly refused to provide a variable that pulls the literal campaign name you created.

This guide provides the final, elegant, universal solution to automate this process once and for all.

1. The Problem: The Empty {campaignname} Void

Many marketers assume that if {campaignid} works, {campaignname} must also work. They build an advanced, account-level tracking template like this, utilizing all five standard UTM variables:

{lpurl}?utm_source=google&utm_medium=cpc&utm_campaign={campaignname}&utm_content={adgroupid}&utm_term={keyword}

They click “Test.” The final https://www.google.com/search?q=URLs appear generated. They save the changes. They wait 24 hours.

When they check their analytics, utm_campaign is either blank or contains the literal string “{campaignname}“.

The data is missing.

The Silent Gaps in Auto-Tagging

Google’s default answer is always: “Use Auto-tagging.”

Auto-tagging is perfect if you only use Google Analytics (GA4). Behind the scenes, Google sends a gclid parameter that GA4 automatically translates into the exact campaign name.

However, auto-tagging cannot pass data to a non-Google CRM or a generic third-party analytics dashboard. If your business depends on HubSpot or Salesforce matching a conversion to a named campaign, auto-tagging is not enough. You need UTMs.

The Manual Workaround (And Why It Fails)

You can manually set this up at the campaign level. You have to navigate to every single campaign you create:

  1. Open Campaign Settings.
  2. Find Campaign https://www.google.com/search?q=URL Options.
  3. Manually create a Custom parameter (e.g., _campaignname = Summer_Sale).

This “solution” relies on human memory and consistency. The first time you launch a new campaign in a rush and forget to set the custom parameter, your tracking pipeline breaks, and your data is corrupted. Manually setting parameters is not a scalable strategy.

2. The Solution: Universal Naming Automation with Google Ads Scripts

We need a solution that is 100% automated, invisible, and future-proof. We need a way to tell Google Ads: “Every time I create ANY campaign, automatically read its name, remove any spaces, and save it in a custom parameter that I can use in my account tracking template.”

We will achieve this using a specific Google Ads Script.

Why Most Campaign Naming Scripts Fail

If you search online, you will find several common scripts designed for this purpose. They all share the same critical flaw: They are not universal.

Standard scripts use a basic “campaign iterator” that only looks for Standard Search and Display campaigns. If you have any other campaign types, these scripts will completely ignore them:

  • Shopping Campaigns
  • Performance Max Campaigns (PMax)
  • Video (YouTube) Campaigns

If you rely on a non-universal script, you will discover that your Search campaigns are tagging campaign names correctly, but your highest-volume Shopping and PMax campaigns are still passing empty IDs.

The Optimized, Universal Fix

We have developed the Ultimate Campaign Naming Script. This script is designed to be truly universal. It explicitly commands the Google Ads API to look inside every single campaign “bucket” it maintains, ensuring no campaign type is left untagged.

3. Implementation Guide: Step-by-Step

Here is the exact workflow you must follow to get this running in under 10 minutes.

Part 1: Install the Universal Automation Script

  1. In your Google Ads account, click on the Tools icon (wrench).
  2. Under Bulk Actions, click Scripts.
  3. Click the blue + button.
  4. Name the script something clear, like Universal_Campaign_Name_Auto-Tag.
  5. Delete all existing placeholder code in the main box.
  6. Copy and paste the entire script below into the code editor:

THE UNIVERSAL SCRIPT (Copy and Paste)

JavaScript

function main() {
  var count = 0;
  Logger.log(“Starting to scan all campaign types…”);

  // 1. Scan Standard Campaigns (Search & Display)
  Logger.log(“–> Checking Standard Campaigns…”);
  var campaignIterator = AdsApp.campaigns().get();
  while (campaignIterator.hasNext()) {
    updateCampaignUrl(campaignIterator.next());
    count++;
  }

  // 2. Scan Shopping Campaigns
  Logger.log(“–> Checking Shopping Campaigns…”);
  var shoppingIterator = AdsApp.shoppingCampaigns().get();
  while (shoppingIterator.hasNext()) {
    updateCampaignUrl(shoppingIterator.next());
    count++;
  }

  // 3. Scan Performance Max Campaigns
  Logger.log(“–> Checking Performance Max Campaigns…”);
  var pmaxIterator = AdsApp.performanceMaxCampaigns().get();
  while (pmaxIterator.hasNext()) {
    updateCampaignUrl(pmaxIterator.next());
    count++;
  }

  // 4. Scan Video Campaigns (YouTube)
  Logger.log(“–> Checking Video Campaigns…”);
  var videoIterator = AdsApp.videoCampaigns().get();
  while (videoIterator.hasNext()) {
    updateCampaignUrl(videoIterator.next());
    count++;
  }

  // Final Results Output
  if (count === 0) {
    Logger.log(“RESULT: No campaigns found in this account.”);
  } else {
    Logger.log(“RESULT: Successfully processed ” + count + ” total campaigns across all types.”);
  }
}

// Helper function to apply the tracking parameter (keeps the code clean)
function updateCampaignUrl(campaign) {
  var campaignName = campaign.getName();
 
  // Replace spaces with underscores to keep URLs clean
  var cleanCampaignName = campaignName.replace(/ /g, ‘_’);
 
  // Grab existing parameters so we don’t overwrite anything else you have
  var customParams = campaign.urls().getCustomParameters() || {};
  customParams[‘campaignname’] = cleanCampaignName;
 
  // Set the parameter
  campaign.urls().setCustomParameters(customParams);
 
  // Print a confirmation message for the Logs
  Logger.log(”    Updated: ” + campaignName + ” —> {_campaignname} is now: ” + cleanCampaignName);
}

  1. Click Authorize (above the code box). You must grant the script permission to access your campaign data. Follow the Google prompts to allow access.
  2. Click Preview. Do not run it yet.
  3. Click on the Logs tab at the bottom of the screen. Read the log output. You should see it successfully find your campaigns, read their names, and confirm they are “Updated.”
  4. Once the Logs confirm it works, click the blue Run button to make the changes live.
  5. Crucial: Go back to the main Scripts page and set the script’s Frequency to Daily. (Choose an early morning hour, like 3:00 AM, to ensure new campaigns created the previous day are tagged before high traffic starts).

Part 2: Update Your Account-Level Tracking Template

Now that the script is attaching the _campaignname parameter to every single campaign in your account (Search, PMax, Shopping, Video), you must update your tracking template to look for it.

Go to your Account Settings -> Tracking section.

The Recommended Universal Template (Copy and Paste)

Update your template to use the new custom variable utm_campaign={_campaignname}:

{lpurl}?utm_source=google&utm_medium=cpc&utm_campaign={_campaignname}&utm_content={adgroupid}&utm_term={keyword}

(Notice we have swapped {campaignid} out and replaced it with our new custom automation: {_campaignname}).

Click Test, then Save.

4. Key Takeaways and Benefits

You have now built a professional-grade, automated tracking pipeline. Once this runs:

  1. Clean Data: You will never see a campaign ID number in your third-party reports again. You will see legible, named campaigns.
  2. Universal Coverage: This works for EVERYTHING. If you launch a new PMax asset group or a new Shopping campaign next week, this script will catch it automatically the next morning.
  3. Third-Party Alignment: You can finally connect your performance data directly to your CRM pipeline, unlocking precise ROAS and lifecycle reporting.
  4. Effortless: You never have to manually set a campaign name parameter again. The script does all the work.

Share this post with your friends

Share on facebook
Share on twitter
Share on linkedin
Share on email

Leave a Reply

Your email address will not be published. Required fields are marked *

Schedule your free two hour Strategy Session

*Limited Slots Available