开发者 |
RogierLankhorst
xkon aurooba mujuonly phpgeekdk paapst aahulsebos pputzer markwolters szepeviktor |
---|---|
更新时间 | 2025年1月29日 20:38 |
PHP版本: | 7.2 及以上 |
WordPress版本: | 6.7 |
版权: | GPL2 |
版权网址: | 版权信息 |
= javascript, tracking plugin =
//listen to consent change event
document.addEventListener("wp_listen_for_consent_change", function (e) {
var changedConsentCategory = e.detail;
for (var key in changedConsentCategory) {
if (changedConsentCategory.hasOwnProperty(key)) {
if (key === 'marketing' && changedConsentCategory[key] === 'allow') {
console.log("just given consent, track user")
}
}
}
});
//basic implementation of consent check:
if (wp_has_consent('marketing')){
activateMarketing();
console.log("set marketing stuff now!");
} else {
console.log("No marketing stuff please!");
}
= PHP =
//declare compliance with consent level API
$plugin = plugin_basename( FILE );
add_filter( "wp_consent_api_registered_{$plugin}", '__return_true' );
/**
No, this plugin provides a framework through which plugins can know if they are allowed to place cookies or track user data. The plugin requires both a consent management plugin for consent management and a plugin that follows the consent level as can be read from this API.
For each action that places cookies or tracks user data, you should consider what type of tracking takes place. There are 5 consent categories: functional, statistics-anonymous, statistics, preferences, marketing. These are explained below. Your code should check if consent has been given for the applicable category. If no cookie banner plugin is active, the Consent API will always return with consent (true). Please check out the example plugin, and the above code examples.
Statistics: Cookies or any other form of local storage that are used exclusively for statistical purposes (Analytics Cookies). Statistics-anonymous: Cookies or any other form of local storage that are used exclusively for anonymous statistical purposes (Anonymous Analytics Cookies), that are placed on a first party domain, and that do not allow identification of particular individuals. Marketing: Cookies or any other form of local storage required to create user profiles to send advertising or to track the user on a website or across websites for similar marketing purposes. Functional: The cookie or any other form of local storage is used for the sole purpose of carrying out the transmission of a communication over an electronic communications network; OR The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user. If cookies are disabled, the requested functionality will not be available. This makes them essential functional cookies. Preferences: Cookies or any other form of local storage that can not be seen as statistics, statistics-anonymous, marketing or functional, and where the technical storage or access is necessary for the legitimate purpose of storing preferences.