UniConsent 标签实施

JavaScript 标签安装

每个网站都有一个独特的 JavaScript Tag,需要安装在每个页面上。

您可以在安装与设置部分找到 UniConsent Tag。

Tag 有两个部分。第一部分是应嵌入页面顶部的 stub。第二部分可以使用 async 加载。对您的网站几乎没有性能影响。

stub 代码

您可以选择使用以下 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>

添加隐私设置链接(可选):

您可以禁用“隐私设置图标”并在页面上添加以下链接。

<a href="#" onclick='__tcfapi("openunic");return false;'>隐私设置</a>

添加带有 CSS 规则的隐私设置链接:

您可以使用 CSS 选择器定位 Web 页面上的 DIV,UniConsent 会根据 GEO 位置和已启用的功能在 DIV 中自动插入隐私设置链接。

<div id="uniconsent-config"></div>

自动插入隐私设置链接:

您可以在 Web 页面的页脚放置以下占位符 DIV,UniConsent 会根据 GEO 位置和已启用的功能在占位符中自动插入隐私设置链接。

<div id="uniconsent-config"></div>

使用 WordPress 和 Drupal 插件安装:

您可以在安装与设置部分找到许可密钥。

下一步

如果您想集成您的 JavaScript 标签,请转到第三方 JavaScript 标签集成部分。