Issue: No. of sitelinks of Adgroups and Campaign

49 views
Skip to first unread message

Sewak Tamang

unread,
Mar 1, 2019, 4:21:12 AM3/1/19
to Google Ads Scripts Forum
Hello All,

I have script which gives Campaign name, Adgroup name  and No. of sitelink  of that Adgroup.

Issue:
But some of the adgroups show 0 no. of sitelinks however if i check there are around 5+ sitelinks.


The code is below : Is there any other way to get Campaign name its' corresponding adgroups and their number of sitelinks.

My following code work for both pause and active . It doesn't count deleted sitelinks.



function main() {
  cleardata();
  getSitelinksForCampaign();
}



function cleardata()
{
  var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
//var activesheet=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
spreadsheet.getRange("A4:C1000").clearContent();
  
}


function getSitelinksForCampaign() {
  var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var email = spreadsheet.getRange('B1').getValue();
 // var sheet1 = spreadsheet.getSheetByName('Report1');
  
  var i=spreadsheet.getLastRow();
  
  var campaignIterator = AdsApp.campaigns().get();
  
  Logger.log('Total count of campaign: ' + campaignIterator.totalNumEntities());
  
  while (campaignIterator.hasNext()) {
    
    var campaign = campaignIterator.next();
    Logger.log('campaign: ' + campaign.getName());
    
var adgroupIterator=campaign.adGroups().get();
while (adgroupIterator.hasNext()) {
var adgroup = adgroupIterator.next();
if (adgroupIterator.hasNext()) {
//var campaign = campaignIterator.next();
var sitelinksIterator = adgroup.extensions().sitelinks().get();
      
      while (sitelinksIterator.hasNext()) {
        var sitelink = sitelinksIterator.next();
      }
      
      spreadsheet.appendRow([campaign.getName(),adgroup.getName(),sitelinksIterator.totalNumEntities()])
      Logger.log('Total count of sitelinks: ' + sitelinksIterator.totalNumEntities());
    }
    }
  }
   MailApp.sendEmail(email, 'Subject : ' + AdsApp.currentAccount().getCustomerId() + ' Sitelink Report', '',
      {htmlBody: "Report created"});
}


googleadsscrip...@google.com

unread,
Mar 1, 2019, 5:32:46 AM3/1/19
to Google Ads Scripts Forum
Hi Sewak,

Upon checking the script that you provided, I noticed that you implemented if (adgroupIterator.hasNext()) { at line 39, however, it is unnecessary. Because of this reason, the script does not log all campaigns and adGroups, as well as the number of sitelinks under your account into your spreadsheet. With this, could you please try to remove the line 39 and line 50 (the closing parenthesis for the said condition) and try to test if you can still see the same issue?

Please let me know how it goes after trying the suggestion.

Regards,
Hiroyuki
Google Ads Scripts Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
-- 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 the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/50617597-1dcd-43cf-8db3-7cc55813fbe6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sewak Tamang

unread,
Mar 1, 2019, 8:08:13 AM3/1/19
to Google Ads Scripts Forum
Removed but same issue.

Do i need to send you my id and script name to check in real campaign?

googleadsscrip...@google.com

unread,
Mar 3, 2019, 10:39:11 PM3/3/19
to adwords...@googlegroups.com, Google Ads Scripts Forum
Hi Sewak,

I am a colleague of Hiroyuki and I will provide support to your concern.

Please refer to modified script below. Aside from the suggestion of my colleague, I also removed the iteration of the sitelinks as this part of the script is unnecessary because expected result of the script is to fetch only the campaign name, ad group name and the number of sitelinks that the ad group have. I tried to test the modified script on my test account and I wasn't able to encounter any issues/errors and it fetched all the sitelinks that my ad groups have. 

function main() {
  cleardata
();
  getSitelinksForCampaign
();
}

function cleardata()
{
var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';

  
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
//var activesheet=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
spreadsheet
.getRange("A4:C1000").clearContent();
  
}

function getSitelinksForCampaign() {

  
var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';

  
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  
var email = spreadsheet.getRange('B1').getValue();
 
// var sheet1 = spreadsheet.getSheetByName('Report1');
  
  
var i=spreadsheet.getLastRow();
  
  
var campaignIterator = AdsApp.campaigns().get();
  
Logger.log('Total count of campaign: ' + campaignIterator.totalNumEntities());
  
  
while (campaignIterator.hasNext()) {
    
var campaign = campaignIterator.next();
    
Logger.log('campaign: ' + campaign.getName());
    
 
var adgroupIterator=campaign.adGroups().get();
 
while (adgroupIterator.hasNext()) {
      
var adgroup = adgroupIterator.next();

      
var sitelinksIterator = adgroup.extensions().sitelinks().get();

      
      spreadsheet
.appendRow([campaign.getName(),adgroup.getName(),sitelinksIterator.totalNumEntities()])
      
Logger.log('Total count of sitelinks: ' + sitelinksIterator.totalNumEntities());
    
}
  
}
   
MailApp.sendEmail(email, 'Subject : ' + AdsApp.currentAccount().getCustomerId() + ' Sitelink Report', '',
      
{htmlBody: "Report created"});
}

With this, you may try to preview the modified script and observe if you will still encounter the issue. If the issue is still persisting, you may provide the CID and the name of the script via Reply privately to author so I can further investigate it. Also, could you provide a sample ad group that have sitelinks but returns 0 sitelink in the spreadsheet?

Regards,
Ejay
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Removed but same issue.

Do i need to send you my id and script name to check in real campaign?

--
-- 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 the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.
Message has been deleted

Sewak Tamang

unread,
Mar 14, 2019, 11:56:32 PM3/14/19
to Google Ads Scripts Forum

googleadsscrip...@google.com

unread,
Mar 15, 2019, 4:27:13 AM3/15/19
to adwords...@googlegroups.com, Google Ads Scripts Forum
Hi Sewak,

Could you confirm if you are still encountering the issue? I am asking this because your message is appearing as blank and I noticed that the code in the specific script that you mentioned has been modified.

Regards,
Ejay
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
-- 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 the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages