function addImageAd(adGroupName,imageUrl,imageName) { const imageBlob = UrlFetchApp.fetch(imageUrl).getBlob(); const mediaOperation = AdsApp.adMedia().newImageBuilder() .withName(`${imageName}`) .withData(imageBlob) .build(); const image = mediaOperation.getResult(); if (!image.isSuccessful()) { throw new Error(`Media could not be created from url: "${imageUrl}"`) } const adGroupIterator = AdsApp.adGroups() .withCondition(`ad_group.name = "${adGroupName}"`) .get(); if (!adGroupIterator.hasNext()) { throw new Error(`No ad group found with name: "${adGroupName}"`); } if (adGroupIterator.totalNumEntities() > 1) { console.warn(`Multiple ad groups named "${name}" found. Using the one from campaign "${adGroup.getCampaign().getName()}".`); } const mediaIterator = AdsApp.adMedia().media() .withCondition(`media_file.name = "${imageName}"`) .get(); if (!mediaIterator.hasNext()) { throw new Error(`No media found with name: "${imageName}"`); } const adGroup = adGroupIterator.next(); const image2 = mediaIterator.next(); adGroup.newAd().imageAdBuilder() .withName('Ad name') .withImage(image2) .withDisplayUrl('http://www.example.com') .withFinalUrl('http://www.example.com') .build(); // ImageAdBuilder has additional options. // For more details, see // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_imageadbuilder }

Preparing destination link... You will be redirected in 5 seconds

Continue to Full Story Now>>>
function addImageAd(adGroupName,imageUrl,imageName) { const imageBlob = UrlFetchApp.fetch(imageUrl).getBlob(); const mediaOperation = AdsApp.adMedia().newImageBuilder() .withName(`${imageName}`) .withData(imageBlob) .build(); const image = mediaOperation.getResult(); if (!image.isSuccessful()) { throw new Error(`Media could not be created from url: "${imageUrl}"`) } const adGroupIterator = AdsApp.adGroups() .withCondition(`ad_group.name = "${adGroupName}"`) .get(); if (!adGroupIterator.hasNext()) { throw new Error(`No ad group found with name: "${adGroupName}"`); } if (adGroupIterator.totalNumEntities() > 1) { console.warn(`Multiple ad groups named "${name}" found. Using the one from campaign "${adGroup.getCampaign().getName()}".`); } const mediaIterator = AdsApp.adMedia().media() .withCondition(`media_file.name = "${imageName}"`) .get(); if (!mediaIterator.hasNext()) { throw new Error(`No media found with name: "${imageName}"`); } const adGroup = adGroupIterator.next(); const image2 = mediaIterator.next(); adGroup.newAd().imageAdBuilder() .withName('Ad name') .withImage(image2) .withDisplayUrl('http://www.example.com') .withFinalUrl('http://www.example.com') .build(); // ImageAdBuilder has additional options. // For more details, see // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_imageadbuilder }