Menu
PPC guy with allen wrench

Adwords Script to Pause Campaigns When Clients Owe You Money

This historically first script by Pizza SEO automatically pauses campaigns in your client accounts based on the condition you set. We use them to automatically pause campaigns of clients that have forgotten to pay their deposit for credit or invoice due.

We automatically generate and update the list of unpaid invoices with company identifier (usually a country level company ID) and amount due. Company IDs are paired with IDs of their Adwords account. If a client does not pay their invoice on time, the running campaigns are paused automatically. When such an invoice is paid, the campaigns will be enabled back again without any manual input. Since everything is hapenning automatically “behind the scenes”, it does not take a few days to get information about the payment to their manager to turn them on back again as it sometimes hapenned in the past.

You can use the script for your own use without any further conditions. The script itself runs from a Google spreadsheet. If you can not automatically generate unpaid invoices due, you can also enter these by hand. We do however recommend to pair company IDs with their respective Adwords IDs in a helper sheet.

How does this Adwords script work?

The script pauses under Adwords account, if Adwords ID appears in a spreadheet (once it is removed, the script unpauses such a campaign). The paused campaigns are labeled with Temporary label, so you can easily identify them, if needed. Once the Adwords ID is removed, the script automatically unpauses the campaigns that were running before and removes the label.

This script fully works with an MCC Adwords account.

Instructions on use:

  1. Create a copy of Google spreadsheetu https://docs.google.com/spreadsheets/d/1eRGX6UQSV2epnZ0Kp4cqpJHm2fj6nhGWtSNSJ_mDRYw/edit?usp=sharing and fill some test data in (Adwords ID must exist and your Google account must have full/edit access to it).
  2. Replace SHEET_URL in the script with the URL of the Google spreadsheet that you have created in step 1.
  3. Fill in Adwords IDs of the clients that have unpaid invoices due in the Client ID column of the Google spreadsheet using this format: 123-456-7890. You can, but don’t have to fill other columns.
  4. If you delete a value from Client ID, the script will automatically run the campaigns that were paused by it.
  5. The script loops over the first 150 rows of the spreadsheet. If you have more than 150 clients owing you money (we hope that’s not your case, though!), just change the used range B2:B151 to e.g. B2:B300 to include further rows.
  6. Set the script to run e.g. every hour.

We will be happy to hear any comments from you, if you use our script. We like Adwords scripts and have written about them in the past!

Adwords script to pause campaigns

Developed by: Nina Varhaníková


/*****************************************************************************
* Pause and enable campaigns - Google Adwords *
* Script pause/enable campaigns if client does not pay/pays an invoice *
* Run the script every hour *
* Developed by: Nina Varhanikova *
* Company: Pizza SEO *
* License: Public domain *
******************************************************************************/

// Place URL of the spreadsheet template inside the brackets
var ss_config = SpreadsheetApp.openByUrl('SHEET_URL');
function main() {
PAUSE();
ENABLE();
}

//PAUSE CAMPAIGNS
function PAUSE()
{
//Choose data from a sheet
var sheet=ss_config.getSheetByName("Client ID")
//Data range
var sheet_range = sheet.getRange("B2:B151").getValues();
var empty_cell = false;
//Cycle running through accounts
for (var a = 0; a < sheet_range.length; a++)
{
if (sheet_range[a] == "")
{
empty_cell = true;
break;
}
if (empty_cell == false)
{
//Create label
var labelName = 'Temporary label';
MccApp.createAccountLabel(labelName);
//Choose account
var working_account1 = MccApp.accounts()
.withIds(sheet_range[a])
.get().next();
MccApp.select(working_account1);

//SCRIPT WORKING IN CAMPAIGNS

//Create label
AdWordsApp.createLabel("Temporary label");

//Assign label to enabled campaigns

//All Campaigns except for video campaigns
var campaignIterator = AdWordsApp.campaigns()
.withCondition("Status = ENABLED")
.get();
while (campaignIterator.hasNext())
{
var campaign = campaignIterator.next();
campaign.applyLabel('Temporary label');
}
//Video campaigns
var campaignIterator1 = AdWordsApp.videoCampaigns()
.withCondition("Status = ENABLED")
.get();
while (campaignIterator1.hasNext())
{
var campaign1 = campaignIterator1.next();
campaign1.applyLabel('Temporary label');
}

//Pause campaigns

//All Campaigns except for video campaigns
var campaignIterator2 = AdWordsApp.campaigns().get();
while (campaignIterator2.hasNext())
{
var campaign2 = campaignIterator2.next();
campaign2.pause();
}
//Video campaigns
var campaignIterator3 = AdWordsApp.videoCampaigns().get();
while (campaignIterator3.hasNext())
{
var campaign3 = campaignIterator3.next();
campaign3.pause();
}

//Back to account
MccApp.select(working_account1);
}
}
}
//ENABLE CAMPAIGNS
function ENABLE()
{
//Choose data from a sheet
var sheet=ss_config.getSheetByName("Client ID")
//Data range
var sheet_range = sheet.getRange("B2:B151").getValues();
var field_ID = [];

for(var b = 0; b < sheet_range.length; b++)
{
if (sheet_range[b] != "")
{
field_ID.push(sheet_range[b]);
}
}
Logger.log(field_ID)

//Choose account ID
var select_account2 = MccApp.accounts().get();
while (select_account2.hasNext())
{
var working_account = select_account2.next();
MccApp.select(working_account);
//Compare account ID with ID in sheet
var accountID = working_account.getCustomerId();
var found = false;
for(var y = 0; y < field_ID.length; y++) {
if (field_ID[y][0] == accountID)
{
found = true;
break;
}
}

//SCRIPT WORKING IN CAMPAIGNS
if(found == false)
{
//Choose campaigns that are not in the sheet and have been paused due to an unpaid bill
var labelIterator = AdWordsApp.labels()
.withCondition("Name = 'Temporary label'")
.get();
//Enable campaigns and remove label
while (labelIterator.hasNext())
{
var label = labelIterator.next();
var campaignIterator4 = label.campaigns().get();
while (campaignIterator4.hasNext())
{
var campaign4 = campaignIterator4.next();
campaign4.enable();
campaign4.removeLabel('Temporary label');
}
var campaignIterator5 = label.videoCampaigns().get();
while (campaignIterator5.hasNext())
{
var campaign5 = campaignIterator5.next();
campaign5.enable();
campaign5.removeLabel('Temporary label');
}
}
}
}
//Back to account
MccApp.select(working_account);
}

Tags: , ,