Error when using 'CONTAINS'

21 views
Skip to first unread message

Sara Cabezudo Vazquez

unread,
Jun 20, 2024, 7:40:49 AM (13 days ago) Jun 20
to Google Ads Scripts Forum
i want to restrict my ads script to campaigns containing the word "Festool", this is the part of the code I'm using for it: 

// Filter for campaigns containing "Festool" in the name
  let BrandFilter = ' CONTAINS(campaign.name, "Festool")';

// build queries                    
  let cd = [segDate, campName, cost, conv, value, views, cpv, impr, clicks, chType] // campaign by day
  let campQuery = 'SELECT ' + cd.join(',') + 
  ' FROM campaign ' +
  ' WHERE ' + date07 + BrandFilter + order;

unfortunately I get this error when I run the query: 

20/06/2024 12:25:33

Ca: QueryError.UNEXPECTED_INPUT: Error in query: unexpected input CONTAINS. at runReport (Code:144:10) at main (Code:128:3)



can you please help me find out why do i get that error? why google does not id CONTAINS??

Thanks in advance

  

Google Ads Scripts Forum

unread,
Jun 21, 2024, 8:28:05 AM (12 days ago) Jun 21
to Google Ads Scripts Forum

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

I would like to inform you that to retrieve a campaign containing Festool, you can use “withCondition("campaign.name REGEXP_MATCH '.*Festool.*'")”. Given below is a sample code to retrieve search type campaigns based on the above condition.

function main(){

  var campaignSelector = AdsApp

var campaignSelector = AdsApp.campaigns().withCondition("campaign.name REGEXP_MATCH '.*Festool.*'");

var campaignIterator = campaignSelector.get();

while (campaignIterator.hasNext()) {

  var campaign = campaignIterator.next();

 } 

}

To retrieve PMax type of campaigns, you can use “AdsApp.performanceMaxCampaigns()” instead of “AdsApp().campaigns()”. I would recommend that you follow the “AdsApp.​PerformanceMaxCampaignSelector”, “AdsApp.​ShoppingCampaignSelector”, “AdsApp.​VideoCampaignSelector”, and “AdsApp.​CampaignSelector” for more information.

I hope this helps! If the issue still persists, kindly reach out to us with the below details.

  • Google Ads account ID/CID
  • Name of the affected script
  • Shareable spreadsheet link if you are using in your script

You can share the requested details via Reply privately to the author option or a direct private reply to this email.

Thanks,
Google Ads Scripts team

Reply all
Reply to author
Forward
0 new messages