Thomas
Thomas

Reputation: 175

Google Adwords | excludedPlacementList -> addExcludedPlacement won't work with Urls that work via the UI

Let list denote an ExcludedPlacementList. Consider a Placement-Url (eg extracted from the Domain / Url column of a URL_PERFORMANCE_REPORT report) of the form 'mobileapp::2-test.bla.com'. If I go to [https://adwords.google.com/aw/placementexclusionlists/detail?] and enter the placement mobileapp::2-test.bla.com, it works. An entry is generated. So why does it not work via the script command (Google Adwords Api):

list.addExcludedPlacement('mobileapp::2-test.bla.com')

? When I call this, I get the error

Placement-URLs müssen in einem gültigen URL-Format angegeben werden

I even tried to call instead

list.addExcludedPlacement('https://play.google.com/store/apps/details?id=test.bla.com')

That didn’t work either.


On the side… Is there a way to suggest to Google developers to fix this, so that the above command is possible?

Upvotes: 0

Views: 119

Answers (1)

Lars M
Lars M

Reputation: 1

I found a working solution here: https://groups.google.com/g/adwords-scripts/c/XEojOPTs0Vk

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')
}

With small adjustments I was able to make this work nicely for my needs, so this might also be usefull to anyone else who googles their way to this question.

Upvotes: 0

Related Questions