Ads Script can't find shopping campaigns

458 views
Skip to first unread message

Petra Manos

unread,
Aug 13, 2020, 3:01:39 AM8/13/20
to Google Ads Scripts Forum

Hey guys, I'm trying to write an ad script for a shopping campaign, but my iterator cannot find any shopping campaigns.

I've tried this way:

var campaignIterator = AdsApp.shoppingCampaigns()
    .withCondition("CampaignName = '" + campaignName + "'")
    .get();

  Logger.log(campaignIterator.hasNext());
 
while (campaignIterator.hasNext()) {
  var campaign = campaignIterator.next();
  Logger.log(campaign.getId());

}

and this way:

var campaignIterator = AdsApp.shoppingCampaigns().get();

  Logger.log(campaignIterator.hasNext());
 
while (campaignIterator.hasNext()) {
  var campaign = campaignIterator.next();
  Logger.log(campaign.getId());

}

and this way:

  var campaign1 = AdsApp.shoppingCampaigns()
    .withIds([9445672520])
    .get().next();


and I just keep getting 'false' for campaignIterator.hasNext(). The third block throws an error Cannot retrieve the next object: iterator has reached the end.

I have three shopping campaigns, so for the life of me I don't understand why it wouldn't find a shopping campaign.

Today is my first day using Google Ads scripts, but I am an experienced javascript developer.

Please help!

Petra Manos

unread,
Aug 13, 2020, 3:20:29 AM8/13/20
to Google Ads Scripts Forum
I ran it again today after my assistant removed and re-created one of the campaigns yesterday. This time my script got one result out of the two campaigns (the one that had been re-created), but the old campaign still doesn't get found by the script.

Campaigns_Life_of_Colour_Google_Ads(1).png

Life_of_Colour_Google_Ads.png

The old campaign called "Campaign for 123935" is a Smart Campaign. Would that have anything to do with it?

If so, how can we work with Smart campaigns?

Sigurd

unread,
Aug 13, 2020, 3:56:07 AM8/13/20
to Google Ads Scripts Forum
Hi Petra,

I'd guess your missing campaigns are smart shopping campaigns rather than standard.

function main() { 
  var campaignIterator = AdsApp.shoppingCampaigns().get(); // only fetches standard shopping campaigns i.e. no smart shopping
while (campaignIterator.hasNext()) {
  var campaign = campaignIterator.next();
  Logger.log(campaign.getName() + ', ' + campaign.getId()); 
}

Petra Manos

unread,
Aug 13, 2020, 4:19:49 AM8/13/20
to Google Ads Scripts Forum
Thanks! So how do I fetch a smart campaign then?

Google Ads Scripts Forum Advisor

unread,
Aug 13, 2020, 4:49:11 AM8/13/20
to adwords...@googlegroups.com
Hi Petra,

Thank you for raising your concern.

I am afraid that the smart campaign is currently not supported and there is no way to retrieve or manage it using Google Ads scripts. However, I already raised a feature request to my team but there is no guarantee that this type of campaign will be supported soon.

For the meantime, you may follow our blog as we will post there any relevant updates about Smart campaign.

Let me know also if you have further questions.

Regards,
Ejay
Google Ads Scripts Team

ref:_00D1U1174p._5004Q23JrqV:ref

Sigurd

unread,
Aug 13, 2020, 4:55:44 AM8/13/20
to Google Ads Scripts Forum
Working with smart shopping is not straightforward .. it's something of a misnomer

If you only need stats you can do calculations by comparing the account performance report with other reports. Not exactly ideal ..

Something like this approach perhaps

var report = AdsApp.report(
    'SELECT ' +
    'Cost, ConversionValue ' +
    'FROM ACCOUNT_PERFORMANCE_REPORT ' + // all reports https://developers.google.com/adwords/api/docs/appendix/reports
    'DURING LAST_7_DAYS'
  )
   var rows = report.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    Logger.log('Account cost ' + row['Cost'] + ', Rev: ' + row['ConversionValue'] + '\n*\n'); // includes unsupported campaign types
  }
  var CampReport = AdsApp.report(
    'SELECT ' +
    'Cost, ConversionValue, CampaignName, CampaignId ' +
    'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
    'DURING LAST_7_DAYS'
  )
   var rows = CampReport.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    Logger.log(row['CampaignName']+' id: '+row['CampaignId']+', cost '+row['Cost']+', rev: '+row['ConversionValue']);
  }


Petra Manos

unread,
Aug 13, 2020, 7:35:30 PM8/13/20
to Google Ads Scripts Forum
Oh, bummer. :-(

Actually I'm not fond of smart shopping campaigns but a new client has one that is performing well, so I wanted to write a script that would pause it and enable a manual one and vice versa to alternate between the two campaigns to see if the manual one has the same performance as the smart one before I turn it off. I believe I can do similar to what I intended with schedules, but it is a shame that I am unable to do basic campaign control with a script. It makes working with smart campaigns even more of a drawback.

Google Ads Scripts Forum Advisor

unread,
Aug 13, 2020, 10:07:24 PM8/13/20
to adwords...@googlegroups.com

Hi Petra,

As an alternative, you may check with the API team if the said campaign type is supported or can be managed by using AdWords API and Google Ads API by posting to this forum. I wouldn't be able to provide suggestion about the API's as this is out of my expertise.



Regards,
Ejay
Google Ads Scripts Team



ref:_00D1U1174p._5004Q23JrqV:ref

Avkeren

unread,
Jun 1, 2021, 7:38:29 AM6/1/21
to Google Ads Scripts Forum

Hi,
I see this is an old post but if someone else needs a solution....
a workaround that can help is to label (manually) the smart campaign you want to work on. Then instead of reaching out to the campaign, you can reach out to the campaigns attached to the label.

Petra Manos

unread,
Jun 1, 2021, 9:25:35 PM6/1/21
to Google Ads Scripts Forum
Clever!!

Google Ads Scripts Forum Advisor

unread,
Jun 2, 2021, 12:02:26 AM6/2/21
to adwords...@googlegroups.com
Hi All,

Harry here, from the Google Scripts Team. I would just like to remind everyone that although Avkeren's workaround is fantastic, kindly take that the concern in this thread is for Smart Shopping campaigns not being supported in Google Ads Scripts currently; hence, it did not reflect when Petra tried to retrieve them using the ShoppingCampaignSelector. In addition, the Label entity can only retrieve Search and Display Campaigns.

@Avkeren: Thank you for contributing to our community.

If there's anything else our team can assist you with, please let us know in a new thread.

Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q23JrqV:ref
Message has been deleted

Avkeren

unread,
Jun 2, 2021, 12:38:34 AM6/2/21
to Google Ads Scripts Forum
Hi All,

I may be missing something but if not, What I was able to do was to use the label and get all of the data I needed of all shopping campaigns including the Smart Shopping Campaigns when running the CAMPAIGN_PERFORMANCE_REPORT 

Google Ads Scripts Forum Advisor

unread,
Jun 2, 2021, 4:56:05 AM6/2/21
to adwords...@googlegroups.com
Hi Avkeren,

Thanks for pointing that out. Yes, I can confirm that Smart Shopping Campaigns data can be retrieved through the Campaign Performance Report via Google Ads Scripts. However, reports will only let you retrieve metrics and data, but reports will not return the actual script entity that you can manage based on a specific requirement (Eg. change status, manage bidding and others). Reports will not fully behave as Selectors.

Hope this clarifies things.

Avkeren Cohen

unread,
Jun 2, 2021, 6:43:53 AM6/2/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Hi Harry,

Yes, this clarifies things. :-)

Thanks and have a great day....

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/IBDQc_Yh5Xw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/7oHDl000000000000000000000000000000000000000000000QU2GTD00jxKIhN8_Rs6fNy6JOW7s8A%40sfdc.net.
Reply all
Reply to author
Forward
0 new messages