0

We're building a platform that fetches data from the AdWords accounts under our AdWords Manager account and saves the data onto BigQuery to be viewed online via nice charts and tables.

As you all know, Adwords numbers need a few days to stabilize. So, every day at 12am we need to refetch all the data for the past 2 weeks and overwrite the data we already have saved for these 2 weeks (we're basically updating the numbers we have).

Our AdWords manager account has 150+ accounts under it. So, when we run the script that fetches the data for all these accounts for the past 2 weeks, understandably, the script times out because it needs more than 65 minutes to be done with the task.

When we looked online for solutions, the only thing we could find was using the "executeInParallel" function provided by the Adwords Script. This should allow us to run a function on several accounts at the same time. Unfortunately, the "executeInParallel" function cannot be called on more than 50 accounts. Since we have 150+ accounts, we cannot call the "executeInParallel" function on them.

We tried splitting the accounts into groups of 50 and calling the "executeInParallel" function on these groups. However, the "executeInParallel" function cannot be called more than once in a single script. This means that we're not able to use this solution.

The only other solution we can think of is to create a script for each one of the 14 days and have each script would fetch the data of all the accounts for a specific day. So, Script1 would fetch the data for today -1. Script2 would fetch the data for today -2 ... Script14 would fetch the data for today -14.

Does anyone else have another solution that we can use?

hadilnc01
  • 25
  • 4

1 Answers1

0

I never used the adwords apps script service but I see it works with iterators so in apps script we are used to use that with Drive service. What I would do, based on this example script :

var accountSelector = AdsManagerApp
     .accounts()
     .withCondition("Impressions > 100")
     .forDateRange("LAST_MONTH")
     .orderBy("Clicks DESC");

 var accountIterator = accountSelector.get();
 while (accountIterator.hasNext()) {
   var account = accountIterator.next();
 }

What you can do :

  • You create a json object where you will store the account id treated.
  • You store this json in a script property, you have to use json.stringify in order to save the json as text in theproperty.
  • You use trigger to restart program before it goes over time limit.

Idea is :

  1. You start the program
  2. you initiate the json by getting the property, if empty create blank json
  3. you initiate account selector
  4. you start the while(), inside you test first before to get data if the account is already treated, i.e. have an entry in the json.
  5. If not you get the data and once done you add an entry in the json
  6. I recommend to do that for 10 account for example and not waiting time overdue
  7. When 10 accounts are treated you go out the while (break;) to push the json in the script property
  8. Last, you create a trigger to rerun the function after 90 seconds.

    ScriptApp.newTrigger("myFunction") .timeBased() .after(90 * 1000) .create();

Don't forget to delete triggers before to create a new one

Don't forget when you finish iterator to stop everything and reset property for newt run.

Stéphane

St3ph
  • 2,232
  • 17
  • 17
  • Hi @St3ph, thank you for your suggestion. I'll give it a go and let you know if it works! – hadilnc01 Sep 04 '19 at 06:58
  • Hello Stephane, unfortunately your idea doesn't work because both "ScriptApp" and "PropertiesService" are not available for AdWords scripts. https://stackoverflow.com/questions/47291439/referenceerror-propertiesservice-is-not-defined – hadilnc01 Sep 04 '19 at 07:53
  • The google ad manager api can be called with apps script using urlfetch in apps script, doc reference https://developers.google.com/ad-manager/api/rel_notes, you will have to manage request by yourself but you will be able to use the program with apps script features. – St3ph Sep 04 '19 at 13:43
  • Hi @St3ph, what does Ad Manager have to do with our scenario? We're dealing with AdWords scripts and AdWords data. – hadilnc01 Sep 04 '19 at 14:11
  • Sorry wrong typing in google, the adwords API can be reached using urlfetch with apps script so it is the same idea. – St3ph Sep 04 '19 at 14:37