How can I match a kw-id from ads-api report to ads-script object

159 views
Skip to first unread message

Elad Ben-David

unread,
Oct 22, 2020, 3:10:48 PM10/22/20
to adwords...@googlegroups.com

Hey

Using ads-script: 
I want to get all "kw ids" that are associated with a given (input) label.
I used this attribute KW id from apps-script object.

Then I want to get the impressions of these keywords for the last month segmented by days.
So I used this KW id from reports.

However, running my code I see the ids don't match.
Do you have an idea of a simple way to achieve this?

TIA



Filling a map {kw_id --> date, daily_impr}


    var report = AdsApp.report(
        "SELECT Date, Id ,Impressions " +
        "FROM   KEYWORDS_PERFORMANCE_REPORT " +
        "DURING LAST_30_DAYS");

    const KW_ID_TO_DAILY_IMPR = {};
    const rows = report.rows();
    while (rows.hasNext()) {
        var row = rows.next();

        const id = row["Id"];
        Logger.log("id "+ id);

        if (KW_ID_TO_DAILY_IMPR[id] === null) {
            KW_ID_TO_DAILY_IMPR[id] = {};
        };

        KW_ID_TO_DAILY_IMPR[id] = {
            date: row["Date"],
            impressions: row["Impressions"]
        };
    };
  Logger.log("KW_ID_TO_DAILY_IMPR "+ KW_ID_TO_DAILY_IMPR);

 

Filling a map {kw_text --> id, list_of_labels }


var labelIterator = AdsApp.labels()
        .withCondition('Name = "Corona"') //input
        .get();
    if (labelIterator.hasNext()) {
        var label = labelIterator.next();

        Logger.log('Label name: ' + label.getName());
        var kwIterator = label.keywords().get();
        while (kwIterator.hasNext()) {
            var k = kwIterator.next();
            if (KW_TO_DATA[k.getText()] == null) {
                KW_TO_DATA[k.getText()] = {
                    id: k.getId(),
                    labels: []
                };
            }
KW_TO_DATA[k.getText()].labels.push(label.getName());

Sigurd Fabrin

unread,
Oct 23, 2020, 3:10:48 AM10/23/20
to Google Ads Scripts Forum
Perhaps you can use the IN operator in reports to select only what is relevant from it

Something like:

    'WHERE LabelIds IN ["' + arrayOfIds.join('","')  + '"]  '


 sigurd

Google Ads Scripts Forum Advisor

unread,
Oct 23, 2020, 3:54:30 AM10/23/20
to adwords...@googlegroups.com

Hi Everyone,

Thank you for reaching out to us.

When checking for keywords, please note that keyword IDs may be shared across ad groups. To uniquely identify a keyword, you must specify both its adgroup and the keyword ID. You may refer to this detailed explanation for more details.

As for the script on Filling a map {kw_id --> date, daily_impr}, please change this line (const id = row["Id"];). The id should be var instead of const. Otherwise, you'll only be referencing a single ID value.

Regards,

Google Logo
Mark Kevin Albios
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q26BQMc:ref

Elad Ben-David

unread,
Oct 23, 2020, 7:35:55 AM10/23/20
to adwords...@googlegroups.com
Tried to rephrase my question:

Hi,

I'm trying to write an ads-script that does as follows:
input: a keyword label. 
output: The last 14 daily impressions for a search keyword of that label. 

My try (code below):
For each relevant keyword I ran keyword::getId()
I have tried to match it with the column["Id"] of kw_performance report (Display Name Keyword ID).

However, debugging shows column["Id"] is always the same (879505933136) and is different from any keyword::getId()

How would you suggest to do this otherwise?

TIA,


My try:

EladB

unread,
Oct 23, 2020, 8:42:02 AM10/23/20
to Google Ads Scripts Forum
Thanks, a good comment.

EladB

unread,
Oct 23, 2020, 9:01:35 AM10/23/20
to Google Ads Scripts Forum
Why does my script never get to the "id" log?


On Friday, October 23, 2020 at 10:10:48 AM UTC+3 Sigurd Fabrin wrote:

EladB

unread,
Oct 23, 2020, 9:24:53 AM10/23/20
to Google Ads Scripts Forum
Thanks, "var" solved the first part.
I thought there would be a runtime error if const is re-defined. no?

Regarding the unique-id, thanks for the clarification.
From the screenshot attached, it seems "id" in both results are of 6 digits. So just need to compare, as is. Correct?



EladB

unread,
Oct 23, 2020, 9:43:31 AM10/23/20
to Google Ads Scripts Forum
A follow-up question.
I'm trying to filter the report only to some label-Ids.

But I never get even to the first log:




function getLabelsByName() {
  const labelsIds = [];
  var label;
    var labelIterator = AdsApp.labels()
        .withCondition('Name = "Corona"') //input
        .get();
    if (labelIterator.hasNext()) {
        var label = labelIterator.next();
      labelsIds.push(label.getId());
    }      
  
    
  Logger.log("labelsIds "+labelsIds);
  const q = "SELECT Date, Id ,Impressions " +
        "FROM   KEYWORDS_PERFORMANCE_REPORT " +
      "WHERE LabelIds IN ['"+ labelsIds.join('","')  + "'] "+
        "DURING LAST_7_DAYS";
  Logger.log (q);
    var report = AdsApp.report(q);

  Logger.log("report is done "+report);

Sigurd Fabrin

unread,
Oct 23, 2020, 10:04:15 AM10/23/20
to Google Ads Scripts Forum
Consider declaring your variable like this:

var labelsIds = [];

.. and outside your function to get global scope

See https://www.w3schools.com/js/js_const.asp reg. diff between let, const and var


 sigurd

Elad Ben-David

unread,
Oct 23, 2020, 11:43:24 AM10/23/20
to Sigurd Fabrin via Google Ads Scripts Forum, Google Ads Scripts Forum
Thanks, but the array is const. No? It's content is mutable.

I have tried that, and still the report doesn't finish.

image.png

image.png

--
-- 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/TqxVrXY98rc/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/d8e3b468-e244-4f82-a228-9799e41c8d80o%40googlegroups.com.
Message has been deleted

Sigurd Fabrin

unread,
Oct 23, 2020, 2:43:08 PM10/23/20
to Google Ads Scripts Forum
Sorry, you cannot use IN or NOT_IN with labelIds, just remembered. Use CONTAINS_ALL or CONTAINS_NONE instead.

Perhaps you can use this short script for inspiration. It will export data for keywords with a specified label to a google spreadsheet


var settings = {
  
  url: 'https://docs.google.com/spreadsheets/rest-of-url', // export data to this spreadhseet
  sheet: 'SheetName',
  label:'test', // only fetch keywords with this label
  report: 'KEYWORDS_PERFORMANCE_REPORT',
  daysAgo: 14, // start date will be this number of days before yesterday. End date will be yesterday
  
}

function main() {
  doStuff();
}
function doStuff() {  
  var timePeriod = dates();
  var labelIter = AdsApp.labels()
  .withCondition('Name = '+ settings.label)
  .get();
  if (labelIter.totalNumEntities() === 1) {
    var labelId = labelIter.next().getId();
  }
  else {Logger.log('Found: '+labelIter.totalNumEntities()+' labels. Expected 1')}

  var report = AdsApp.report(
    'SELECT ' +
    'Date,AdGroupId,AdGroupName,Id,Criteria,LabelIds,Labels,Impressions ' +
    'FROM ' + settings.report.toUpperCase() + ' ' +
    'WHERE ' +
    'LabelIds CONTAINS_ALL ["' + labelId + '"] ' + // use CONTAINS_ALL/CONTAINS_ANY with LabelIds. IN/NOT_IN doesn't work
    'DURING ' + timePeriod
  );
 var ss = SpreadsheetApp.openByUrl(settings.url);
 var sheet = ss.getSheetByName(settings.sheet);
   report.exportToSheet(sheet);
Logger.log('All done!\n\n..data for these dates '+timePeriod+' exported to this spreadsheet:\n\n'+settings.url); 
}
function dates() {
var timeZone = AdsApp.currentAccount().getTimeZone();
  var today = new Date();
  var oneDay = 1000*60*60*24;
  var yesterday = new Date(today-oneDay); 
  var xDays = oneDay * settings.daysAgo; 
  var xDaysAgo = new Date(yesterday-xDays);
  var dateFormat = 'yyyyMMdd';
  var startDate = Utilities.formatDate(xDaysAgo,timeZone,dateFormat);
  var endDate = Utilities.formatDate(yesterday,timeZone,dateFormat);
  return startDate + ',' + endDate
}


 sigurd


On Friday, October 23, 2020 at 5:43:24 PM UTC+2, EladB wrote:
Thanks, but the array is const. No? It's content is mutable.

I have tried that, and still the report doesn't finish.

image.png

image.png

To unsubscribe from this group and all its topics, send an email to adwords...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Oct 25, 2020, 11:46:44 PM10/25/20
to adwords...@googlegroups.com

Hi Elad,

Thanks for getting back to us.

With regard to this inquiry ("From the screenshot attached, it seems "id" in both results are of 6 digits. So just need to compare, as is. Correct?"), yes, you just need to compare those IDs together with their respective AdGroup ID to get the actual keyword (as stated on my previous response on the uniqueness of the keyword). As for your other questions, I do agree with Sigurd's answers on those. You can also refer to the sample script shared by Sigurd. I've also checked that script on my end.

Feel free to let us know if you have further questions/concerns.

@Sigurd - thanks for sharing with us your sample script.

Regards,

Elad Ben-David

unread,
Apr 26, 2021, 6:59:30 PM4/26/21
to Google Ads Scripts Forum, scripty-users, Alexander Wang, Mark Kevin Albios

Hi all,


I have this code:

var videoAds = AdsApp .videoAds() .withCondition('????') .get();


I'm not sure what to put in the withCondition to get all such only beaconsless videoAds.

I have seen this doc, but wasn't sure what where clause could fit.


Thanks

Google Ads Scripts Forum Advisor

unread,
Apr 26, 2021, 11:31:28 PM4/26/21
to adwords...@googlegroups.com
Hi,

Harry here from the Google Ads Scripts. Since your question is not related to this thread, let us instead continue our conversation in the new thread you have posted and also for better tracking of issues on our end.

Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2GHmrT:ref

Elad Ben-David

unread,
Apr 27, 2021, 5:06:24 PM4/27/21
to Trevor Murphy, Google Ads Scripts Forum, Alexander Wang, Mark Kevin Albios
Thanks for the reply.

Please look at profileId = 4232167
I'm not too familiar with the CM360, but this profile should have a videoAd with a beacon tracking enabled.

On Tue, Apr 27, 2021 at 10:36 PM Trevor Murphy <trevor...@google.com> wrote:
Hey, Elad.  I'm still digging, but I don't think we expose beacon tracking information in the Ads UI or in the Scripts product.  It would help me investigate if you could provide an account with an ad with beacon tracking enabled, so I can look them up in ICS.

As a short-term workaround, if the client knows which ads do / do not have beacon tracking, then they could write the condition as something like `Id IN [...]` or `Id NOT IN [...]`

Elad Ben-David

unread,
May 12, 2021, 7:17:35 PM5/12/21
to Google Ads Scripts Forum, scripty-users, Alexander Wang, Mark Kevin Albios
Hello esteemed, 

Given a campaign object, I want to get its CPA bidding price.
I don't see any API to do so, is there any?

Thanks
Message has been deleted

Google Ads Scripts Forum Advisor

unread,
May 13, 2021, 11:41:37 PM5/13/21
to adwords...@googlegroups.com
Hello EladB,

Thanks for reaching out. I am Harry from the Google Ads Scripts Team. Allow me to assist you on this.

I would like to inform you that tCPAs or Target cost per acquisition (CPA) at the Campaign level is currently not supported in the Google Ads Scripts. You may only manage BiddingStategies at this entity level. Please see also CampaignBidding and Bidding - Strategy types for your reference. On the other hand, may retrieve CPAs at the AdGroup level by using the getCpa() method. A request to retrieve CPAs for campaigns has already been filed in the past so allow me to make a follow up on your behalf. However, there is no guarantee if this will be supported soon in the Google Ads Scripts. Please follow our blog for updates and new releases in the meantime.

On the other hand, if you would be interested in using the Google Ads API, you may check out the provided solution by Andrew. Please note that our team can only provide assistance with regard to the Google Ads Scripts so if you would need further assistance in this regard, it would be best if you reach out to the Google Ads API forum channel through this link.

@Andrew: Thanks for contributing to the Google Ads Scripts community. Much appreciated.

Let me know if you have further questions on this.


Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2HAW1b:ref
Message has been deleted

Google Ads Scripts Forum Advisor

unread,
May 25, 2021, 9:20:55 PM5/25/21
to adwords...@googlegroups.com
Hello,

I have followed the syntax from this [doc]

    withCondition("ColumnName IN [Value1, Value2]")



But I get an error when running this piece of code:


      var adGroups = AdsApp
        .adGroups()
        .withCondition(agName)
        .withCondition(campName)
        .get();


Error:


    5/25/2021 9:32:53 PM CampaignName CONTAINS_ALL ['test', 'play']
    5/25/2021 9:32:54 PM Invalid or inapplicable operator is used for field CampaignName. Please check the supported operators. (file Code.gs, line 52)

=========================================

Hello,

Thanks for reaching out. I have scrubbed your post as it contains internal sensitive links. Kindly take note of this when posting on public forums.

On the other hand, the CONTAINS_ALL operator is used for StringSet columns (e.g. LabelNames). The CampaignName or Name are of type String so you would need to use either the IN operator or a chained CONTAINS condition.

Let me know if there's anything else I can assist you with.


Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2HxrJT:ref

Elad Ben-David

unread,
May 25, 2021, 9:36:51 PM5/25/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Thanks

just to verify:
IN means (any of the items in the list)
CONTAINS means (all of the items in the list)

?

Regards,


--
-- 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/TqxVrXY98rc/unsubscribe.

Google Ads Scripts Forum Advisor

unread,
May 26, 2021, 2:44:16 AM5/26/21
to adwords...@googlegroups.com
Hello,

The IN operator is simply a shorthand for multiple OR conditions while the CONTAINS operator will behave like the includes method. On the other hand, I would appreciate it if you can open up a new thread instead for topics that are unrelated to existing threads like this for better tracking of issues on our end.

Elad Ben-David

unread,
Jul 5, 2021, 2:02:51 PM7/5/21
to Google Ads Scripts Forum, scripty-users, Alexander Wang, Mark Kevin Albios
Hi all,


I try to run this query in Ads-script, but I get an empty result set.

    var query = "SELECT conversion_action.firebase_settings.event_name, conversion_action.status, conversion_action.resource_name FROM conversion_action";
    var report = AdWordsApp.report(query, {apiVersion: reportVersion});


I cannot add `DURING` last 30 days:
DURING is disallowed in service calls. It is required in report downloads if the SELECT clause of your request includes the Date or Week column.

When there is no date range in the query, how back in time does it go? How can I extend the date range to get data?

Thanks!

Google Ads Scripts Forum Advisor

unread,
Jul 6, 2021, 2:25:26 AM7/6/21
to adwords...@googlegroups.com, script...@google.com, markk...@google.com, alex...@google.com
Hi Elad,

Thanks for reaching out. Harry here, from the Google Ads Scripts Team.

It is to my knowledge that if queries are not filtered by date, then they should return all time data; however, as you would already know, date fields/segment for the conversion_action is not supported. If you would like, I can file a feature request for you so kindly confirm and provide a use case.

On the other hand, if you would need further assistance with debugging your script regarding the empty results, please provide the CID and script name where the issue was encountered so I can take a closer look. You may send them here or privately via the reply to author option. Note that you may need to join the Google Group for you to use this option.
 
If this option is not available at your end still, you may send it through our email (googleadsscr...@google.com) instead.

Let me know your thoughts.


Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2JYm9b:ref

Elad Ben-David

unread,
Jul 13, 2021, 1:04:55 PM7/13/21
to Google Ads Scripts Forum, scripty-users, Alexander Wang, Mark Kevin Albios
Hi esteemed,

Google documentation says:
Auction insights are updated a few times a day.

Talking to a few ACs I understand it's more complex. Data about competitors in different time zones is really if we ask for data older than 24hrs.

1) Is there any external API that gives competitors'?
2) Is there any external way to fetch competitor's data newer than 24hrs?
3) Is there any external way to calculate how a client should raise their bidding in order to be absolut top for its brand?

Thanks

EladB

unread,
Jul 13, 2021, 2:27:52 PM7/13/21
to Google Ads Scripts Forum
Hi Harry,

Send you in private. Did you get it?
Does your team hold office hours?

Elad

Google Ads Scripts Forum Advisor

unread,
Jul 13, 2021, 11:31:24 PM7/13/21
to adwords...@googlegroups.com
Hi Elad,

We can only provide support through our support (email) and forum channels. Let me know if you have questions on my last post.

Google Ads Scripts Forum Advisor

unread,
Jul 13, 2021, 11:42:05 PM7/13/21
to adwords...@googlegroups.com
Hi Elad,

With regard to auction insights freshness, it would be best if you reach to out to the Google Ads Product Team instead through this link. They should be able to assist you further on that matter. Moreover, our team can only comment on Google Ads Scripts related concerns and would not be able to provide you insights on external APIs or means to your questions.


Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2KbviP:ref

Elad Ben-David

unread,
Jul 14, 2021, 4:56:27 AM7/14/21
to Google Ads Scripts Forum on behalf of adsscripts
Thanks, 

Have you received it?

--
-- 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/TqxVrXY98rc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Jul 15, 2021, 2:09:01 AM7/15/21
to adwords...@googlegroups.com, script...@google.com, alex...@google.com
Hi Elad,

This is to confirm that we've received your message privately. 

I checked your script, and I wasn't able to proceed with the investigation due to spreadsheet's access. Could you please provide the shareable link of the spreadsheet being used in the script? You may send them privately via the reply to author option. If the mentioned option is not available at your end still, you may send it through our email (googleadsscr...@google.com) instead.

Regards,
Google Logo
Teejay Wennie Pimentel
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2JYm9b:ref
Reply all
Reply to author
Forward
0 new messages