Compliant with GDPR, CCPA, COPPA, LGPD, PECR, PDPA, PIPEDA, and more.
在每个页面添加一个带有许可证密钥的 script 标签,尽量放在 <head> 的最前面。该标签会设置 Google Consent Mode 默认状态,立即定义 unicReady 和 unicUpdate,然后在后台加载完整的 CMP。
<script src="https://cmp.uniconsent.com/v2/cmp.js" data-license="YOUR_LICENSE"></script>
您可以在安装与设置部分找到许可证密钥。
cmp.js 加载器。请勿重复添加。wait_for_update 为 3 秒。如果您自行设置 Consent Mode 默认值,请放在该标签之后,否则会被覆盖。unicReady 和 unicUpdate 在同意状态最终确定后运行您的代码。请参阅 Consent Ready API。已经使用经典两段式标签安装了 UniConsent?它可以继续正常工作。请参阅本页底部的经典标签安装部分。
您可以关闭 Show Privacy Settings Button 并在页面上添加以下链接。
<a href="#" onclick='__tcfapi("openunic");return false;'>隐私设置</a>
您可以使用 CSS 选择器定位 Web 页面上的 DIV,UniConsent 会根据 GEO 位置和已启用的功能在 DIV 中自动插入隐私设置链接。
<div id="uniconsent-config"></div>
您可以在 Web 页面的页脚放置以下占位符 DIV,UniConsent 会根据 GEO 位置和已启用的功能在占位符中自动插入隐私设置链接。
<div id="uniconsent-config"></div>
您可以在安装与设置部分找到许可密钥。
在页面顶部的 <head> 中、UniConsent 标签之前添加以下标签。它们让浏览器提前解析 DNS 并与 cmp.uniconsent.com 建立连接,使 CMP 脚本更早开始下载,同意横幅显示得更快。
<link rel='dns-prefetch' href='//cmp.uniconsent.com' />
<link rel="preconnect" href="https://cmp.uniconsent.com" crossorigin>
如果您通过第一方 CMP 域名提供 CMP,请使用您的自定义域名代替 cmp.uniconsent.com。
单一标签特意不使用 async 加载。它会先于页面上的其他内容执行,因此 Google Consent Mode 默认状态、IAB TCF、USP 和 GPP stub,以及 unicReady 和 unicUpdate 函数都会在您的 Google 标签、广告标签或自有代码运行之前就绪。标签本身很小且会被缓存,完整的 CMP 在后台加载,因此对页面加载的影响极小。配合上面的预连接标签,可以最快显示横幅,同时避免标签在同意默认值设置之前触发。
您可以为标签添加 async,但需注意以下几点:
unicReady 和 unicUpdate 可能尚不存在。请添加下面的两行队列保护代码,这样提前发出的调用会在标签加载后被重放。unicReady 回调中加载您的 Google 标签。async 时,您的广告标签或 Prebid 调用 __tcfapi 时它可能尚不存在。请在广告标签之前添加 stub 标签,或者在 unicReady 回调中加载广告标签。<script async src="https://cmp.uniconsent.com/v2/cmp.js" data-license="YOUR_LICENSE"></script>
<script>
window.unicReady = window.unicReady || function (cb) { (window.unicReady.q = window.unicReady.q || []).push(cb); };
window.unicUpdate = window.unicUpdate || function (cb) { (window.unicUpdate.q = window.unicUpdate.q || []).push(cb); };
unicReady(function (status) {
// 同意状态已最终确定:在此加载您的标签
});
unicUpdate(function (status) {
// 每次同意状态变化
});
</script>
您也可以监听 window 上的 unic:ready 和 unic:update DOM 事件(需在标签之前注册)。状态对象和完整细节请参阅 Consent Ready API。
如果您想集成您的 JavaScript 标签,请转到第三方 JavaScript 标签集成部分。
本部分适用于在单一标签推出之前安装 UniConsent 的网站。经典两段式标签可继续正常工作,无需迁移。如需切换,请移除下方所有标签,并添加本页顶部的单一标签。
每个网站都有一个独特的 JavaScript Tag,需要安装在每个页面上。
您可以在安装与设置部分找到 UniConsent Tag。
Tag 有两个部分。第一部分是应嵌入页面顶部的 stub。第二部分可以使用 async 加载。对您的网站几乎没有性能影响。
您可以选择使用以下 JavaScript 标签加载 stub 代码:
<script src="https://cmp.uniconsent.com/v2/stub.min.js"></script>
或者用以下代码替换上述 stub 标签:
<script type="text/javascript">
!function(){var e,t,a;e="__tcfapiLocator",t=[],(a=window.frames[e])||(function t(){var n=window.document,i=!!a;if(!i)if(n.body){var o=n.createElement("iframe");o.style.cssText="display:none",o.name=e,n.body.appendChild(o)}else setTimeout(t,50);return!i}(),window.__tcfapi=function(){for(var e,a=[],n=0;n<arguments.length;n++)a[n]=arguments[n];if(!a.length)return t;if("setGdprApplies"===a[0])a.length>3&&2===parseInt(a[1],10)&&"boolean"==typeof a[3]&&(e=a[3],"function"==typeof a[2]&&a[2]("set",!0));else if("ping"===a[0]){var i={gdprApplies:e,cmpLoaded:!1,cmpStatus:"stub"};"function"==typeof a[2]&&a[2](i,!0)}else t.push(a)},window.addEventListener("message",(function(e){var t="string"==typeof e.data,a={};try{a=t?JSON.parse(e.data):e.data}catch(e){}var n=a.__tcfapiCall;if(n)try{window.__tcfapi(n.command,n.version,(function(a,i){var o={__tcfapiReturn:{returnValue:a,success:i,callId:n.callId}};t&&(o=JSON.stringify(o)),e.source&&"function"==typeof e.source.postMessage&&e.source.postMessage(o,"*")}),n.parameter)}catch(e){}}),!1))}();
!function(){var e,a,t;e="__uspapiLocator",a=[],(t=window.frames[e])||(function a(){var n=window.document,s=!!t;if(!t)if(n.body){var i=n.createElement("iframe");i.style.cssText="display:none",i.name=e,n.body.appendChild(i)}else setTimeout(a,50);return!s}(),window.__uspapi=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!e.length)return a;"ping"===e[0]?"function"==typeof e[2]&&e[2]({cmpLoaded:!1,cmpStatus:"stub"},!0):a.push(e)},window.addEventListener("message",(function(e){var a="string"==typeof e.data,t={};try{t=a?JSON.parse(e.data):e.data}catch(e){}var n=t&&t.__uspapiCall;if(n)try{window.__uspapi(n.command,n.version,(function(t,s){var i={__uspapiReturn:{returnValue:t,success:s,callId:n.callId}};a&&(i=JSON.stringify(i)),e.source&&"function"==typeof e.source.postMessage&&e.source.postMessage(i,"*")}),n.parameter)}catch(e){}}),!1))}();
window.__gpp_addFrame=function(e){if(!window.frames[e])if(document.body){var t=document.createElement("iframe");t.style.cssText="display:none",t.name=e,document.body.appendChild(t)}else window.setTimeout(window.__gpp_addFrame,50,e)},window.__gpp_stub=function(){var e=arguments;if(__gpp.queue=__gpp.queue||[],__gpp.events=__gpp.events||[],!e.length||1==e.length&&"queue"==e[0])return __gpp.queue;if(1==e.length&&"events"==e[0])return __gpp.events;var t=e[0],p=e.length>1?e[1]:null,s=e.length>2?e[2]:null;if("ping"===t)p&&p({gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[-1],gppString:"",parsedSections:{}},!0);else if("addEventListener"===t){"lastId"in __gpp||(__gpp.lastId=0),__gpp.lastId++;var n=__gpp.lastId;__gpp.events.push({id:n,callback:p,parameter:s}),p({eventName:"listenerRegistered",listenerId:n,data:!0,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[-1],gppString:"",parsedSections:{}}},!0)}else if("removeEventListener"===t){for(var a=!1,i=0;i<__gpp.events.length;i++)if(__gpp.events[i].id==s){__gpp.events.splice(i,1),a=!0;break}p({eventName:"listenerRemoved",listenerId:s,data:a,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[-1],gppString:"",parsedSections:{}}},!0)}else"hasSection"===t?p(!1,!0):"getSection"===t||"getField"===t?p(null,!0):__gpp.queue.push([].slice.apply(e))},window.__gpp_msghandler=function(e){var t="string"==typeof e.data;try{var p=t?JSON.parse(e.data):e.data}catch(e){p=null}if("object"==typeof p&&null!==p&&"__gppCall"in p){var s=p.__gppCall;try{window.__gpp(s.command,(function(p,n){var a={__gppReturn:{returnValue:p,success:n,callId:s.callId}};e.source&&"function"==typeof e.source.postMessage&&e.source.postMessage(t?JSON.stringify(a):a,"*")}),"parameter"in s?s.parameter:null,"version"in s?s.version:"1.1")}catch(e){}}},"__gpp"in window&&"function"==typeof window.__gpp||(window.__gpp=window.__gpp_stub,window.addEventListener("message",window.__gpp_msghandler,!1),window.__gpp_addFrame("__gppLocator"));
</script>