Google Ads Script and Smart Campaigns

886 views
Skip to first unread message

Andrey R

unread,
Oct 14, 2019, 1:03:38 PM10/14/19
to Google Ads Scripts Forum
Hi there!

It seems Ads script doesn't return smart campaigns. Is there any workaround?

function main(){
 
  var account = AdsApp.currentAccount();
  var campaigns = AdsApp.campaigns().get();
  
  while (campaigns.hasNext()){
   
     Logger.log(campaigns.next().getName())
    }
}

Google Ads Scripts Forum Advisor

unread,
Oct 14, 2019, 3:59:37 PM10/14/19
to adwords-scripts+apn2wqfvj2ly29kg...@googlegroups.com, adwords-scripts+apn2wqfvj2ly29kg...@googlegroups.co, adwords...@googlegroups.com
Hi Andrey,

Scripts does not support Smart Campaigns at the moment. Please monitor this page to keep an eye on new features.

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UKNEK4:ref

Andrey R

unread,
Oct 16, 2019, 7:59:06 AM10/16/19
to Google Ads Scripts Forum
Hi,

Thanks for the response.

Could you please suggest a way to get Total costs for an account (including Smart Campaigns costs)?
Is that possible via AdWords API?

Cheers,
Andrey

Google Ads Scripts Forum Advisor

unread,
Oct 16, 2019, 3:50:10 PM10/16/19
to adwords-scripts+apn2wqfvj2ly29kg...@googlegroups.com, adwords-scripts+apn2wqfvj2ly29kg...@googlegroups.co, adwords...@googlegroups.com
Hi Andrey,

You should be able to use reports and obtain this information for smart campaigns through the API's Campaign Performance Report.

Christopher Larkin

unread,
Oct 16, 2019, 7:48:21 PM10/16/19
to Google Ads Scripts Forum
Hi - 

I had the same problem, and in order to work around this, I simple used a report as mentioned by Matt. 

I've provided a chunk of the code I use to do exactly that, and in this case I have a variable (groupPartialCampaigns.name) that contains a partial text match with the name of the campaign. 

Note that because values come back with commas, you'll need to strip them before using parsefloat. 

Hope it helps you !


        var queryText = "SELECT CampaignName, Clicks, Cost, Conversions, CostPerConversion " +
            "FROM CAMPAIGN_PERFORMANCE_REPORT " +
            "WHERE Cost > 0 and CampaignName CONTAINS '" + groupPartialCampaigns[i].name + "'" +
            " DURING " + dateRange + " ";

        var report = AdsApp.report(queryText);
        var rows = report.rows();
        while (rows.hasNext()) {

            var row = rows.next();
            rowClicks = row['Clicks'];
            rowClicks = rowClicks.replace(/,/g, '');
            rowCost = row['Cost'];
            rowCost = rowCost.replace(/,/g, '');
            rowConversions = row['Conversions'];
            rowConversions = rowConversions.replace(/,/g, '');
            rowCostPerConv = row['CostPerConversion'];
            rowCostPerConv = rowCostPerConv.replace(/,/g, '');
            clicks = clicks + parseFloat(rowClicks);
            cost = cost + parseFloat(rowCost);
            conversions += parseFloat(rowConversions);

            matchedCampaigns += 1;
        }

Christopher Larkin

unread,
Oct 16, 2019, 7:50:08 PM10/16/19
to Google Ads Scripts Forum
Oh - BTW - in my example, I have campaigns divided by cities and I wanted to total all campaigns with "chicago" in the name, for example. You could easily just remove the name part of the where clause. 

Good luck!
Christopher

Google Ads Scripts Forum Advisor

unread,
Oct 17, 2019, 2:20:43 PM10/17/19
to adwords-scripts+apn2wqefskufq04q...@googlegroups.com, adwords...@googlegroups.com
Hi Christopher,

Thanks for contributing to the thread! We appreciate it.

Dane Kuiper

unread,
Feb 19, 2020, 10:45:25 AM2/19/20
to Google Ads Scripts Forum
I'm having the same problem. I can't get cost data for smart campaigns within the google ads scripts. I tried your solution, but it doesn't return any smart campaigns either.
AdWordsApp.currentAccount().getStatsFor("THIS_MONTH").getCost();
results in exactly the same sum as what you suggested. Upon inspecting the data in more detail, only the non-smart campaigns are returned.

I'm not sure why and really stumped on this.

Has the API changed somehow since 4 months ago that would break this?


On Wednesday, October 16, 2019 at 6:48:21 PM UTC-5, Christopher Larkin wrote:

Andrey R

unread,
Feb 19, 2020, 11:53:41 AM2/19/20
to Google Ads Scripts Forum
Hi Dane,

Christopher gave a great hint, feel free to use it as a workaround.

Christopher Larkin

unread,
Feb 19, 2020, 1:03:38 PM2/19/20
to Google Ads Scripts Forum
It's not a standard solution so this is not supported by Google, but try using my code in the thread to build a query and test here: https://www.awql.me/adwords

Good luck! 

Google Ads Scripts Forum Advisor

unread,
Feb 19, 2020, 1:40:53 PM2/19/20
to adwords-scripts+apn2wqe9cozojgro...@googlegroups.com, adwords...@googlegroups.com
Hi Dane,

At the moment, Ads scripts does not support smart campaigns. I will forward this request for smart campaign support to our team.

Thanks,

Dane Kuiper

unread,
Feb 20, 2020, 1:54:31 PM2/20/20
to Google Ads Scripts Forum
Thanks Christopher,

here's the code I had put into my script
            var report = AdsApp.report(
      "SELECT Cost " +
      "FROM   ACCOUNT_PERFORMANCE_REPORT  " +
      "WHERE Cost > 0 " +
      "DURING THIS_MONTH");
    
    var rows = report.rows();
    while (rows.hasNext()) {
      var row = rows.next();
            Logger.log(row.formatForUpload());
      var query = row["Query"];
      var res = row["Cost"];

But, I am only getting data from non-smart campaigns. (One account returns 2200$, when actual spend is over 4000$, and another is 72$ when actual spend is 160$) I also tried pulling from the CAMPAIGN_PERFORMANCE_REPORT, but the results were identical.

I understand it's not supported, though I'm trying to find a way to make it work.

Thanks for your idea!

Dane Kuiper

unread,
Feb 20, 2020, 2:02:34 PM2/20/20
to Google Ads Scripts Forum
Matt,

Thanks. That would be most excellent. We have some angry clients right now.

The main goal here is, our system allows the clients to set their "max spend" per month. They can change this at any time during the month, depending on their changing circumstances.

My script simply checks the account's total spend, and pauses all campaigns if the account spend is over their max amount (pulled from our systems API).

But without access to smart campaigns, I can't get the full account cost. Even the ACCOUNT_PERFORMANCE_REPORT reports incorrect values. (as I summarized above my code) And even if I could get the correct cost, I can only pause the non-smart campaigns.

If you have any other ideas than waiting, please let me know,

Thanks,

Christopher Larkin

unread,
Feb 20, 2020, 3:05:31 PM2/20/20
to Google Ads Scripts Forum
I can imagine people are frustrated. Remember there are ToS that limit how end users can be exposed to our apps. 

No client should be allowed to set a max spend directly, and if you set the 1/30.4 factor for spend you won't have problems with overspending. That being said - I'll take a look at my version of the code I posted and confirm it still works then reply back here. 

:-) 

Google Ads Scripts Forum Advisor

unread,
Feb 20, 2020, 4:20:28 PM2/20/20
to adwords-scripts+apn2wqe9cozojgro...@googlegroups.com, adwords...@googlegroups.com
Hi Dane,

The request for smart campaign support directly in scripts has been relayed to our team.

You should be able to pull smart campaign data from the campaign performance report, and the account cost should be accurate for the account performance report. As a test to ensure you can pull smart campaigns via reports, you might try running this code and substitute a smart campaign's name where indicated:

  var report = AdsApp.report("SELECT CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT WHERE CampaignName = 'INSERT_CAMPAIGN_NAME' ").rows().next(); 
  Logger.log(report.formatForUpload());

Regards,

Mario Vasile

unread,
Mar 9, 2020, 5:02:16 PM3/9/20
to Google Ads Scripts Forum
I tried the same report for CAMPAIGN_PERFORMANCE_REPORT and it doesn't return the smart campaigns details. Is this enabled only for Dane? I would want to be able to retrieve as well the smart campaigns details through CAMPAIGN_PERFORMANCE_REPORT

Google Ads Scripts Forum Advisor

unread,
Mar 9, 2020, 11:42:49 PM3/9/20
to adwords-scripts+apn2wqfc87e5zk3o...@googlegroups.com, adwords...@googlegroups.com
Hi Mario,

My apologies for the inconvenience, however, Smart Campaigns are not supported in Google Ads Scripts at this moment. For now, you may keep an eye on our blog for updates or announcements.

Thanks,
Peter

Vanrajsinh Bihola

unread,
Sep 8, 2020, 1:20:05 AM9/8/20
to Google Ads Scripts Forum
Hello all,

You can use automated rules for now if you want to pause the campaign or enabled on specific amount of spend.

Thanks,
Vanrajsinh
Reply all
Reply to author
Forward
0 new messages