AdWords
2.6K members online now
2.6K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Adwords script for campaign report

Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

Hi,

 

I encountered Account summary report script (https://developers.google.com/adwords/scripts/docs/solutions/account-summary) but Im curious if there is something like this but for campaigns in account. I would like to have the same statistics for every campaign in the particular account. I guess it wont be so easy to just change some code lines in Account summary report script to get what I have on my mind Smiley Happy

 

Thanks for any info

Lukas

4 Expert replyverified_user

Re: Adwords script for campaign report

Explorer ✭ ✭ ✭
# 2
Explorer ✭ ✭ ✭

Hey Lukas,

 

Welcome to AdWords Community. @Jon_Gritton  and @AdWiser  can help you in terms of Scripts. Let's wait for them Smiley Happy

 

Thanks!

Shafi Ahamed

Re: Adwords script for campaign report

Top Contributor
# 3
Top Contributor
All our hopes rest on you, Jon, as I'll be away for a week Smiley Wink.
Calin Sandici, AdWords Top Contributor | Find me on: Google+ | Twitter | LinkedIn | myBlog
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Re: Adwords script for campaign report

Rising Star
# 4
Rising Star
May be following script libraries might help you to find something related to this.

http://www.freeadwordsscripts.com/
http://www.optmyzr.com/scripts/

Re: Adwords script for campaign report

Top Contributor
# 5
Top Contributor

Hi Lukas, unfortunately, no, it's not that simple to change this script to work on a Campaign by Campaign basis because the entire script makes references to the Account structure.

 

However, it's relatively easy to build simple reporting for Campaigns and once you have the basic structure you can add additional metrics and play with the formatting of the spreadsheet until you end up with something that suits your requirements.

 

I'm a little busy at the moment, but in a day or so I'll post something here that'll help you get started.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Adwords script for campaign report

Follower ✭ ☆ ☆
# 6
Follower ✭ ☆ ☆
That would be great.

thanks Jon Smiley Happy

Re: Adwords script for campaign report

Follower ✭ ☆ ☆
# 7
Follower ✭ ☆ ☆
Hi Jon

I hope you didnt forget me Smiley Happy

Re: Adwords script for campaign report

Top Contributor
# 8
Top Contributor

Hi Lukas, sorry, no, I didn't forget, I've just been terribly busy these past couple of weeks.  I promise I'll post you a skeleton script by the end of the week.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Adwords script for campaign report

[ Edited ]
Top Contributor
# 9
Top Contributor

Hi Lukas, this is slightly more than a skeleton, in fact it's a fully working script, but it'll certainly give you all the building blocks you need to adapt for your own purposes.

 

In its current form the script will write statistics to a spreadsheet, using one sheet for each Campaign.  The script will create a new sheet each year and should be run daily around 2am.

 

Copy the spreadsheet linked below into your own Drive and change the URL in the script to be the shared URL of your own copy.  Make sure you grant edit access to the script owner.

 

http://goo.gl/jhApT1

 

The script makes no changes to the Account, so can be run safely, but as always, I recommend using the Preview option before running for the first time.

 

/* Basic Campaign performance
** (c) Jon Gritton 2015
*/

// user vars
// URL of Google Docs Spreadsheet for reporting
var SPREAD_URL = "enter your spreadsheet URL here";

// the "look-back" period used for examining statistics. 7 days is a useful figure as it will then show trends more clearly
// but you may use a shorter period if heavy click activity.
var PERIOD = 7;

var CURR_SYMBOL = "$";

function main() {
doMain();
}

function doMain() {
// get duration dates and other useful dates
var nowThen = getNowThen();
var sheetName = "";

var campIter = AdWordsApp.campaigns()
.withCondition("Status = 'ENABLED'")
.get();

while(campIter.hasNext()) {
thisCampaign = campIter.next();

// Campaigns - use for "ordinary" Campaigns
// For Shopping Campaigns, replace report name below with "SHOPPING_PERFORMANCE_REPORT"
// and change sheetName

var rows = getReportRows(nowThen.now, nowThen.then, thisCampaign.getName(), "CAMPAIGN_PERFORMANCE_REPORT");
sheetName = thisCampaign.getName() + ": " + nowThen.year;

while(rows.hasNext()) {
var thisRow = rows.next();
sData = {date: nowThen.dateCol,
AvCPC: thisRow.AverageCpc,
AvPos: thisRow.AveragePosition,
Clicks: thisRow.Clicks,
Imps: thisRow.Impressions,
CTR: thisRow.Ctr,
Cost: thisRow.Cost,
Conv: thisRow.Conversions,
ConvValue: thisRow.ConversionValue
};
}
logToSheet(sData, sheetName);
}
}

function logToSheet(d, sheetName) {
// log stats to sheet
var thisBook = SpreadsheetApp.openByUrl(SPREAD_URL);
try {
thisBook.setActiveSheet(thisBook.getSheetByName(sheetName));
}
catch(err) {
thisBook.setActiveSheet(thisBook.getSheetByName("Template"));
var newSheet = thisBook.duplicateActiveSheet();
thisBook.renameActiveSheet(sheetName);
}
var thisSheet = thisBook.getSheetByName(sheetName);
thisSheet.appendRow([d.date, d.AvCPC, d.AvPos, d.Clicks, d.Imps, d.CTR, CURR_SYMBOL + parseFloat(d.Cost), d.Conv, parseFloat(d.ConvValue)]);
}

function getReportRows(now,then,campaignName, reportName) {
// retrieves Keyword level performance data for mobile or non-mobile clicks
var sql = "SELECT AverageCpc, AveragePosition, Clicks, Impressions, Ctr, Cost, Conversions, ConversionValue " +
"FROM " + reportName + " " +
"WHERE CampaignName = '" + campaignName + "' " +
"DURING " + then + "," + now;
var report = AdWordsApp.report(sql);
return report.rows();
}

function getNowThen() {
// simply generates dates for a period in the correct format for use with API reports
// and other handy date related vars
var d = new Date();
var dateCol = (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear();
var now = Utilities.formatDate(new Date(),AdWordsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
d.setDate(d.getDate()-PERIOD);
var then = Utilities.formatDate(d,AdWordsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
return {now: now, then: then, dateCol: dateCol, year: d.getFullYear()};
}

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Adwords script for campaign report

Follower ✭ ☆ ☆
# 10
Follower ✭ ☆ ☆
Hi Jon,

thats great, I will test it tomorrow but I want to ask, you´re writing there to copy this spreadsheet to my google drive but I dont see any link to special spreadsheet, does it mean that all I need to do is just create a blank spreadsheet or ...?

Thanks
Lukas