谷歌AdWords | exceptedPlacementList -> addExcludedPlacement 不适用于通过 UI 工作的 URL

问题描述 投票:0回答:1

list
表示
ExcludedPlacementList
。考虑一个 Domain 形式的 Placement-Url(从
Url
报告的
URL_PERFORMANCE_REPORT
/
'mobileapp::2-test.bla.com'
列中提取的
eg
)。如果我转到 [https://adwords.google.com/aw/placementexclusionlists/detail?] 并输入展示位置
mobileapp::2-test.bla.com
,它就会起作用。生成一个条目。那么为什么它不能通过脚本命令(Google Adwords Api)工作:

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

?当我调用这个时,我收到错误

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

我什至尝试打电话

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

那也没用。


另一方面……有没有办法建议 Google 开发人员解决这个问题,以便上面的命令成为可能?

javascript url invalid-argument google-ads-api
1个回答
0
投票

我在这里找到了一个可行的解决方案: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')
}

通过一些小的调整,我能够很好地满足我的需求,所以这对于其他通过谷歌搜索这个问题的人来说也可能有用。

© www.soinside.com 2019 - 2024. All rights reserved.