how to catch first page cpc into a variable

127 views
Skip to first unread message

Yaniv Lev-Ari

unread,
May 31, 2022, 7:05:49 AM5/31/22
to Google Ads Scripts Forum
I am trying to create a script which raise the bid of low impression share keywords,

and on of the parameters I want to check is that its bid is higher then the first page estimate

this is my script

var keywords =  AdsApp.keywords()
      .withCondition(`ad_group_criterion.status = ENABLED`)
      .withCondition("campaign.status = ENABLED")
      .withCondition(
          `metrics.search_impression_share < ${TARGET_IMPRESSION_SHARE - TOLERANCE}`)
      .withCondition("ad_group_criterion.position_estimates.first_page_cpc_micros > 0")

      .orderBy(`metrics.search_impression_share ASC`)
      .forDateRange("YESTERDAY")
      .get().next();
 
  var stats = keywords.getStatsFor("YESTERDAY");
 
  for (const keyword of keywordsToRaise) {
   
    const name = keyword.getText();
   
    //Logger.log(keyword);
       
    const curr_cpc= keyword.bidding().getCpc();
   
    const top_page_est = keyword.adGroupCriterion.first_page_cpc_micros;



but it seems this is not the way to set the first_page_cpc_micros into a variable, 
than.. how should it be done? 

Sigurd Fabrin

unread,
May 31, 2022, 9:35:12 AM5/31/22
to Google Ads Scripts Forum
 .getFirstPageCpc() should do it

smth like this:
function main() {
  const kwIter = AdsApp.keywords().withLimit(10).get();
  while (kwIter.hasNext()) {
    const keyword = kwIter.next();
    console.log(keyword.getText()+': 1st page: '+keyword.getFirstPageCpc()+', top: '+keyword.getTopOfPageCpc());
  }
}


Sigurd

Yaniv Lev-Ari

unread,
May 31, 2022, 9:45:29 AM5/31/22
to Sigurd Fabrin via Google Ads Scripts Forum
great, thanks

שיהיה בכיף,

יניב לב ארי



‫בתאריך יום ג׳, 31 במאי 2022 ב-16:35 מאת ‪Sigurd Fabrin via Google Ads Scripts Forum‬‏ <‪adwords...@googlegroups.com‬‏>:‬
--
-- 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/eWQ3divwBAU/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/87b4346a-3997-44b6-a2bd-ae02a729a470n%40googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Jun 1, 2022, 5:17:51 AM6/1/22
to adwords...@googlegroups.com

Hello Yaniv,

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

Please excuse us for the delay. I agree with the given solution by Sigurd and I confirm that’s the correct method to use. However, if you have any further questions or concerns, please let us know. We’re happy to assist you.

@Sigurd - Thank you for your continuous effort assisting other users. We appreciate it!

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2bFFoY:ref

2 Generations

unread,
Feb 17, 2023, 1:53:18 AM2/17/23
to Google Ads Scripts Forum
Hi Sigurd, 
Do you need to add the given script with any other script to make it work? I tried it in preview and return null for each keyword. 
Thank you 
Sujan

Google Ads Scripts Forum

unread,
Feb 17, 2023, 3:35:33 AM2/17/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/eWQ3divwBAU) from the forum as it wasn't routed to our support queue.

Regards,
Yasmin
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Feb 17, 2023, 5:13:32 AM2/17/23
to Google Ads Scripts Forum
Hi Sujan,

Please let us know in the event that you would require our assistance from our team so we're able to assist you accordingly. In the event that you do, kindly provide your Google Ads account ID as well as the name of the script so we could further check on our end.

Best regards,

Yasmin
Google Ads Scripts Team

Sigurd Fabrin

unread,
Feb 20, 2023, 8:11:25 AM2/20/23
to Google Ads Scripts Forum
"Do you need to add the given script with any other script to make it work? I tried it in preview and return null for each keyword."
No, it works out of the box. I'm guessing you don't have enough data in your account.


Sigurd
Reply all
Reply to author
Forward
0 new messages