You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -50,7 +51,7 @@ function my_add_cookie_category( $categories ) {
50
51
'enabled' => false, // it is advised to have categories disabled by default
51
52
'readonly' => false, // user should have always control over categories
52
53
'title' => 'Ads',
53
-
'description' => 'This site uses external services to display ads, and they might set some cookies.',
54
+
'description' => 'This site uses external services to display ads, and they might set some cookies.', // Check how to remove cookies from example below.
54
55
];
55
56
56
57
return $categories;
@@ -60,13 +61,68 @@ function my_add_cookie_category( $categories ) {
60
61
When adding new categories, the function itself is responsile for handling the translations for title and description.
61
62
62
63
There is also `air_cookie\categories\{category-key}` filter available to change the settings of indivual category.
function my_change_category_analytics( $edited_categoy ) {
67
+
$edited_category = [
68
+
'key' => 'analytics',
69
+
'enabled' => false,
70
+
'readonly' => false,
71
+
'title' => 'Analytics',
72
+
'description' => 'This site uses Google Analytics and it set some cookies. Read more about those from privacy policy.',
73
+
'auto_clear' => [ // Optional: auto_clear allows you to define cookies, which will be removed after changing consent. List all cookies to correct categories. Possible to use string or regex format (format is a bit different than official docs points out! https://cookieconsent.orestbida.com/reference/configuration-reference.html#category-autoclear).
74
+
'cookies' => [
75
+
[
76
+
'name' => '^(_ga)', // Match all cookies starting with '_ga',
77
+
],
78
+
[
79
+
'name' => '_gid',
80
+
],
81
+
],
82
+
],
83
+
];
84
+
85
+
return $edited_category;
86
+
}
87
+
```
88
+
89
+
ℹ If you add Google Analytics, remember [Google consent mode](https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced#upgrade-consent-v2) scripts.
63
90
91
+
```javascript
92
+
<script
93
+
type="text/plain"
94
+
data-category="analytics">
95
+
// Executed when the "analytics" category is enabled. Use this snippet after defining GA.
96
+
window.dataLayer=window.dataLayer|| [];
97
+
functiongtag() { dataLayer.push(arguments); }
98
+
gtag('consent', 'default', {
99
+
'ad_storage':'denied',
100
+
'analytics_storage':'granted',
101
+
'ad_user_data':'denied',
102
+
'ad_personalization':'denied'
103
+
});
104
+
</script>
105
+
106
+
<script
107
+
type="text/plain"
108
+
data-category="!analytics">
109
+
// Executed when the "analytics" category is disabled. Use this snippet after defining GA.
110
+
window.dataLayer=window.dataLayer|| [];
111
+
functiongtag() { dataLayer.push(arguments); }
112
+
gtag('consent', 'update', {
113
+
'ad_storage':'denied',
114
+
'analytics_storage':'denied',
115
+
'ad_user_data':'denied',
116
+
'ad_personalization':'denied'
117
+
});
118
+
</script>
119
+
```
64
120
## Loading scripts after cookies have been accepted
65
121
66
122
The easiest way to load external script is by altering the `script` tag to be:
The example above works only, if the script does not require any extra javascript to be executed after the script has been loaded. If you need to execute extra javascript, use the example below.
@@ -75,7 +131,7 @@ The example above works only, if the script does not require any extra javascrip
Setting names do follow the [CookieConsents option](https://github.com/orestbida/cookieconsent#apis--configuration-parameters) names. Some settings defaults are set to be different than the CookieConsent defaults:
293
+
Setting names do follow the [CookieConsents option](https://cookieconsent.orestbida.com/reference/configuration-reference.html#configuration-reference) names. Some settings defaults are set to be different than the CookieConsent defaults:
238
294
239
295
Setting | Value
240
296
--- | ---
241
-
`cookie_name` | air_cookie
242
-
`current_lang` | _value from polylang or locale option_
297
+
cookie/name | air_cookie
243
298
`revision` | _automatically calculated from cookie categories_
244
-
`page_scripts` | true
245
-
gui_options/consent_modal/layout | box
246
-
gui_options/consent_modal/position | bottom left
299
+
settings/language/default | _value from polylang or locale option_
300
+
guiOptions/consentModal/layout | cloud inline
301
+
guiOptions/consentModal/position | bottom center
247
302
248
303
You may change the settings with `air_cookie\settings` filter which contains all settings or `air_cookie\settings\{setting-name}` filter for indivual setting.
0 commit comments