PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.11.1
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.11.1
4.7.4 4.7.5 4.7.3 4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 All 95 releases
cookiebot / addons / controller / addons / google-analytics-plus / google-analytics-plus.php

google-analytics-plus.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 3.11.1, at addons/controller/addons/google-analytics-plus/google-analytics-plus.php

328 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace cookiebot_addons\controller\addons\google_analytics_plus;
4
5 use cookiebot_addons\controller\addons\Cookiebot_Addons_Interface;
6 use cookiebot_addons\lib\Cookie_Consent_Interface;
7 use cookiebot_addons\lib\Settings_Service_Interface;
8 use cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface;
9 use cookiebot_addons\lib\buffer\Buffer_Output_Interface;
10
11 class Google_Analytics_Plus implements Cookiebot_Addons_Interface {
12
13 /**
14 * @var Settings_Service_Interface
15 *
16 * @since 1.5.0
17 */
18 protected $settings;
19
20 /**
21 * @var Script_Loader_Tag_Interface
22 *
23 * @since 1.5.0
24 */
25 protected $script_loader_tag;
26
27 /**
28 * @var Cookie_Consent_Interface
29 *
30 * @since 1.5.0
31 */
32 public $cookie_consent;
33
34 /**
35 * @var Buffer_Output_Interface
36 *
37 * @since 1.5.0
38 */
39 protected $buffer_output;
40
41 /**
42 * constructor.
43 *
44 * @param $settings Settings_Service_Interface
45 * @param $script_loader_tag Script_Loader_Tag_Interface
46 * @param $cookie_consent Cookie_Consent_Interface
47 * @param $buffer_output Buffer_Output_Interface
48 *
49 * @since 1.5.0
50 */
51 public function __construct( Settings_Service_Interface $settings, Script_Loader_Tag_Interface $script_loader_tag, Cookie_Consent_Interface $cookie_consent, Buffer_Output_Interface $buffer_output ) {
52 $this->settings = $settings;
53 $this->script_loader_tag = $script_loader_tag;
54 $this->cookie_consent = $cookie_consent;
55 $this->buffer_output = $buffer_output;
56 }
57
58 /**
59 * Loads addon configuration
60 *
61 * @since 1.5.0
62 */
63 public function load_configuration() {
64 add_action( 'wp_loaded', array( $this, 'cookiebot_addon_google_analytics_async' ), 5 );
65 }
66
67 /**
68 * Disable scripts if state not accepted
69 *
70 * @since 1.5.0
71 */
72 public function cookiebot_addon_google_analytics_async() {
73 // Disable Analytify if cookie consent not allowed
74 $this->buffer_output->add_tag( 'wp_head', 10, array(
75 'GoogleAnalyticsObject' => $this->get_cookie_types(),
76 ), false );
77 }
78
79 /**
80 * Return addon/plugin name
81 *
82 * @return string
83 *
84 * @since 1.5.0
85 */
86 public function get_addon_name() {
87 return 'Google Analytics +';
88 }
89
90 /**
91 * Option name in the database
92 *
93 * @return string
94 *
95 * @since 1.5.0
96 */
97 public function get_option_name() {
98 return 'google_analytics_plus';
99 }
100
101 /**
102 * Plugin file name
103 *
104 * @return string
105 *
106 * @since 1.5.0
107 */
108 public function get_plugin_file() {
109 return 'google-analytics-async/google-analytics-async.php';
110 }
111
112 /**
113 * Returns checked cookie types
114 * @return mixed
115 *
116 * @since 1.5.0
117 */
118 public function get_cookie_types() {
119 return $this->settings->get_cookie_types( $this->get_option_name(), $this->get_default_cookie_types() );
120 }
121
122 /**
123 * Returns default cookie types
124 * @return array
125 *
126 * @since 1.5.0
127 */
128 public function get_default_cookie_types() {
129 return array( 'statistics' );
130 }
131
132 /**
133 * Check if plugin is activated and checked in the backend
134 *
135 * @since 1.5.0
136 */
137 public function is_addon_enabled() {
138 return $this->settings->is_addon_enabled( $this->get_option_name() );
139 }
140
141 /**
142 * Checks if addon is installed
143 *
144 * @since 1.5.0
145 */
146 public function is_addon_installed() {
147 return $this->settings->is_addon_installed( $this->get_plugin_file() );
148 }
149
150 /**
151 * Checks if addon is activated
152 *
153 * @since 1.5.0
154 */
155 public function is_addon_activated() {
156 return $this->settings->is_addon_activated( $this->get_plugin_file() );
157 }
158
159 /**
160 * Retrieves current installed version of the addon
161 *
162 * @return bool
163 *
164 * @since 2.2.1
165 */
166 public function get_addon_version() {
167 return $this->settings->get_addon_version( $this->get_plugin_file() );
168 }
169
170 /**
171 * Default placeholder content
172 *
173 * @return string
174 *
175 * @since 1.8.0
176 */
177 public function get_default_placeholder() {
178 return 'Please accept [renew_consent]%cookie_types[/renew_consent] cookies to watch this video.';
179 }
180
181 /**
182 * Get placeholder content
183 *
184 * This function will check following features:
185 * - Current language
186 *
187 * @param $src
188 *
189 * @return bool|mixed
190 *
191 * @since 1.8.0
192 */
193 public function get_placeholder( $src = '' ) {
194 return $this->settings->get_placeholder( $this->get_option_name(), $this->get_default_placeholder(), cookiebot_addons_output_cookie_types( $this->get_cookie_types() ), $src );
195 }
196
197 /**
198 * Checks if it does have custom placeholder content
199 *
200 * @return mixed
201 *
202 * @since 1.8.0
203 */
204 public function has_placeholder() {
205 return $this->settings->has_placeholder( $this->get_option_name() );
206 }
207
208 /**
209 * returns all placeholder contents
210 *
211 * @return mixed
212 *
213 * @since 1.8.0
214 */
215 public function get_placeholders() {
216 return $this->settings->get_placeholders( $this->get_option_name() );
217 }
218
219 /**
220 * Return true if the placeholder is enabled
221 *
222 * @return mixed
223 *
224 * @since 1.8.0
225 */
226 public function is_placeholder_enabled() {
227 return $this->settings->is_placeholder_enabled( $this->get_option_name() );
228 }
229
230 /**
231 * Adds extra information under the label
232 *
233 * @return string
234 *
235 * @since 1.8.0
236 */
237 public function get_extra_information() {
238 return '<p>' . esc_html__( 'Google Analytics is a simple, easy-to-use tool that helps website owners measure how users interact with website content', 'cookiebot-addons' ) . '</p>';
239 }
240
241 /**
242 * Returns the url of WordPress SVN repository or another link where we can verify the plugin file.
243 *
244 * @return boolean
245 *
246 * @since 1.8.0
247 */
248 public function get_svn_url() {
249 return false;
250 }
251
252 /**
253 * Placeholder helper overlay in the settings page.
254 *
255 * @return string
256 *
257 * @since 1.8.0
258 */
259 public function get_placeholder_helper() {
260 return '<p>Merge tags you can use in the placeholder text:</p><ul><li>%cookie_types - Lists required cookie types</li><li>[renew_consent]text[/renew_consent] - link to display cookie settings in frontend</li></ul>';
261 }
262
263
264 /**
265 * Returns parent class or false
266 *
267 * @return string|bool
268 *
269 * @since 2.1.3
270 */
271 public function get_parent_class() {
272 return get_parent_class( $this );
273 }
274
275 /**
276 * Action after enabling the addon on the settings page
277 *
278 * @since 2.2.0
279 */
280 public function post_hook_after_enabling() {
281 //do nothing
282 }
283
284 /**
285 * Cookiebot plugin is deactivated
286 *
287 * @since 2.2.0
288 */
289 public function plugin_deactivated() {
290 //do nothing
291 }
292
293 /**
294 * @return mixed
295 *
296 * @since 2.4.5
297 */
298 public function extra_available_addon_option() {
299 //do nothing
300 }
301
302 /**
303 * Returns boolean to enable/disable plugin by default
304 *
305 * @return bool
306 *
307 * @since 3.6.3
308 */
309 public function enable_by_default() {
310 return false;
311 }
312
313 /**
314 * Sets default settings for this addon
315 *
316 * @return array
317 *
318 * @since 3.6.3
319 */
320 public function get_default_enable_setting() {
321 return array(
322 'enabled' => 1,
323 'cookie_type' => $this->get_default_cookie_types(),
324 'placeholder' => $this->get_default_placeholder(),
325 );
326 }
327 }
328