Ad Customizer Script By Weather Conditions

189 views
Skip to first unread message

James G

unread,
Jul 25, 2017, 8:18:21 AM7/25/17
to AdWords Scripts Forum
Hello,

I'm wondering if anyone has any experience creating a hybrid of the bid adjustment by weather script and the Ad Customisers script?

Essentially, the output i'm looking for is the ability to have a set of weather specific ad copies show during specific weather conditions.

I have searched around, but i've not seen anything along these lines done before (apologies if I missed it!)

It seems as though all of the required pieces to the puzzle are available (Weather data API, ability to customise from a reference sheet), however my fingers are not currently capable of the magic required to produce the end result.

Any insights appreciated.

Thanks

Anthony Madrigal

unread,
Jul 25, 2017, 2:32:20 PM7/25/17
to AdWords Scripts Forum
Hi James,

I'm afraid we don't have a script that combines the two.

You could consider using the Generic Weather script instead. You could place your logic for ad customizers into one of the functions from the weather script.

Regards,
Anthony
AdWords Scripts Team

James G

unread,
Jul 27, 2017, 6:56:06 AM7/27/17
to AdWords Scripts Forum
Hi Anthony,

Thanks very much for the response.

Apologies for being spectacularly out of my depth here, but could you please give me some further insight on how to go about achieving what you describe?

Here is an attempt I have made, really appreciate any insights you can provide;


 * Manage your campaigns based on current weather. The contents of
 * this method are for your reference; replace it with your campaign
 * management logic.
 */
function manageCampaignsBasedOnCurrentWeather() {
  var manchesterWeather = getWeatherForLocation('Manchester, GB');

  // Example 1: Use weather summary provided by OpenWeathermap.
  if (manchesterWeather.weather.status.summary === 'Rain') {
    // Add your logic here.

/**
 * Retrieves an ad group given a campaign and ad group name.
 *
 * @param {string} campaignName The campaign name.
 * @param {string} adGroupName The ad group name.
 * @return {!AdGroup} The ad group.
 * @throws if the specified campaign and ad group does not exist.
 */
function getAdGroup(campaignName, adGroupName) {
  return AdWordsApp.adGroups()
      .withCondition('Name = "' + adGroupName + '"')
      .withCondition('CampaignName = "' + campaignName + '"')
      .get()
      .next();
}

/**
 * Creates customized ads if they haven't already been created.
 *
 * @param {!AdGroup} adGroup The ad group within which to create the ads.
 */
function maybeCreateAds(adGroup) {
  var ads = adGroup.ads().get();
  while (ads.hasNext()) {
    var ad = ads.next();
    if (ad.isType().expandedTextAd()) {
      var expandedTextAd = ad.asType().expandedTextAd();
      if (expandedTextAd.getHeadlinePart1() == 'Flowers For Sale') {
        // The ads have already been created; no need to do more
        return;
      }
    }
  }

  // Reference the 'Weather' data source here; text will be inserted when the
  // ad is served.
  adGroup.newAd().expandedTextAdBuilder()
      .withHeadlinePart1('{=Weather.name} For Sale')
      .withHeadlinePart2('Fresh cut {=Weather.name_lowercase}')
      .withDescription('starting at {=Weather.price}')
      .withFinalUrl('http://example.com')
      .build();
  // All ad groups also need to have an ad without ad customizers to fall back
  // on, in case no ad customizers are able to serve.
  adGroup.newAd().expandedTextAdBuilder()
      .withHeadlinePart1('Flowers For Sale')
      .withHeadlinePart2('Fresh cut flowers')
      .withDescription('delivered for cheap')
      .withFinalUrl('http://www.example.com')
      .build();
}

}

/**
 * Retrieves or creates the Weather data source.
 *
 * @return {!AdCustomizerSource}
 */
function getOrCreateDataSource() {
  var sources = AdWordsApp.adCustomizerSources().get();
  while (sources.hasNext()) {
    var source = sources.next();
    if (source.getName() == 'Flowers') {
      return source;
    }


  }
  return AdWordsApp.newAdCustomizerSourceBuilder()
      .withName('Weather')
      .addAttribute('name', 'text')
      .addAttribute('name_lowercase', 'text')
      // Attributes named 'Custom ID' are special: the system will make sure
      // that all values in the data source have unique custom IDs.
      .addAttribute('Custom ID', 'text')
      .build()
      .getResult();
}





}
/**
 * Obtains a mapping from Customizer ID to Customizer object.
 *
 * @param {!AdCustomizerSource} source
 * @return {!Object.<!AdCustomizerItem>} A mapping from custom ID to item.
 */
function getCustomizersById(source) {
  var customizers = source.items().get();
  var customizersById = {};
  while (customizers.hasNext()) {
    var customizer = customizers.next();
    customizersById[customizer.getAttributeValue('Custom ID')] = customizer;
  }
  return customizersById;
}





James

Anthony Madrigal

unread,
Jul 27, 2017, 3:01:03 PM7/27/17
to AdWords Scripts Forum
Hi James,

It may be easier for you to implement the Ad Customizer snippets with the weather script rather than the Ad Customizer Solution.

Please let me know if you face any issues.

Cheers,
Anthony
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages