Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

AdWords MCC Scripts – Beginner’s Guide

When working with multiple clients there are very often tasks that you need to do – whether it’s every week or every month – that are mundane, repetitive, and could seemingly be done by a robot. Happily, if that really is the case, scripting is very often the right answer. Keep in mind that although automation can be incredibly powerful when done well, it isn’t an excuse to spend no time analysing and manually updating your campaigns. This post is an intro to MCC scripting and, although straightforward, assumes that you have at least some passing knowledge in javascript.

What we need

For this post we’re going to take a really simple example of a weekly report. This needs to be generated for 3 accounts within our MCC, and is a simple set of to level stats (overall CTR, CPC, etc.) that we then send onto the client manually every Friday. We generate a more detailed monthly report, which is done manually, but for this weekly email there’s no need for any insights – it’s a very straightforward “here’s how the account’s performed this week”.

Creating our first script

First things first, we log in to our MCC account and go to the “scripts” menu. Once we’re there we click the button to “add a new script” and we immediately end up on a screen that lets us create our code.

From here we need to name our script and authorise it to have access to our AdWords account. Let’s do that straight away to keep life simple and make sure that as we want to test things out we can do. You’ll also notice that there’s a single function that’s already been created for us.

With the formalities out of the way, it’s time to start building our code. Unlike normal AdWords scripts, an MCC script needs to be told which accounts to access first, and then what to do with each one afterwards. This could be done by specifying the account id(s) or, and this is my preference, by using account labels. The reason I prefer the latter is that if you want to add or remove accounts you don’t need to edit your script – you simply update the labels and the script does the rest.

So, here’s our first code snippet to do just that:

function main() {
// Specify the label name to look for
var labelName = 'Friday Report';
// Select the accounts to be processed.
var accountIterator = MccApp.accounts()
.withCondition('LabelNames CONTAINS "' + labelName + '"')
.get();
}

Nice and simple. We specify the label we want to look for, and then “get” any accounts that have a label containing that name. These accounts are then stored within the “accountIterator” variable which we’ll use later.

If you’d rather specify by account id, this code would change to the following:

function main() {
// Specify the label name to look for
var labelName = 'Friday Report';
// Select the accounts to be processed.
var accountIterator = MccApp.accounts()
.withIds(['123-456-7890', '223-456-7890', '323-456-7890'])
.get();
}

So far so good but all we’ve done so far is select a few account. Now it’s time to do something with them.

Iterating through accounts

Moving on from account selection, we now want to create a loop that goes through each one and then does something. Let’s start with that loop:

// First we take the accountIterator variable from before
while (accountIterator.hasNext()) {
// And, for each account, we save the data into another variable
var account = accountIterator.next();
// Switch to the account you want to process.
MccApp.select(account);
// Now we can do something
}

So that’s moved us on slightly – we’ve now gone from having a list of accounts to being able to select each one, but we’re still not actually doing anything. Let’s grab some data.

// Generate account level query
var report = AdWordsApp.report(
'SELECT Clicks, Impressions, Cost, AllConversions, AllConversionValue, ViewThroughConversions, Ctr ' +
'FROM ACCOUNT_PERFORMANCE_REPORT ' +
'DURING LAST_WEEK');
// Get the results and save them into a variable
var rows = report.rows();
while (rows.hasNext()) {
var row = rows.next();
var clicks = row['Clicks'];
var impressions = row['Impressions'];
var cost = row['Cost'];
var ctr = row['Ctr'];
}

We have two option for generating this data – we could access to the account, check the stats, and do some calculations… or we could use the AdWords reporting API to get all of our data really quickly. There are a load of reports that you can access, doing so via an AWQL query (which is basically a SQL query), the documentation for which can be found here.

Knowing it’s working

So far we’ve written some code but have no idea at all whether or not we’ve been able to access the data. Here’s where logging comes into play. Adding this line below or AWQL query will output results into the console so we can see what’s going on:

Logger.log(account.getName() + ": Clicks " + clicks + ', Impressions ' + impressions + ' CTR ' + ctr + ', Cost £' + cost);

If we put all of that together, here’s our code:

function main() {

// Specify the label name to look for
var labelName = 'Friday Report';
// Select the accounts to be processed.
var accountIterator = MccApp.accounts()
.withCondition('LabelNames CONTAINS "' + labelName + '"')
.get();

// First we take the accountIterator variable from before
while (accountIterator.hasNext()) {
// And, for each account, we save the data into another variable
var account = accountIterator.next();
// Switch to the account you want to process.
MccApp.select(account);
// Now we can do something

// Generate account level query
var report = AdWordsApp.report(
'SELECT Clicks, Impressions, Cost, AllConversions, AllConversionValue, ViewThroughConversions, Ctr ' +
'FROM ACCOUNT_PERFORMANCE_REPORT ' +
'DURING LAST_WEEK');
// Get the results and save them into a variable
var rows = report.rows();
while (rows.hasNext()) {
var row = rows.next();
var clicks = row['Clicks'];
var impressions = row['Impressions'];
var cost = row['Cost'];
var ctr = row['Ctr'];
}

Logger.log(account.getName() + ": Clicks " + clicks + ', Impressions ' + impressions + ' CTR ' + ctr + ', Cost £' + cost);

}

}

Finally, make sure you’ve applied the “Friday Report” lable to at least one account, click the “preview” button, go to the “log” tab, and here’s what we see:

Done! Well, not quite…

That’s really useful but it means that we have to log into the account each week to run the report at a certain time. Fortunately it’s possible to send emails from AdWords scripts as well as being able to schedule them, which is something I’ll write about in a separate post.

if you’re looking for help with your AdWords campaigns, I offer consulting on both an agency and freelance basis.

The post AdWords MCC Scripts – Beginner’s Guide appeared first on Matt Beswick - Digital Strategist, PPC & SEO Consultant.



This post first appeared on SEO Consultant - SEO Services | Matt Beswick, please read the originial post: here

Share the post

AdWords MCC Scripts – Beginner’s Guide

×

Subscribe to Seo Consultant - Seo Services | Matt Beswick

Get updates delivered right to your inbox!

Thank you for your subscription

×