Script to pause keywords based on account performance

137 views
Skip to first unread message

Josh

unread,
Jun 26, 2018, 4:27:07 PM6/26/18
to AdWords Scripts Forum
Hi,

Does anyone know if it's possible to create a script that will pause poor performing keywords when the account average CTR is below a certain threshold and then turn them back on again when the account average CTR rises?

Rules won't allow it but I essentially want something like this:

If account CTR =<2%, pause keywords with CTR =<2%
Then wait a day or two and run...
If account CTR=>2.1%, enable keywords with CTR =<2% or with no CTR stat.

Please bear in mind I don't know Javascript.

Thanks in advance,
Josh 

Hiroyuki Miyauchi (AdWords Scripts Team)

unread,
Jun 27, 2018, 3:47:44 AM6/27/18
to AdWords Scripts Forum
Hello Josh,

You may refer to the sample script below to help you get started. If it meets your requirements, you may implement the script under your MCC account, and you may modify the code based on your preferences.

The following are the steps implemented in the script.
  1. Fetch all accounts under your MCC account using accounts method
  2. Fetch account's stats using getStatsFor method (Please update the dateRange based on your preference)
  3. Fetch all keywords under the account using keywords method
  4. Fetch keyword's stats using getStatsFor method (Please update the dateRange based on your preference)
  5. Check if the account's CTR satisfies the condition "CTR =<2%"
    1. If yes, check if the keyword's CTR satisfies the condition "CTR =<2%" and pause the keyword using pause method
    2. If no, check if the keyword's CTR satisfies the condition "CTR =<2% or with no CTR", and enable the keyword using enable method
function main() {

   
var accountIterator = MccApp.accounts().get();

   
while (accountIterator.hasNext()) {
       
var account = accountIterator.next();
       
MccApp.select(account);
       
var accountStats = account.getStatsFor("INSERT_DATE_RANGE");
       
var keywordsIterator = AdWordsApp.keywords().get();

       
while (keywordsIterator.hasNext()) {

           
var keyword = keywordsIterator.next();
           
var keywordStats = keyword.getStatsFor("INSERT_DATE_RANGE");

           
//If account CTR =<2%
           
if (accountStats.getCtr() <= 2) {

               
//keyword CTR =<2%
               
if (keywordStats.getCtr() <=  2) {
                   
//Pause keyword
                    keyword
.pause();
               
}

           
//If account CTR =>2.1%
           
} else {

               
//keyword CTR =<2% or with no CTR
               
if (keywordStats.getCtr() <=  2) {
                   
//Enable keyword
                    keyword
.enable();
               
}

           
}

       
}

   
}

}

I would suggest that you test this script using the Preview button first to see possible changes.

Regards,
Hiroyuki
AdWords Scripts Team

Josh

unread,
Jun 28, 2018, 9:44:41 AM6/28/18
to AdWords Scripts Forum
Thanks Hiroyuki, 

I'll give it a go. can the date range be set so it analyses the previous week or day or do I have to put in actual dates? I would ideally like to keep the script running every day or week.

Thanks for your help,
Josh

Josh

unread,
Jun 28, 2018, 9:47:34 AM6/28/18
to AdWords Scripts Forum
P.S. will it be fairly straight forward to edit the script so it only analyses a particular account? We have three active accounts but I only want to run this script on one.
Thanks,
Josh

On Wednesday, 27 June 2018 08:47:44 UTC+1, Hiroyuki Miyauchi (AdWords Scripts Team) wrote:

Hiroyuki Miyauchi (AdWords Scripts Team)

unread,
Jun 29, 2018, 12:03:57 AM6/29/18
to AdWords Scripts Forum
Hello Josh,

With regards on setting the date range, you can check supported values in getStatsFor(dateRange) or getStatsFor(dateFrom, dateTo) documentation page. If you want to fetch all the data from the previous week, then you can set LAST_WEEK and set YESTERDAY if you want to get all the data from previous day.

The script I provided in the previous thread will check all client accounts under your MCC account. If you want to run the script for one account, you may implement the sample script below in your specific account.

function main() {

   
var accountStats = AdWordsApp.currentAccount().getStatsFor("INSERT_DATE_RANGE");

   
var keywordsIterator = AdWordsApp.keywords().get();

   
while (keywordsIterator.hasNext()) {

       
var keyword = keywordsIterator.next();
       
var keywordStats = keyword.getStatsFor("INSERT_DATE_RANGE");

       
//If account CTR =<2%
       
if (accountStats.getCtr() <= 2) {

           
//keyword CTR =<2%
           
if (keywordStats.getCtr() <= 2) {
               
//Pause keyword
                keyword
.pause();
           
}

       
//If account CTR =>2.1%
       
} else {

           
//keyword CTR =<2% or with no CTR
           
if (keywordStats.getCtr() <= 2) {
               
//Enable keyword
                keyword
.enable();
           
}
       
}
   
}
}

Please let me know how it goes after previewing the sample script above.

Josh

unread,
Jun 29, 2018, 4:35:06 AM6/29/18
to AdWords Scripts Forum
Thanks Hiroyuki - that's exactly what I need. Thanks for getting back to me so quickly.

Cheers,
Josh
Reply all
Reply to author
Forward
0 new messages