Placement Exclusion of An App

220 views
Skip to first unread message

Orkhan Alikhanov

unread,
Mar 8, 2022, 2:53:43 AM3/8/22
to Google Ads Scripts Forum
It seems it's impossible to exclude apps via `placement.addExcludedPlacement` method. For example following invocations does not exclude apps:

placement.addExcludedPlacement('mobileapp::2-com.exkot.wifi.helper')
placement.addExcludedPlacement('com.exkot.wifi.helper.adsenseformobileapps.com')

Upon exploration, we found out that behavior of `addExcludedPlacement` can be patched to accommodate exclusion of apps. However, we think that it would be better if G. Ads Scripts supported these methods. Here is the patch method:

function patchMutation(placement) {
  const orig = placement.service.mutate
  placement.service.mutate = (...args) => {
    const create = args[1].create
    const url = create.placement.url

    const isAndroidApp = url.startsWith('https://play.google.com/')
    const isIOSApp = url.startsWith('https://itunes.apple')
    if (isAndroidApp || isIOSApp) {
      const app_id = isIOSApp ? '1-' + /(\d+)$/.exec(url)[1] : '2-' + url.replace('https://play.google.com/store/apps/details?id=', '')
     
      create.type = 'MOBILE_APPLICATION'
      create.mobile_application = {
        app_id,
      }
   
      delete create.placement
    }
   
    return orig.call(placement.service, ...args)
  }
}

Usage:
const placement = AdsApp.excludedPlacementLists().get().next()
patchMutation(placement)
placement.addExcludedPlacement(url)
// placement.addExcludedPlacements(urls)

Google Ads Scripts Forum Advisor

unread,
Mar 9, 2022, 3:26:59 AM3/9/22
to adwords...@googlegroups.com

Hello Orkhan,

 

Michael here from Google Ads scripts Team.

 

It is good to know that you found a workaround to achieve your use case on scripts, as mobile app placements and mobile app category placements are not currently supported, see here for this information. However, I can raise this to our wider team as a feature request. But for the meantime, please provide your use case in business terms and how this feature will help you.

Regards,

Google Logo
Michael Angelo
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2XmQRo:ref

Orkhan Alikhanov

unread,
Mar 9, 2022, 12:07:56 PM3/9/22
to Google Ads Scripts Forum
We were using this feature to exclude ad placements in fraudulent apps and websites.

Google Ads Scripts Forum Advisor

unread,
Mar 10, 2022, 2:49:07 AM3/10/22
to adwords...@googlegroups.com
Hi Orkhan,

Could you please share your CID as well via Reply privately to author option? In case you encounter an error when using the mentioned option, you can send the requested information on this email (googleadsscr...@google.com) instead, then let us know here once sent.

Regards,
Google Logo
Teejay Wennie
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2XmQRo:ref

Orkhan Alikhanov

unread,
Mar 22, 2022, 4:39:33 PM3/22/22
to Google Ads Scripts Forum
I can't reply to author. Says I don't have permission. Also by CID you mean the customer id of the account I'm running the script? It's a manager account by the way if that matters.

Google Ads Scripts Forum Advisor

unread,
Mar 24, 2022, 1:49:31 AM3/24/22
to adwords...@googlegroups.com

Hello Orkhan,

Thanks for getting back to us.

You can share your Customer ID by replying to this thread. If you want to share it privately, then you can send an email to our support channel (googleadsscr...@google.com). As for the Customer ID, yes, it is the customer id of the account you're running the script which can be found on the top right side of your Google Ads account, typically in the form of XXX-XXX-XXXX (where X is a number).

Regards,

Google Logo
Mark Kevin
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2XmQRo:ref

Pascal van Dooren

unread,
Mar 30, 2022, 3:13:29 AM3/30/22
to Google Ads Scripts Forum
Thank you so much for this fix Orkhan. Really annoying this is not possible in through Google Ads Script, even though it's possible in the UI. I did notice that trying to apply the list campaigns after the patch results in an error. Good to mention that using bulk uploads for placements works as well.

I've also noticed that URLs with more than 2 paths also fail to exclude. This is something that happens in the UI as well.

Orkhan Alikhanov

unread,
Mar 30, 2022, 6:06:37 AM3/30/22
to Google Ads Scripts Forum
Bulk upload is a nice idea actually. Glad it works.

You can revert the patch after you don't need it:

function patchMutation(placement) {
  placement.service.__original_mutate = placement.service.mutate

  placement.service.mutate = (...args) => {
    const create = args[1].create
    const url = create.placement.url

    const isAndroidApp = url.startsWith('https://play.google.com/')
    const isIOSApp = url.startsWith('https://itunes.apple')
    if (isAndroidApp || isIOSApp) {
      const app_id = isIOSApp ? '1-' + /(\d+)$/.exec(url)[1] : '2-' + url.replace('https://play.google.com/store/apps/details?id=', '')
     
      create.type = 'MOBILE_APPLICATION'
      create.mobile_application = {
        app_id,
      }
   
      delete create.placement
    }
   
    return placement.service.__original_mutate.call(placement.service, ...args)
  }
}

function unpatchMutation(placement) {
  placement.service.mutate = placement.service.__original_mutate
  delete placement.service.__original_mutate
}

Usage:
function main() {
  const placement = AdsApp.excludedPlacementLists().get().next()

  // fails
  placement.addExcludedPlacement('https://play.google.com/store/apps/details?id=com.exkot.wifi.helper')

  // now works
  patchMutation(placement)
  placement.addExcludedPlacement('https://play.google.com/store/apps/details?id=com.exkot.wifi.helper')
 
  // fails again
  unpatchMutation(placement)
  placement.addExcludedPlacement('https://play.google.com/store/apps/details?id=com.exkot.wifi.helper')
}


Pascal van Dooren

unread,
Mar 30, 2022, 7:31:19 AM3/30/22
to Google Ads Scripts Forum
Thanks a lot Orkhan, appreciate the help.

Google Ads Scripts Forum Advisor

unread,
Mar 30, 2022, 11:22:17 PM3/30/22
to adwords...@googlegroups.com

Hello Everyone,

Thanks for sharing all the details and use cases for your Placement concerns. As previously mentioned by my colleagues, Mobile app placements and mobile app category placements are not supported in the Google Ads scripts (as mentioned here). Please note that there are some features in the Google Ads UI that are not available in the Google Ads scripts. Having said that, allow me to raise a feature request for this; however, there is no guarantee if this will be supported in the scripts soon. We recommend that you keep an eye to our blog for any updates and releases.

Regards,

Pascal van Dooren

unread,
Apr 6, 2022, 9:22:23 AM4/6/22
to Google Ads Scripts Forum
Hi Orkhan,

Have you also found a way to patch this for placementBuilder() on campaign level? Trying to exclude app URLs on campaign level, but I can't seem to figure out the request.

Reply all
Reply to author
Forward
0 new messages