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 / wp-google-analytics-events / wp-google-analytics-events.php

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

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