Pixel Cookie 同意模式
TikTok 的 Pixel 同意模式提供两种解决方案: - 默认不给予同意:此解决方案将阻止 Pixel 与 TikTok 共享数据,直到用户明确同意为止。 - 默认给予同意:此解决方案允许 Pixel 与 TikTok 共享数据,直到用户明确撤销同意为止。
默认不给予同意的解决方案
- 在 Pixel 基础代码中,为
ttq.methods数组新增 "holdConsent","revokeConsent" 和 "grantConsent" 方法。 - 在通过
ttq.load()加载 Pixel 之前,调用ttq.holdConsent()。这将使事件处于事件队列中,在用户同意状态发生更改之前不会共享事件数据。 - 根据用户的偏好:
- 如果用户给予同意,调用
ttq.grantConsent()。这将与 TikTok 服务器共享事件,包括会话中先前处于队列中的事件。 - 如果用户不给予同意,调用ttq.revokeConsent()。这将阻止与 TikTok 服务器共享事件,包括会话中先前处于队列中的事件。 - 如果用户更改偏好,需根据情况调用
ttq.grantConsent()启用通过 Pixel 的数据共享或调用ttq.revokeConsent()关闭通过 Pixel 的数据共享。调用ttq.revokeConsent()不会影响已与 TikTok 服务器共享的数据。
注意
若条件允许,在安装了 TikTok Pixel 的每个网页上广告主都应实施此解决方案。
用例 1:在用户进行明确选择之前,网站默认为未给予同意
(code Javascript javascript)
<script>
// Add the new methods "holdConsent", "revokeConsent", and "grantConsent" to the ttq.methods array
!function (w, d, t) {
w.TiktokAnalyticsObject=t;var ttq=w[t]=w[t]||[];ttq.methods=["page","track","identify","instances","debug","on","off","once","ready","alias","group","enableCookie","disableCookie","holdConsent","revokeConsent","grantConsent"],ttq.setAndDefer=function(t,e){t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}};for(var i=0;i<ttq.methods.length;i++)ttq.setAndDefer(ttq,ttq.methods[i]);ttq.instance=function(t){for(var e=ttq._i[t]||[],n=0;n<ttq.methods.length;n++)ttq.setAndDefer(e,ttq.methods[n]);return e},ttq.load=function(e,n){var i="https://analytics.tiktok.com/i18n/pixel/events.js";ttq._i=ttq._i||{},ttq._i[e]=[],ttq._i[e]._u=i,ttq._t=ttq._t||{},ttq._t[e]=+new Date,ttq._o=ttq._o||{},ttq._o[e]=n||{};var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=i+"?sdkid="+e+"&lib="+t;var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(o,a)};
// Hold consent before 'ttq.load' is called
ttq.holdConsent();
ttq.load('YOUR PIXEL ID WILL BE LOCATED HERE');
ttq.page();
}(window, document, 'ttq');
</script>
<script>
function accept
<script>
(/code)
(code)
// Once affirmative consent has been denied.
<span style="background-color: green;">ttq.revokeConsent(); </span>
(/code)
(code)
// Once affirmative consent has been granted
<span style="background-color: green;">ttq.grantConsent(); </span>
(/code)
默认给予同意的解决方案
- 在 Pixel 基础代码中,为
ttq.methods数组新增 "revokeConsent" 和 "grantConsent" 方法。 - 调用
ttq.load()以初始化 Pixel。所有事件都将默认发送到 TikTok 服务器。 - 根据用户的偏好:
- 如果用户给予同意,调用
ttq.grantConsent()。这将使用户触发的事件持续发送到 TikTok 服务器。 - 如果用户不给予同意,调用ttq.revokeConsent()。这将阻止后续事件发送到 TikTok 服务器。 - 如果用户更改偏好,需根据情况调用
ttq.grantConsent()启用通过 Pixel 的数据共享或调用ttq.revokeConsent()关闭通过 Pixel 的数据共享。调用ttq.revokeConsent()不会影响已与 TikTok 服务器共享的数据。
注意
若条件允许,在安装了 TikTok Pixel 的每个网页上广告主都应实施此解决方案。
用例 2:网站默认给予同意,用户明确拒绝 Cookie,随后又接受 Cookie
(code Javascript javascript)
<script>
// Add the new methods "revokeConsent" and "grantConsent" to the ttq.methods array
!function (w, d, t) {
w.TiktokAnalyticsObject=t;var ttq=w[t]=w[t]||[];ttq.methods=["page","track","identify","instances","debug","on","off","once","ready","alias","group","enableCookie","disableCookie","revokeConsent","grantConsent"],ttq.setAndDefer=function(t,e){t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}};for(var i=0;i<ttq.methods.length;i++)ttq.setAndDefer(ttq,ttq.methods[i]);ttq.instance=function(t){for(var e=ttq._i[t]||[],n=0;n<ttq.methods.length;n++)ttq.setAndDefer(e,ttq.methods[n]);return e},ttq.load=function(e,n){var i="https://analytics.tiktok.com/i18n/pixel/events.js";ttq._i=ttq._i||{},ttq._i[e]=[],ttq._i[e]._u=i,ttq._t=ttq._t||{},ttq._t[e]=+new Date,ttq._o=ttq._o||{},ttq._o[e]=n||{};var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=i+"?sdkid="+e+"&lib="+t;var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(o,a)};
ttq.load('YOUR PIXEL ID WILL BE LOCATED HERE');
ttq.page();
}(window, document, 'ttq');
</script>
(/code)
(code)
// Users explicitly reject cookies
<span style="background-color: green;">ttq.revokeConsent() </span>
// After a certain period
// ...
// Users accept them later
<span style="background-color: green;">ttq.grantConsent() </span>
(/code)