Google ads API Script images

Google ads script for build client report using aPI


Have a great day, Today’s i am gonna share with you a Google Adword Keyword Performance Client Report Script and as well as tell you how to GENERATE Client Report in google adword with using API.

It MADE up with JAVA SCRIPT PROGRAMMING language which is add in google ads bulk option for built a client report very easily. Some of the syntax we will use in the script and made up some changes in the script and then we will follow the CONDITIONAL rule in google ads new interface.

Google docs file :

We will use some parameter in php script code according to the google ads performance then google ads will mail us the spread sheet url containing all the report of our performance.

First of all , we will come into the google ads interface

Then click on the Tools & Setting

then go to the bulk option

then click on the script option

Now, This is final Script which will use for the build up client report using api.

/ Comma-separated list of recipients. Comment out to not send any emails.
 var RECIPIENT_EMAIL = 'Put into your ad word mail id';
 // URL of the default spreadsheet template. This should be a copy of
 var SPREADSHEET_URL = 'Put into your spread sheet url';
 This script computes an Ad performance report
 and outputs it to a Google spreadsheet.
 function main() {
 Logger.log('Using template spreadsheet - %s.', SPREADSHEET_URL);
 var spreadsheet = copySpreadsheet(SPREADSHEET_URL);
 Logger.log('Generated new reporting spreadsheet %s based on the template ' +
   'spreadsheet. The reporting data will be populated here.',
 var headlineSheet = spreadsheet.getSheetByName('Headline');
 headlineSheet.getRange(1, 2, 1, 1).setValue('Date');
 headlineSheet.getRange(1, 3, 1, 1).setValue(new Date());
 var finalUrlSheet = spreadsheet.getSheetByName('Final Url');
 finalUrlSheet.getRange(1, 2, 1, 1).setValue('Date');
 finalUrlSheet.getRange(1, 3, 1, 1).setValue(new Date());
 // Only include ad types on the headline sheet for which the concept of a
 // headline makes sense.
 outputSegmentation(headlineSheet, 'Headline', function(ad) {
 var headline;
 // There is no AdTypeSpace method for textAd
 if (ad.getType() === 'TEXT_AD') {
   headline = ad.getHeadline();
 } else if (ad.isType().expandedTextAd()) {
   var eta = ad.asType().expandedTextAd();
   headline = eta.getHeadlinePart1() + ' - ' + eta.getHeadlinePart2();
 } else if (ad.isType().gmailMultiProductAd()) {
   var gmailMpa = ad.asType().gmailMultiProductAd();
   headline = gmailMpa.getHeadline();
 } else if (ad.isType().gmailSinglePromotionAd()) {
   var gmailSpa = ad.asType().gmailSinglePromotionAd();
   headline = gmailSpa.getHeadline();
 } else if (ad.isType().responsiveDisplayAd()) {
   var responsiveDisplayAd = ad.asType().responsiveDisplayAd();
   headline = responsiveDisplayAd.getLongHeadline();
 return headline;
 outputSegmentation(finalUrlSheet, 'Final Url', function(ad) {
 return ad.urls().getFinalUrl();
 Logger.log('Ad performance report available at\n' + spreadsheet.getUrl());
 if (validateEmailAddress(RECIPIENT_EMAIL)) {
   'Ad Performance Report is ready',
 Retrieves the spreadsheet identified by the URL.
 @param {string} spreadsheetUrl The URL of the spreadsheet.
 @return {SpreadSheet} The spreadsheet.
 function copySpreadsheet(spreadsheetUrl) {
 var spreadsheet = validateAndGetSpreadsheet(spreadsheetUrl).copy(
   'Ad Performance Report - ' +
   getDateStringInTimeZone('MMM dd, yyyy HH:mm:ss z'));
 // Make sure the spreadsheet is using the account's timezone.
 return spreadsheet;
 Generates statistical data for this segment.
 @param {Sheet} sheet Sheet to write to.
 @param {string} segmentName The Name of this segment for the header row.
 @param {function(AdsApp.Ad): string} segmentFunc Function that returns
 a string used to segment the results by.
 function outputSegmentation(sheet, segmentName, segmentFunc) {
 // Output header row.
 var rows = [];
 var header = [
 'Num Ads',
 'CTR (%)',
 var segmentMap = {};
 // Compute data.
 var adIterator =
   .withCondition('Impressions > 0').get();
 while (adIterator.hasNext()) {
 var ad =;
 var stats = ad.getStatsFor('LAST_WEEK');
 var segment = segmentFunc(ad);
 // In the case of the headline segmentation segmentFunc will return null
 // where there is no headline e.g. an HTML5 ad or other non-text ad, for
 // which metrics are therefore not aggregated.
 if (segment) {
   if (!segmentMap[segment]) {
     segmentMap[segment] =
         {numAds: 0, totalImpressions: 0, totalClicks: 0, totalCost: 0.0};
   var data = segmentMap[segment];
   data.totalImpressions += stats.getImpressions();
   data.totalClicks += stats.getClicks();
   data.totalCost += stats.getCost();
 // Write data to our rows.
 for (var key in segmentMap) {
 if (segmentMap.hasOwnProperty(key)) {
   var ctr = 0;
   if (segmentMap[key].numAds > 0) {
     ctr = (segmentMap[key].totalClicks /
       segmentMap[key].totalImpressions) * 100;
   var row = [
 sheet.getRange(3, 2, rows.length, 6).setValues(rows);
 Produces a formatted string representing a given date in a given time zone.
 @param {string} format A format specifier for the string to be produced.
 @param {date} date A date object. Defaults to the current date.
 @param {string} timeZone A time zone. Defaults to the account's time zone.
 @return {string} A formatted string of the given date in the given time zone.
 function getDateStringInTimeZone(format, date, timeZone) {
 date = date || new Date();
 timeZone = timeZone || AdsApp.currentAccount().getTimeZone();
 return Utilities.formatDate(date, timeZone, format);
 Validates the provided email address
 to make sure that it's set up properly. Throws a descriptive error message
 if validation fails.
 @param {string} emailAddress The email address to send the results.
 @return {Spreadsheet} The email address, if it is not the default fake one.
 @throws {Error} If the email address has not been changed from the default.
 function validateEmailAddress(emailAddress) {
 if (emailAddress == '') {
 throw new Error('Please specify a valid email or leave empty to not' +
 ' send any email.');
 return emailAddress;
 Validates the provided spreadsheet URL
 to make sure that it's set up properly. Throws a descriptive error message
 if validation fails.
 @param {string} spreadsheeturl The URL of the spreadsheet to open.
 @return {Spreadsheet} The spreadsheet object itself, fetched from the URL.
 @throws {Error} If the spreadsheet URL hasn't been set
 function validateAndGetSpreadsheet(spreadsheeturl) {
 if (spreadsheeturl == 'YOUR_SPREADSHEET_URL') {
 throw new Error('Please specify a valid Spreadsheet URL. You can find' +
     ' a link to a template in the associated guide for this script.');
 return spreadsheet = SpreadsheetApp.openByUrl(spreadsheeturl); 

After paste this code in bulk action script, you have to made some changes which is bolt in the script you can see in the api script above

we will know about this more with using of some screen shot images.

This is Script option you can see above in the image which i used in the google ads client report build using api.

however, you had seen this images so we have already let you know about that how to use this script in google ads. so keep follow my instruction and then build the client report using api in google ads.

1 thought on “Google Adword Keyword Performance Report Script by API”

Leave a Reply

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