InputError: Unrecognized function name "main"

204 views
Skip to first unread message

Jay Wilner

unread,
Jul 24, 2022, 6:32:07 PM7/24/22
to Google Ads Scripts Forum
Beginner here. Wondering what this error means: InputError: Unrecognized function name "main".  Just trying to run this example script: https://developers.google.com/google-ads/scripts/docs/examples/reports?hl=en#create-a-text-report

I am assuming this script is somehow calling a function named "main"? I just cut and pasted the code provided.

thanks in advance!

Google Ads Scripts Forum Advisor

unread,
Jul 25, 2022, 12:43:08 AM7/25/22
to adwords...@googlegroups.com

Hello Jay,

I’m James from the Google Ads scripts support team. Thank you for reaching out to us.

Can you please provide us with the following details below so that we can check your issue?

  • Google Ads account ID / CID
  • Name of the script that encountered the said error


Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2d0v74:ref

Jay Wilner

unread,
Jul 25, 2022, 10:06:42 AM7/25/22
to Google Ads Scripts Forum on behalf of adsscripts
Hi James,

Thanks for quick reply.  see below.

Jay Wilner

"Digital Marketing for E-Commerce"
1712 Main St, Suite 200, PMB #6
Kansas City, Missouri 64108




On Sun, Jul 24, 2022 at 11:43 PM Google Ads Scripts Forum on behalf of adsscripts <adwords...@googlegroups.com> wrote:

Hello Jay,

I’m James from the Google Ads scripts support team. Thank you for reaching out to us.

Can you please provide us with the following details below so that we can check your issue?

  • Google Ads account ID / CID: 781-438-3043
  • Name of the script that encountered the said error: "create text report"


Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2d0v74:ref

--
-- 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/YG3-X6hK8kI/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/iHLCg000000000000000000000000000000000000000000000RFK7RP00oQpGep37QCGisHZnwNc4lw%40sfdc.net.

Google Ads Scripts Forum Advisor

unread,
Jul 26, 2022, 3:09:39 AM7/26/22
to adwords...@googlegroups.com

Hello Jay,

Thank you for providing the requested information. I checked your script and I observed that you’re not utilizing the function main() which is the main reason why you encountered the said error. Having said that, I made some adjustments to your script below for it to work on your end.

function main() {
  const searchResults = AdsApp.search(
      'SELECT campaign.name, metrics.clicks, metrics.impressions, metrics.cost_micros ' +
      'FROM   campaign ' +
      'WHERE  metrics.impressions < 10 ' +
      ' AND   segments.date DURING LAST_30_DAYS');

  for (const row of searchResults) {
    const campaignName = row.campaign.name;
    const clicks = row.metrics.clicks;
    const impressions = row.metrics.impressions;
    const cost = row.metrics.cost;
    console.log(`${campaignName}, ${clicks}, ${impressions}, ${cost}`);
  }
}

Can you please try to implement the given code above and let me know how it goes on your end?

Regards,

Nils Rooijmans

unread,
Jul 26, 2022, 3:17:58 AM7/26/22
to Google Ads Scripts Forum
Hi Jay,

most probably you have copy-pasted the code from the example you mentioned in the Google Ads scripts editor, and removed the initial main() function that is required.
The main() function is the function that gets executed first when a script is run.

You can fix this by adding the following at the top of your script:

function main() {
  runReport();
}

This will call the runReport function from within the main function.

More info to help you get started -->

Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Google Ads Scripts Forum Advisor

unread,
Jul 26, 2022, 4:04:32 AM7/26/22
to adwords...@googlegroups.com

Hello Nils,

Thank you for sharing your insights here. We appreciate it.

@Jay - you may also try the given approach by Nils. It is an alternative way to execute your scripts successfully.

If you have any questions, please let us know. We’re here to assist you.

Regards,

Jay Wilner

unread,
Aug 4, 2022, 9:56:53 AM8/4/22
to Google Ads Scripts Forum
Thank you. Those suggestions got me started. Appreciate you all pitching in to get me going. 
Reply all
Reply to author
Forward
0 new messages