Responsive ad customizers update

38 views
Skip to first unread message

Mindaugas Jakutis

unread,
Jun 20, 2024, 12:00:30 PM (13 days ago) Jun 20
to Google Ads Scripts Forum
Hi,

I've tried to create a script that would take responsive ad customizer values from my csv file and update it. But after many tries it seems that I need some help. Could anyone review my code ant tell where the problem is? Or maybe anyone already solved this and have a functioning solution?

function main() {
  // URL of the CSV file
  var csvUrl = 'https://www.pasirinksparnus.lt/download/files/feeds/customizer_hotels.csv';

  // Fetch and parse the CSV file
  var response = UrlFetchApp.fetch(csvUrl);
  var csvContent = response.getContentText();
  var csvData = Utilities.parseCsv(csvContent);

  // Extract headers and ensure 'Ad Group' is present
  var headers = csvData[0];
  var adGroupNameIndex = headers.indexOf('Ad Group');
  if (adGroupNameIndex === -1) {
    Logger.log('Ad Group column not found in the CSV file');
    return;
  }

  // Create a map of ad customizer data
  var customizerData = {};
  for (var i = 1; i < csvData.length; i++) {
    var row = csvData[i];
    if (row.length !== headers.length) {
      continue; // Skip malformed rows
    }
    var adGroupName = row[adGroupNameIndex];
    var customizerValues = {};
    for (var j = 0; j < headers.length; j++) {
      if (j != adGroupNameIndex) {
        var key = headers[j];
        var value = row[j];
        customizerValues[key] = value;
      }
    }
    customizerData[adGroupName] = customizerValues;
  }

  // Iterate through ad groups and update ad customizers
  var adGroups = AdsApp.adGroups().get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    var adGroupName = adGroup.getName();

    // Find the matching customizer data for the ad group
    var customizerValues = customizerData[adGroupName];
    if (customizerValues) {
      // Assign customizer attributes to the responsive search ads
      var ads = adGroup.ads().withCondition("Type = RESPONSIVE_SEARCH_AD").get();
      while (ads.hasNext()) {
        var ad = ads.next();
        applyCustomParameters(ad, customizerValues);
      }
    }
  }
}

function applyCustomParameters(ad, customizerValues) {
  var customParameters = {};
  for (var key in customizerValues) {
    customParameters[key] = customizerValues[key];
  }
  ad.urls().setCustomParameters(customParameters);
}

Google Ads Scripts Forum

unread,
Jun 21, 2024, 8:28:58 AM (12 days ago) Jun 21
to Google Ads Scripts Forum

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

In order to replicate your issue at our end, kindly provide us with the below details.

  • Google Ads account ID/CID
  • Name of the affected script

You can share the requested details via Reply privately to the author option or a direct private reply to this email.

Thanks,
Google Ads Scripts team

Mindaugas Jakutis

unread,
Jul 1, 2024, 4:58:25 AM (2 days ago) Jul 1
to Google Ads Scripts Forum
Hi,

  • Google Ads account ID/CID -  452-598-5404
  • Name of the affected script - Hotels - Update Ad Customizer Attributes
Thanks for the help!

Google Ads Scripts Forum Advisor

unread,
Jul 1, 2024, 10:57:43 AM (2 days ago) Jul 1
to adwords...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads Scripts team. 

When I tried to preview the script, I got the error "ad.urls(...).setCustomParameters is not a function ". The ad.urls() function does not support the setCustomParameters() function. You may refer to this document to know more about the supported methods of ad.urls(). Also, you may check this guide to set the custom parameters of the ad group.

Hope this helps. Let us know if you have any further queries. 
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02tJWZF:ref" (ADR-00244670)

Thanks,
 
Google Logo Google Ads Scripts Team


Reply all
Reply to author
Forward
0 new messages