如何为 amp-consent 设置端点?

How do I setup an endpoint for amp-consent?

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

我使用了 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 位置有一些功能来采取某种行动。

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

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

{
  "promptIfUnknown": true
}

#or

{
  "promptIfUnknown": false
}


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

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

我不知道使用这个 "example" url 代替自己的是否是一个好习惯。