進階使用者同意流程
簡介
現今的使用者希望對其線上體驗有更多的控制權。此外,發布商在如何向使用者提供通知和選擇方面,面臨來自供應商政策到不斷演變的法律要求的各種不同需求。開放原始碼 AMP 專案正努力為發布商和技術供應商提供工具,以實施他們偏好的使用者控制,並支援他們在 AMP 頁面上的各種個別合規性要求。
此頁面示範如何建構更進階的封鎖同意流程。它將顯示「接受」和「拒絕」按鈕,點擊後將顯示更多資訊,例如使用者接受時使用的第三方列表,或使用者拒絕時的一般資料使用通知。
設定
在標頭中匯入 consent 元件。
<script async custom-element="amp-consent" src="https://cdn.ampproject.org/v0/amp-consent-0.1.js"></script>
在此範例中,我們也使用了 amp-ad
以及...
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
... amp-list
以及...
<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
... amp-mustache
。
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
基本用法
amp-consent
元件可讓您使用必要的 consentRequired
旗標來指定此頁面所需的使用者同意。可以使用 checkConsentHref
屬性指定 CORS 端點,該端點將透過 POST 請求進行檢查。回應應如下所示
{ "consentRequired": boolean (required), "consentStateValue": enum (accepted/rejected/unknown) (optional), "consentString": string (optional), "expireCache": boolean (default false), }
回應將指示是否顯示 promptUI
中給定 ID 的元素。 amp-consent
將首先檢查本機儲存空間中是否已存在同意決定,如果存在則使用它。否則,如果已設定 promptUi
且 consentRequired
為 true
,則會顯示 promptUi
。如果 consentRequired
設定為 false,`amp-consent 將立即解除封鎖所有元素。
<amp-consent id="myConsent" layout="nodisplay">
<script type="application/json">{
"consentInstanceId": "advanced-consent",
"consentRequired": "remote",
"checkConsentHref": "/documentation/examples/api/get-consent",
"promptUI": "consentDialog",
"postPromptUI": "post-consent-ui"
}</script>
<div class="lightbox" id="consentDialog">
<div class="lightbox-content">
<div class="dismiss-button" role="button" tabindex="0" on="tap:myConsent.dismiss">X</div>
<div class="message">
<h2>Headline</h2>
<p>This is an important message requiring you to make a choice.</p>
</div>
<div id="choice">
<button on="tap:choice2.show,choice1.hide">Choice 2</button>
</div>
<div id="choice1" hidden class="message">
<p>This is some more information about this choice. Here's a list of items related to this choice.</p>
<amp-list height="132" layout="fixed-height" src="/json/consent-items.json" binding="no">
<template type="amp-mustache">
<li>{{.}}</li>
</template>
</amp-list>
<button on="tap:myConsent.accept">Confirm</button>
</div>
<div id="choice2" hidden class="message">
<p>This is some more information about this choice.</p>
<button on="tap:myConsent.reject">Confirm</button>
</div>
</div>
</div>
<div id="post-consent-ui">
<button on="tap:myConsent.prompt()">Update Consent</button>
</div>
</amp-consent>
使用 data-block-on-consent
屬性來封鎖 AMP 元件,直到獲得同意。個別 AMP 元件可以覆寫封鎖行為並自行實作封鎖邏輯。
以下是圖片,在獲得同意之前會被封鎖
<amp-img data-block-on-consent src="/static/samples/img/landscape_lake_300x201.jpg" width="300" height="201">
</amp-img>
廣告也可以在獲得同意之前被封鎖,但廣告聯播網可以實作自己的行為(例如,預設為非個人化廣告,無需同意,如 此處文件 中針對 Doubleclick 所述)。請注意,當您接受或拒絕此特定範例的同意時,您可能會看到相同的廣告,那是因為即使在接受同意時,範例也不會使用個人化資訊。
以下是 amp-ad
依賴 amp-consent
的範例
<amp-ad data-block-on-consent data-slot="/30497360/a4a/a4a_native" height="250" type="doubleclick" width="300">
</amp-ad>
如果此頁面上的說明沒有涵蓋您的所有問題,請隨時聯繫其他 AMP 使用者,討論您的確切使用案例。
前往 Stack Overflow 未說明的特色功能?AMP 專案強烈鼓勵您的參與和貢獻!我們希望您能成為我們開放原始碼社群的持續參與者,但我們也歡迎您針對您特別感興趣的問題提供一次性的貢獻。
在 GitHub 上編輯範例