Link Checker Script - How to exclude ended campaigns

244 views
Skip to first unread message

Alberto Vicente

unread,
Jan 6, 2022, 5:54:25 PM1/6/22
to Google Ads Scripts Forum
Hi there, I'm using the Link checker script excluding paused ads, keywords and sitelinks, but the script is picking up all enabled campaigns that have ended. Is there any way of modifying the script so it doesn't pick up on ended campaigns?

Thanks, 

Alberto

Google Ads Scripts Forum Advisor

unread,
Jan 6, 2022, 11:55:56 PM1/6/22
to adwords...@googlegroups.com
Hi Alberto,

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

The withCondition method of the AdsApp.​CampaignSelector does not seem to support an ENDED status column value or a Campaign end date column for you to filter out already ended campaigns.  However, I believe you could add a condition to look at the campaign end date (see getEndDate method) on line 755 where entities are processed. Please see code below:
    while (iterator.hasNext()) {
      var entity = iterator.next();
      if(entity.getEntityType() === 'Campaign' && entity.getEndDate() != null) {
        var accountTimeZone = AdsApp.currentAccount().getTimeZone();
        var campaignEndDate = entity.getEndDate();
        var accountDateTodayString = Utilities.formatDate(new Date(), accountTimeZone, 'MM/dd/YYYY');
        var dateToday = new Date(accountDateTodayString);
        var formattedCampaignEndDate = new Date(campaignEndDate.month + '/' + campaignEndDate.day + '/' + campaignEndDate.year);
        if(formattedCampaignEndDate < dateToday) {
          entities.push(entity);
        }
      } else {
        entities.push(entity);
      }
    }
Let me know if you need anything else.

Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2UhOeE:ref

Alberto Vicente

unread,
Jan 9, 2022, 11:56:10 PM1/9/22
to Google Ads Scripts Forum
Thanks, Harry,

I have replaced
 while (iterator.hasNext()) {
    entities.push(iterator.next());
  }
with your code in line 755, but it is still picking up the ended campaigns...

I can see a second instance with the same original code in line 682. Do we need to change it also there?

Google Ads Scripts Forum Advisor

unread,
Jan 10, 2022, 3:55:22 AM1/10/22
to adwords...@googlegroups.com
Hi Alberto,

Thanks for getting back. Kindly provide your Google Ads account ID and script name so I can take a look at your script on our end and assist you further.

Phương Đào

unread,
Jan 10, 2022, 6:56:55 PM1/10/22
to Google Ads Scripts Forum on behalf of adsscripts
thanks a lot my account id
402-470-5133
10/1/2022 16:00:37TypeError: Cannot use instanceof on a non-object. (file Code.gs, line 35)
2022-01-10_160114.jpg

Consulting Office : ĐÀO LÊ PHƯƠNG         

Tel       :  090.33.000.64  -  0961.784.130

Email  :  phuongdaon...@gmail.com



Vào Th 2, 10 thg 1, 2022 vào lúc 15:55 Google Ads Scripts Forum on behalf of adsscripts <adwords...@googlegroups.com> đã viết:
--
-- 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-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/-JJyQ000000000000000000000000000000000000000000000R5HKS400_wb-5dhESAaLhh2wfSyuUw%40sfdc.net.
Currency Converter Script.docx

Google Ads Scripts Forum Advisor

unread,
Jan 11, 2022, 1:34:27 AM1/11/22
to adwords...@googlegroups.com
Hi Alberto,

Thanks for getting back. It is great to use the campaign IDs to filter out entities to be processed by the script. Could you try applying the same concept of checking the campaign end date (getEndDate) to the custom function (getBaseCampaignIds) you have added there? Iterating through the campaign selector, would be like the following:
while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    if (campaign.getEndDate() != null) {
        var accountTimeZone = AdsApp.currentAccount().getTimeZone();
        var campaignEndDate = entity.getEndDate();
        var accountDateTodayString = Utilities.formatDate(new Date(), accountTimeZone, 'MM/dd/YYYY');
        var dateToday = new Date(accountDateTodayString);
        var formattedCampaignEndDate = new Date(campaignEndDate.month + '/' + campaignEndDate.day + '/' + campaignEndDate.year);
        if (formattedCampaignEndDate < dateToday) {
            campaignIds.push(campaign.getId());
        }
    }
}
Let me know if you are still unable to achieve your requirement. 

@Phuong Dao: It seems that you have not been able to provide an API key for your script to access the the third party API. Kindly check provided instructions in the script to obtain the API key.

Alberto Vicente

unread,
Jan 17, 2022, 5:38:00 PM1/17/22
to Google Ads Scripts Forum
Thanks, Harry,

I have implemented the code but it doesn't seem to be working. The script is still picking on the ads, extensions and keywords inside those paused campaigns. I'm wondering if I have put it in the wrong place and is not properly filtering the ended campaigns out, can you take a look?

Thanks, 

Alberto

Google Ads Scripts Forum Advisor

unread,
Jan 18, 2022, 1:27:42 AM1/18/22
to adwords...@googlegroups.com
Hi Alberto,

Thanks for trying that out. In your custom function, could you try filtering out paused campaigns with this condition: "Status NOT_IN [PAUSED]" and let me know if that works? On the other hand, I would appreciate it if you can provide a shareable link to the template spreadsheet you use in the script so I can take a look at the results that you got on your end.

Looking forward to your reply.

Alberto Vicente

unread,
Jan 19, 2022, 12:03:47 AM1/19/22
to Google Ads Scripts Forum
Thanks Harry, 

Sorry for the confusion I meant that the script is still picking on the ads, extensions and keywords inside those ended campaigns (Paused campaigns are filtered out). 

Can you share your email address so I can give you access?

Google Ads Scripts Forum Advisor

unread,
Jan 19, 2022, 3:44:40 AM1/19/22
to adwords...@googlegroups.com
Hi Alberto,

Thanks getting back. Could you instead provide a shareable link of the template spreadsheet or attach a local file copy of the spreadsheet instead? You can send a private message to our email (googleadsscr...@google.com) as well.

Google Ads Scripts Forum Advisor

unread,
Jan 21, 2022, 2:46:59 AM1/21/22
to adwords...@googlegroups.com
Hi Alberto,

Thanks for getting back to us with the private details and for your patience on the matter as we try to identify the best way to update the script and achieve your requirement. I have deemed that you can instead take advantage of the Advanced link validation feature that the Link Checker script offers. You can set the 'Use custom validation function' to Yes in your template spreadsheet and insert a custom validation logic into the isValidResponse function on line 86 of the script to check each URL and its associated campaign.

From there, you can use the entityDetails.campaign value to retrieve the campaign object using the AdsApp.​CampaignSelector and compare today's date with the campaign's end date to identify if it has ended. You can then have 'true' in the return statement so that the script will not report the URL as broken.

Let me know if you have further questions on this.

Alberto Vicente

unread,
Jan 23, 2022, 11:05:37 PM1/23/22
to Google Ads Scripts Forum
Hi Harry, 
I 'm not surec what you mean. The function isValidResponse is set up by default as true. If I add some code in there returning true it will not do anything, right? 

Google Ads Scripts Forum Advisor

unread,
Jan 24, 2022, 5:23:06 AM1/24/22
to adwords...@googlegroups.com
Hi Alberto,

Thanks for your response. The isValidResponse function returns true by default as a placeholder implementation to treat all URLs as valid. You can instead have the return statement as true in the condition that you will add to check if a campaign have ended already. In this case, the script should ignore the broken or invalid URLs from ended campaigns or would not be exported in the spreadsheet results. 

Let me know if you need anything else.

Alberto Vicente

unread,
Jan 26, 2022, 5:43:04 PM1/26/22
to Google Ads Scripts Forum

Hi Harry,

 I'm new with coding, could you pass me the code to insert, I’m not entirely sure of how the logic works there.

 Thanks,

 Alberto

Google Ads Scripts Forum Advisor

unread,
Jan 27, 2022, 3:00:08 AM1/27/22
to adwords...@googlegroups.com
Hi Alberto,

Thanks for getting back. I believe you can use the logic I have provided you the first time which I am reiterating below. However, I would highly recommend reaching to a developer in your team to help you with the implementation.
var campaign = AdsApp.campaigns().withCondition('CampaignName =' + entityDetails).get().next();
if (campaign.getEndDate() != null) {
  var accountTimeZone = AdsApp.currentAccount().getTimeZone();
  var campaignEndDate = campaign.getEndDate();
  var accountDateTodayString = Utilities.formatDate(new Date(), accountTimeZone, 'MM/dd/YYYY');
  var dateToday = new Date(accountDateTodayString);
  var formattedCampaignEndDate = new Date(campaignEndDate.month + '/' + campaignEndDate.day + '/' + campaignEndDate.year);
  if (formattedCampaignEndDate < dateToday) {
    // If valid, return true.If invalid, return false.
  }
}
Reply all
Reply to author
Forward
0 new messages