【问题标题】:How do I setup an endpoint for amp-consent?如何为 amp-consent 设置端点?
【发布时间】:2019-11-16 18:50:56
【问题描述】:

我不知道需要在 checkConsentHref 的 URL 引用的文档中放置什么代码。

我使用了来自https://amp.dev/documentation/examples/user-consent/basic_user_consent_flow/?format=websites 的示例代码。

我知道 checkConsentHref 应该是我自己的 url,但是那个位置需要放什么文档,应该放什么代码?

<amp-consent layout="nodisplay" id="consent-element">
<script type="application/json">
{
  "consents": {
    "my-consent": {
      "checkConsentHref": "https://example.com/api/show-consent",
      "promptUI": "consent-ui"
    }
  }
}
</script>
</amp-consent>

我希望在 checkConsentHref 位置有一些功能可以采取某种行动。

【问题讨论】:

  • 这里有同样的问题。如果我不必为此设置自己的端点,那就太好了……为什么这不可能?

标签: amp-html


【解决方案1】:

我在这里找到了一个很好的解释:About consent

可以通过checkConsentHref 属性指定 CORS 端点。 amp-consent component 将通过 POST 请求检查是否需要显示同意 UI。对此请求的响应应如下所示:

{
  "promptIfUnknown": true
}

#or

{
  "promptIfUnknown": false
}


所以你可以在那里添加例如https://ampbyexample.com/samples_templates/consent/getConsent 我第一次看到这个网址时,我以为它只是示例,但它确实有效。 此 url 存储有关显示同意的信息。您可以在 JS 控制台中查看它。

https://ampbyexample.com/samples_templates/consent/getConsent 将根据之前的用户操作返回 "promptIfUnknown": true"promptIfUnknown": false

我不知道使用这个“示例”网址代替自己的网址是否是一个好习惯。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-24
  • 1970-01-01
  • 2021-12-10
  • 2016-03-01
  • 1970-01-01
相关资源
最近更新 更多