Scriptlytics
  • Introduction
    • Welcome to the community
  • Account level scripts
    • Account overview (all time)
    • Account performance (date range)
    • Account performance (daily export)
    • Account performance (last 90 days)
    • Account search query optimizer
    • Account search query optimizer (yesterday)
    • Call asset scheduling
    • Account keyword optimizer (date range)
    • Account keyword optimizer (last 90 days)
    • Match type report (last 360 days)
    • Negative keyword list
  • Campaign level scripts
    • Campaign performance (date range)
    • Campaign performance (daily export)
    • Campaign performance (last 90 days)
    • Multiple campaign performance (last 90 days)
    • Ad groups (date range)
    • Ad groups (last 30 days)
    • Keyword optimizer (date range)
    • Keyword optimizer (last 30 days)
    • Impressions heatmap (date range)
    • Impressions heatmap (last 30 days)
    • Clicks heatmap (date range)
    • Clicks heatmap (last 30 days)
    • CTR heatmap (date range)
    • CTR heatmap (last 30 days)
    • Conversions heatmap (last 30 days)
    • Conversions heatmap (date range)
    • Conversion rate heatmap (last 30 days)
    • Conversion rate heatmap (date range)
    • CPC heatmap (last 30 days)
    • CPC heatmap (date range)
  • pmax scripts
    • Pmax segmentation
    • Pmax search query optimizer
    • Pmax search query optimizer (all time)
  • Call reports
    • Call report (date range)
    • Call report (evergreen)
  • Bulk edit and actions
    • Bulk upload template
    • Swap Base URL's
    • Copy campaign and swap base URL's
  • Alerts and notifications
    • Zero spend alert
  • MCC scripts
    • MCC account performance export
    • Revised MCC account performance export
  • Search ads
    • Keyword match optimizer
  • Google sheets
    • Remove the following keywords
    • Remove keywords that don't contain
    • Remove keywords that don't contain and create negative keyword list
  • Product title modification
Powered by GitBook
On this page
  1. Bulk edit and actions

Copy campaign and swap base URL's

This is specifically built for responsive search ads

The script automates the process of copying an existing campaign, renaming it, and updating the base URLs of all responsive search ads within the new campaign. This ensures that you can create a modified version of an existing campaign with updated URLs efficiently, saving time compared to manual duplication and modification

To set up this script, follow these steps:

  1. Open your Google Ads account.

  2. Go to the "Tools & Settings" menu and select "Scripts".

  3. Click the "Create" or "+" button to create a new script.

  4. Copy and paste the following script.

function main() {
  var oldCampaignName = 'Original Campaign Name'; // Name of the campaign to copy
  var newCampaignName = 'New Campaign Name'; // Name for the copied campaign
  var oldBaseUrl = 'https://www.old-url.com'; // The base URL to replace
  var newBaseUrl = 'https://www.new-url.com'; // The new base URL to use

  // Get the original campaign to copy
  var campaignIterator = AdsApp.campaigns()
    .withCondition('Name = "' + oldCampaignName + '"')
    .get();

  // Check if the original campaign exists
  if (!campaignIterator.hasNext()) {
    Logger.log('No campaign found with the name "' + oldCampaignName + '"');
    return;
  }

  // Get the original campaign
  var oldCampaign = campaignIterator.next();

  // Create a new campaign by copying settings from the old campaign
  var newCampaign = AdsApp.campaigns()
    .newCampaignBuilder()
    .withName(newCampaignName)
    .withBudget(oldCampaign.getBudget())
    .withStatus(oldCampaign.isEnabled() ? 'ENABLED' : 'PAUSED') // Copy status
    .withBiddingStrategy(oldCampaign.getBiddingStrategyType()) // Copy bidding strategy
    .build()
    .getResult();

  Logger.log('Campaign "' + newCampaignName + '" created.');

  // Copy each ad group and its ads
  var adGroupIterator = oldCampaign.adGroups().get();

  while (adGroupIterator.hasNext()) {
    var oldAdGroup = adGroupIterator.next();

    // Create a new ad group with the same settings as the old one
    var newAdGroup = newCampaign
      .newAdGroupBuilder()
      .withName(oldAdGroup.getName())
      .withCpc(oldAdGroup.bidding().getCpc()) // If CPC bidding, copy CPC
      .withCpm(oldAdGroup.bidding().getCpm()) // If CPM bidding, copy CPM
      .withMaxCpa(oldAdGroup.bidding().getMaxCpa()) // If CPA bidding, copy CPA
      .withStatus(oldAdGroup.isEnabled() ? 'ENABLED' : 'PAUSED')
      .build()
      .getResult();

    Logger.log('Ad group "' + newAdGroup.getName() + '" created.');

    // Copy and modify ads from the old ad group to the new ad group
    var adIterator = oldAdGroup.ads().get();
    while (adIterator.hasNext()) {
      var oldAd = adIterator.next();
      var currentUrl = oldAd.urls().getFinalUrl();

      // If the ad's URL starts with the old base URL, modify it with the new base URL
      if (currentUrl && currentUrl.startsWith(oldBaseUrl)) {
        var urlParams = currentUrl.substring(oldBaseUrl.length); // Get everything after the base URL
        var newUrl = newBaseUrl + urlParams;

        // Copy ad and apply the new URL in the new ad group
        var adBuilder = newAdGroup
          .expandedTextAds()
          .newAd()
          .withHeadlinePart1(oldAd.getHeadlinePart1())
          .withHeadlinePart2(oldAd.getHeadlinePart2())
          .withDescription(oldAd.getDescription())
          .withFinalUrl(newUrl) // Set the new URL here
          .withPath1(oldAd.getPath1())
          .withPath2(oldAd.getPath2())
          .build();

        Logger.log('Ad "' + oldAd.getHeadlinePart1() + '" copied with new URL: ' + newUrl);
      }
    }
  }

  Logger.log('Campaign copy and URL swap complete!');
}
  1. Add the old campaign name, new campaign name, old base URL and new base URL.

  2. Save the script.

  3. Review and authorize the script to access your Google Ads and Google Sheets accounts.

  4. Run the script manually for the first time to populate the initial values in the spreadsheet.

  5. (Optional) Schedule the script to run on a specific cadence (ie: daily, weekly, monthly, etc.)

Note: Ensure that you have the necessary permissions to access and modify the target Google Spreadsheet.

PreviousSwap Base URL'sNextZero spend alert

Last updated 9 months ago