Link Checker Script: How to check if URL contains a specific value

526 views
Skip to first unread message

Kelvis Albarran

unread,
Feb 8, 2022, 1:25:12 AM2/8/22
to Google Ads Scripts Forum
Hi everyone.

I need to do an audit in a Google Ads account where all the URLs need to have a specific value. This value is not added as a custom parameter but it's part of the URL.

I'm trying to use the Google Ads Link Checker script and even though it is helpful for finding issues in the landing page, I was wondering if there is a way I can use the Custom Validation setup to audit the values that are requeried for the URLs.

Ideally, I would like to recieve an email if there is any URL in an active ad that doesn't contain the requeried value in the URL.

I don't have experience in JavaScript and I'm finding hard to solve this. I would appreaciate all the help you can provide.

Thank you so much in advance.


Google Ads Scripts Forum Advisor

unread,
Feb 9, 2022, 3:28:01 AM2/9/22
to adwords...@googlegroups.com
Hi Kelvis,

Thank you for reaching out to us.

With regard to your concern, the link checker advanced link validation should be able to assess your use case. However, could you kindly provide sample of the URL that you mentioned which should trigger an email notification?

Regards,
Google Logo
Teejay Wennie Pimentel
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2W5G9T:ref

Jose

unread,
Feb 9, 2022, 7:43:55 AM2/9/22
to Google Ads Scripts Forum
Hi Teejay!
Thank you for your answer.

Let's say my website is: example.com. I need to add a custom parameter directly on the final URL of every ad: example.com?phone_number=xxxxxxx 

Sometimes this custom parameter could be missed when creating new ads so ideally, I would like to receive an email every time the parameter phone_number is not in the URL of an ad so I can fix it.

Please note phone_number is inserted directly in the Final URL of each ad and not as a parameter in Google Ads.
How can I leverage the advance link validation in this case?

Thank you so much in advance

Sigurd Fabrin

unread,
Feb 9, 2022, 10:03:08 AM2/9/22
to Google Ads Scripts Forum
If you only wish to find the URLs in your account that contains a specific text, it is somewhat overkill to use Google's link checker script.

Instead, just pull a list of all URLs in the account and match them up against the text string you wish to look for.

This example code will send an email with a list of URLs that match a predetermined text
let settings = {  
  string: 'some-string', // find URLs that contain this text
  notify: 'em...@example.com', // send email with list of URLs
}

function main() {
  let query = 'SELECT ad_group_ad.ad.final_urls FROM ad_group_ad';
  let response = AdsApp.search(query)
  let urls = [];
   while (response.hasNext()) {
    let row = response.next();
    let url = row.adGroupAd.ad.finalUrls;  
     if (url != undefined && url.toString().match(settings.string)) {
      urls.push(url.toString());    
     }
   }
  let data = getUnique(urls) // remove duplicates
   if (data.length > 0) { // only send email when there are matches
     let account = AdsApp.currentAccount().getName();
  MailApp.sendEmail(
    settings.notify,'Found '+data.length+' unique URL(s) that contains: "'+settings.string+'"',
    'There are a total of '+urls.length+' ads with one of these URLs in the account\n***\n'+data.join('\n')+
    '\n\n\n---\nNotification sent by script running in the "'+account+'" Google Ads account'
    );
   }
}
function getUnique(array) {
  let uniqueArray = [];
    for (let index in array) {
      if(uniqueArray.indexOf(array[index]) === -1) {
        uniqueArray.push(array[index]);
   }
 }
   return uniqueArray;
}


Cheers
 Sigurd

Google Ads Scripts Forum Advisor

unread,
Feb 10, 2022, 1:47:44 AM2/10/22
to adwords...@googlegroups.com
Hi Jose,

I could see that Sigurd (Thank you for sharing this to the community) provided a script which fits to your use case, and can confirm that the implementation looks fine. Could you kindly check, then let me know how it goes?

Regards,
Google Logo
Teejay Wennie
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2W5G9T:ref

Jose

unread,
Feb 10, 2022, 10:08:28 AM2/10/22
to Google Ads Scripts Forum
Hi Sigurd / Teejay.

Thank you so much for your help so far.
I think the script Sigurd shared could help me but I was wondering if there is a way to adapt it to send me an email with a list of URL that does not contain a predetermined text instead.

It would be helpful because that could warn us about any ad that we need to modify immediately, instead of knowing which ads are ok.
Thank you again in advance!

Sigurd Fabrin

unread,
Feb 10, 2022, 10:54:47 AM2/10/22
to Google Ads Scripts Forum
Sure, just reverse the logic i.e. add a '!' so it adds URLs to the array when there is no match in the IF statement within the while loop

This line: if (url != undefined && !url.toString().match(settings.string)) 
..and then perhaps re-phrase the email so it makes sense ..

Btw: to look for more than one text string and ignore casing, change the syntax in the settings slightly

With the syntax below, it will match against any of of the text strings: adidas, nike or puma
string: /(adidas|nike|puma)/gi, // find URLs that contain this text


Cheers
 Sigurd
Reply all
Reply to author
Forward
0 new messages