@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | 66 | $this->base = MonsterInsights(); |
67 | - $this->tracking = monsterinsights_get_option( 'tracking_mode', false ); |
|
68 | - $events = monsterinsights_get_option( 'events_mode', false ); |
|
69 | - |
|
70 | - if ( $events === 'php' && ( $this->tracking === 'ga' || $this->tracking === 'analytics' ) ) { |
|
71 | - require_once plugin_dir_path( $this->base->file ) . 'includes/frontend/events/class-link.php'; |
|
72 | - add_filter( 'the_content', array( $this, 'the_content' ), 99 ); |
|
73 | - add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 ); |
|
74 | - add_filter( 'widget_text', array( $this, 'widget_content' ), 99 ); |
|
75 | - add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 ); |
|
76 | - add_filter( 'comment_text', array( $this, 'comment_text' ), 99 ); |
|
77 | - add_filter( 'wp_nav_menu', array( $this, 'nav_menu' ), 99 ); |
|
67 | + $this->tracking = monsterinsights_get_option('tracking_mode', false); |
|
68 | + $events = monsterinsights_get_option('events_mode', false); |
|
69 | + |
|
70 | + if ($events === 'php' && ($this->tracking === 'ga' || $this->tracking === 'analytics')) { |
|
71 | + require_once plugin_dir_path($this->base->file) . 'includes/frontend/events/class-link.php'; |
|
72 | + add_filter('the_content', array($this, 'the_content'), 99); |
|
73 | + add_filter('the_excerpt', array($this, 'the_content'), 99); |
|
74 | + add_filter('widget_text', array($this, 'widget_content'), 99); |
|
75 | + add_filter('wp_list_bookmarks', array($this, 'widget_content'), 99); |
|
76 | + add_filter('comment_text', array($this, 'comment_text'), 99); |
|
77 | + add_filter('wp_nav_menu', array($this, 'nav_menu'), 99); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | . '>' // matches the characters > literally |
108 | 108 | . '(.*)' // 7. matches any character (except newline) (Between 0 and * times) |
109 | 109 | . '<\/a>' // matches the characters </a> literally |
110 | - . '/isU'; // case insensitive, single line, ungreedy |
|
110 | + . '/isU'; // case insensitive, single line, ungreedy |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return string The resulting content. |
123 | 123 | */ |
124 | - public function the_content( $text ) { |
|
125 | - if ( ! is_feed() ) { |
|
126 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_article_link' ), $text ); |
|
124 | + public function the_content($text) { |
|
125 | + if ( ! is_feed()) { |
|
126 | + $text = preg_replace_callback($this->get_link_regex(), array($this, 'parse_article_link'), $text); |
|
127 | 127 | } |
128 | 128 | return $text; |
129 | 129 | } |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return string The parsed link string. |
140 | 140 | */ |
141 | - public function parse_article_link( $matches ) { |
|
142 | - return $this->parse_link( 'outbound-article', $matches ); |
|
141 | + public function parse_article_link($matches) { |
|
142 | + return $this->parse_link('outbound-article', $matches); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return string The resulting content. |
154 | 154 | */ |
155 | - public function widget_content( $text ) { |
|
156 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_widget_link' ), $text ); |
|
155 | + public function widget_content($text) { |
|
156 | + $text = preg_replace_callback($this->get_link_regex(), array($this, 'parse_widget_link'), $text); |
|
157 | 157 | return $text; |
158 | 158 | } |
159 | 159 | |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return string The parsed link string. |
169 | 169 | */ |
170 | - public function parse_widget_link( $matches ) { |
|
171 | - return $this->parse_link( 'outbound-widget', $matches ); |
|
170 | + public function parse_widget_link($matches) { |
|
171 | + return $this->parse_link('outbound-widget', $matches); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return string The resulting content. |
183 | 183 | */ |
184 | - public function nav_menu( $text ) { |
|
185 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_nav_menu_link' ), $text ); |
|
184 | + public function nav_menu($text) { |
|
185 | + $text = preg_replace_callback($this->get_link_regex(), array($this, 'parse_nav_menu_link'), $text); |
|
186 | 186 | return $text; |
187 | 187 | } |
188 | 188 | |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return string The parsed link string. |
198 | 198 | */ |
199 | - public function parse_nav_menu_link( $matches ) { |
|
200 | - return $this->parse_link( 'outbound-menu', $matches ); |
|
199 | + public function parse_nav_menu_link($matches) { |
|
200 | + return $this->parse_link('outbound-menu', $matches); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return string The resulting content. |
212 | 212 | */ |
213 | - public function comment_text( $text ) { |
|
214 | - if ( ! is_feed() ) { |
|
215 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_comment_link' ), $text ); |
|
213 | + public function comment_text($text) { |
|
214 | + if ( ! is_feed()) { |
|
215 | + $text = preg_replace_callback($this->get_link_regex(), array($this, 'parse_comment_link'), $text); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | return $text; |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return string The parsed link string. |
230 | 230 | */ |
231 | - public function parse_comment_link( $matches ) { |
|
232 | - return $this->parse_link( 'outbound-comment', $matches ); |
|
231 | + public function parse_comment_link($matches) { |
|
232 | + return $this->parse_link('outbound-comment', $matches); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | |
@@ -244,19 +244,19 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return string The resulting link attribute for onclick. |
246 | 246 | */ |
247 | - public function output_add_onclick( $link_attribute, $onclick ) { |
|
248 | - if ( preg_match( '/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { |
|
249 | - $onclick_with_double = str_replace( "'", '"', $onclick ); |
|
247 | + public function output_add_onclick($link_attribute, $onclick) { |
|
248 | + if (preg_match('/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches) > 0 && is_string($onclick)) { |
|
249 | + $onclick_with_double = str_replace("'", '"', $onclick); |
|
250 | 250 | $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\''; |
251 | 251 | $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
252 | 252 | |
253 | - $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute ); |
|
254 | - $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute ); |
|
253 | + $link_attribute = str_replace('onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute); |
|
254 | + $link_attribute = str_replace("onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute); |
|
255 | 255 | |
256 | 256 | return $link_attribute; |
257 | - } else if ( preg_match( '/onclick=[\'\"](.*?)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { // if not closed, see #33 |
|
258 | - $onclick_with_double = str_replace( "'", '"', $onclick ); |
|
259 | - if ( strlen( trim ( $matches[1] ) ) > 0 ) { |
|
257 | + } else if (preg_match('/onclick=[\'\"](.*?)[\'\"]/i', $link_attribute, $matches) > 0 && is_string($onclick)) { // if not closed, see #33 |
|
258 | + $onclick_with_double = str_replace("'", '"', $onclick); |
|
259 | + if (strlen(trim($matches[1])) > 0) { |
|
260 | 260 | $js_snippet_single = 'onclick=\'' . $matches[1] . '; ' . $onclick_with_double . '\''; |
261 | 261 | $js_snippet_double = 'onclick="' . $matches[1] . '; ' . $onclick . '"'; |
262 | 262 | } else { |
@@ -264,12 +264,12 @@ discard block |
||
264 | 264 | $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
265 | 265 | } |
266 | 266 | |
267 | - $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute ); |
|
268 | - $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute ); |
|
267 | + $link_attribute = str_replace('onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute); |
|
268 | + $link_attribute = str_replace("onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute); |
|
269 | 269 | |
270 | 270 | return $link_attribute; |
271 | 271 | } else { |
272 | - if ( ! empty( $onclick ) && is_string( $onclick ) ) { |
|
272 | + if ( ! empty($onclick) && is_string($onclick)) { |
|
273 | 273 | return 'onclick="' . $onclick . '" ' . $link_attribute; |
274 | 274 | } else { |
275 | 275 | return $link_attribute; |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @return string The resulting link (with pre-pended protocol). |
292 | 292 | */ |
293 | - public function make_full_url( $link ) { |
|
293 | + public function make_full_url($link) { |
|
294 | 294 | $protocol = ''; |
295 | - switch ( $link->type ) { |
|
295 | + switch ($link->type) { |
|
296 | 296 | case 'download': |
297 | 297 | case 'internal': |
298 | 298 | case 'internal-as-outbound': |
299 | 299 | case 'outbound': |
300 | - $protocol = ! empty( $link->protocol ) ? $link->protocol . '://' : ''; |
|
300 | + $protocol = ! empty($link->protocol) ? $link->protocol . '://' : ''; |
|
301 | 301 | break; |
302 | 302 | case 'email': |
303 | 303 | $protocol = 'mailto:'; |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return string The resulting link. |
320 | 320 | */ |
321 | - protected function parse_link( $category, $matches ) { |
|
322 | - return $this->output_parse_link( $category, new MonsterInsights_Link( $this->base, $category, $matches ) ); |
|
321 | + protected function parse_link($category, $matches) { |
|
322 | + return $this->output_parse_link($category, new MonsterInsights_Link($this->base, $category, $matches)); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | * @return string The internal label to use. |
332 | 332 | */ |
333 | 333 | protected function sanitize_internal_label() { |
334 | - $label = monsterinsights_get_option( 'track_internal_as_label', '' ); |
|
335 | - if ( ! empty( $label ) && is_string( $label ) ) { |
|
336 | - $label = trim( $label, ',' ); |
|
337 | - $label = trim( $label ); |
|
334 | + $label = monsterinsights_get_option('track_internal_as_label', ''); |
|
335 | + if ( ! empty($label) && is_string($label)) { |
|
336 | + $label = trim($label, ','); |
|
337 | + $label = trim($label); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // If the label is empty, set a default value |
341 | - if ( empty( $label ) ) { |
|
341 | + if (empty($label)) { |
|
342 | 342 | $label = 'int'; |
343 | 343 | } |
344 | 344 | |
@@ -356,64 +356,64 @@ discard block |
||
356 | 356 | * |
357 | 357 | * @return string The resultant new <a> tag to use. |
358 | 358 | */ |
359 | - protected function output_parse_link( $category, $link_target ) { |
|
359 | + protected function output_parse_link($category, $link_target) { |
|
360 | 360 | $object_name = '__gaTracker'; // $this->tracking === 'analytics' |
361 | - if ( $this->tracking === 'ga' ) { |
|
361 | + if ($this->tracking === 'ga') { |
|
362 | 362 | $object_name = '_gaq.push'; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // bail early for links that we can't handle |
366 | - if ( $link_target->type === 'internal' ) { |
|
366 | + if ($link_target->type === 'internal') { |
|
367 | 367 | return $link_target->hyperlink; |
368 | 368 | } |
369 | 369 | |
370 | 370 | $onclick = null; |
371 | - $full_url = $this->make_full_url( $link_target ); |
|
372 | - switch ( $link_target->type ) { |
|
371 | + $full_url = $this->make_full_url($link_target); |
|
372 | + switch ($link_target->type) { |
|
373 | 373 | case 'download': |
374 | - if ( $this->tracking === 'ga' ){ |
|
375 | - if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) { |
|
376 | - $onclick = $object_name . "(['_trackPageview','download/" . esc_js( $full_url ) . "']);"; |
|
374 | + if ($this->tracking === 'ga') { |
|
375 | + if (monsterinsights_get_option('track_download_as', '') === 'pageview') { |
|
376 | + $onclick = $object_name . "(['_trackPageview','download/" . esc_js($full_url) . "']);"; |
|
377 | 377 | } else { |
378 | - $onclick = $object_name . "(['_trackEvent','download','" . esc_js( $full_url ) . "']);"; |
|
378 | + $onclick = $object_name . "(['_trackEvent','download','" . esc_js($full_url) . "']);"; |
|
379 | 379 | } |
380 | 380 | } else { |
381 | - if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) { |
|
382 | - $onclick = $object_name . "('send', 'pageview', '" . esc_js( $full_url ) . "');"; |
|
381 | + if (monsterinsights_get_option('track_download_as', '') === 'pageview') { |
|
382 | + $onclick = $object_name . "('send', 'pageview', '" . esc_js($full_url) . "');"; |
|
383 | 383 | } else { |
384 | - $onclick = $object_name . "('send', 'event', 'download', '" . esc_js( $full_url ) . "');"; |
|
384 | + $onclick = $object_name . "('send', 'event', 'download', '" . esc_js($full_url) . "');"; |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | break; |
388 | 388 | case 'email': |
389 | - if ( $this->tracking === 'ga' ){ |
|
390 | - $onclick = $object_name . "(['_trackEvent','mailto','" . esc_js( $link_target->original_url ) . "']);"; |
|
389 | + if ($this->tracking === 'ga') { |
|
390 | + $onclick = $object_name . "(['_trackEvent','mailto','" . esc_js($link_target->original_url) . "']);"; |
|
391 | 391 | } else { |
392 | - $onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js( $link_target->original_url ) . "');"; |
|
392 | + $onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js($link_target->original_url) . "');"; |
|
393 | 393 | } |
394 | 394 | break; |
395 | 395 | case 'internal-as-outbound': |
396 | - if ( $this->tracking === 'ga' ){ |
|
396 | + if ($this->tracking === 'ga') { |
|
397 | 397 | $category = $this->sanitize_internal_label(); |
398 | - $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);"; |
|
398 | + $onclick = $object_name . "(['_trackEvent', '" . esc_js($link_target->category) . '-' . esc_js($category) . "', '" . esc_js($full_url) . "', '" . esc_js(strip_tags($link_target->link_text)) . "']);"; |
|
399 | 399 | } else { |
400 | 400 | $category = $this->sanitize_internal_label(); |
401 | - $onclick = $object_name . "('send', '" . esc_js( monsterinsights_get_option('track_download_as', '' ) ) . "', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');"; |
|
401 | + $onclick = $object_name . "('send', '" . esc_js(monsterinsights_get_option('track_download_as', '')) . "', '" . esc_js($link_target->category) . '-' . esc_js($category) . "', '" . esc_js($full_url) . "', '" . esc_js(strip_tags($link_target->link_text)) . "');"; |
|
402 | 402 | } |
403 | 403 | break; |
404 | 404 | case 'outbound': |
405 | - if ( $this->tracking === 'ga' ){ |
|
406 | - $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);"; |
|
405 | + if ($this->tracking === 'ga') { |
|
406 | + $onclick = $object_name . "(['_trackEvent', '" . esc_js($link_target->category) . "', '" . esc_js($full_url) . "', '" . esc_js(strip_tags($link_target->link_text)) . "']);"; |
|
407 | 407 | } else { |
408 | - $onclick = $object_name . "('send', 'event', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');"; |
|
408 | + $onclick = $object_name . "('send', 'event', '" . esc_js($link_target->category) . "', '" . esc_js($full_url) . "', '" . esc_js(strip_tags($link_target->link_text)) . "');"; |
|
409 | 409 | } |
410 | 410 | break; |
411 | 411 | } |
412 | 412 | |
413 | - $link_target->link_attributes = $this->output_add_onclick( $link_target->link_attributes, $onclick ); |
|
413 | + $link_target->link_attributes = $this->output_add_onclick($link_target->link_attributes, $onclick); |
|
414 | 414 | |
415 | - if ( ! empty( $link_target->link_attributes ) ) { |
|
416 | - return '<a href="' . $full_url . '" ' . trim( $link_target->link_attributes ) . '>' . $link_target->link_text . '</a>'; |
|
415 | + if ( ! empty($link_target->link_attributes)) { |
|
416 | + return '<a href="' . $full_url . '" ' . trim($link_target->link_attributes) . '>' . $link_target->link_text . '</a>'; |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | return '<a href="' . $full_url . '">' . $link_target->link_text . '</a>'; |
@@ -11,411 +11,411 @@ |
||
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
14 | - exit; |
|
14 | + exit; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | class MonsterInsights_Events_PHP { |
18 | 18 | |
19 | - /** |
|
20 | - * Holds the base class object. |
|
21 | - * |
|
22 | - * @since 6.0.0 |
|
23 | - * @access public |
|
24 | - * |
|
25 | - * @var object $base Base class object. |
|
26 | - */ |
|
27 | - public $base; |
|
19 | + /** |
|
20 | + * Holds the base class object. |
|
21 | + * |
|
22 | + * @since 6.0.0 |
|
23 | + * @access public |
|
24 | + * |
|
25 | + * @var object $base Base class object. |
|
26 | + */ |
|
27 | + public $base; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Holds the name of the events type. |
|
31 | - * |
|
32 | - * @since 6.0.0 |
|
33 | - * @access public |
|
34 | - * |
|
35 | - * @var string $name Name of the events type. |
|
36 | - */ |
|
37 | - public $name = 'php'; |
|
38 | - |
|
39 | - /** |
|
40 | - * Version of the events class. |
|
41 | - * |
|
42 | - * @since 6.0.0 |
|
43 | - * @access public |
|
44 | - * |
|
45 | - * @var string $version Version of the events class. |
|
46 | - */ |
|
47 | - public $version = '1.0.0'; |
|
48 | - |
|
49 | - /** |
|
50 | - * Holds the name of the tracking type. |
|
51 | - * |
|
52 | - * @since 6.0.0 |
|
53 | - * @access public |
|
54 | - * |
|
55 | - * @var string $name Name of the tracking type. |
|
56 | - */ |
|
57 | - public $tracking = 'ga'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Primary class constructor. |
|
61 | - * |
|
62 | - * @since 6.0.0 |
|
63 | - * @access public |
|
64 | - */ |
|
65 | - public function __construct() { |
|
66 | - $this->base = MonsterInsights(); |
|
67 | - $this->tracking = monsterinsights_get_option( 'tracking_mode', false ); |
|
68 | - $events = monsterinsights_get_option( 'events_mode', false ); |
|
69 | - |
|
70 | - if ( $events === 'php' && ( $this->tracking === 'ga' || $this->tracking === 'analytics' ) ) { |
|
71 | - require_once plugin_dir_path( $this->base->file ) . 'includes/frontend/events/class-link.php'; |
|
72 | - add_filter( 'the_content', array( $this, 'the_content' ), 99 ); |
|
73 | - add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 ); |
|
74 | - add_filter( 'widget_text', array( $this, 'widget_content' ), 99 ); |
|
75 | - add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 ); |
|
76 | - add_filter( 'comment_text', array( $this, 'comment_text' ), 99 ); |
|
77 | - add_filter( 'wp_nav_menu', array( $this, 'nav_menu' ), 99 ); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Get the regular expression used in ga.js and analytics.js PHP tracking to detect links |
|
83 | - * |
|
84 | - * @since 6.0.0 |
|
85 | - * @access protected |
|
86 | - * |
|
87 | - * @todo If we don't remove this soon, it'd be far superior to use a real DOM parser. |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - protected function get_link_regex() { |
|
92 | - return '/' |
|
93 | - . '<a' // matches the characters <a literally |
|
94 | - . '\s' // Match any sort of whitespace |
|
95 | - . '([^>]*)' // 1. match a single character not present in the list (Between 0 and * times) |
|
96 | - . '\s' // match any white space character |
|
97 | - . 'href=' // matches the characters href= literally |
|
98 | - . '([\'\"])' // 2. match a single or a double quote |
|
99 | - . '(' // 3. matches the link protocol (between 0 and 1 times) |
|
100 | - . '([a-zA-Z]+)' // 4. matches the link protocol name |
|
101 | - . ':' // matches the character : literally |
|
102 | - . '(?:\/\/)??' // matches the characters |
|
103 | - . ')??' // literally (between 0 and 1 times) |
|
104 | - . '(.*)' // 5. matches any character (except newline) (Between 0 and * times) |
|
105 | - . '\2' // matches the same quote (2nd capturing group) as was used to open the href value |
|
106 | - . '([^>]*)' // 6. match a single character not present in the list below |
|
107 | - . '>' // matches the characters > literally |
|
108 | - . '(.*)' // 7. matches any character (except newline) (Between 0 and * times) |
|
109 | - . '<\/a>' // matches the characters </a> literally |
|
110 | - . '/isU'; // case insensitive, single line, ungreedy |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Parse the_content or the_excerpt for links |
|
116 | - * |
|
117 | - * @since 6.0.0 |
|
118 | - * @access public |
|
119 | - * |
|
120 | - * @param string $text Text to parse |
|
121 | - * |
|
122 | - * @return string The resulting content. |
|
123 | - */ |
|
124 | - public function the_content( $text ) { |
|
125 | - if ( ! is_feed() ) { |
|
126 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_article_link' ), $text ); |
|
127 | - } |
|
128 | - return $text; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Parse article link |
|
133 | - * |
|
134 | - * @since 6.0.0 |
|
135 | - * @access public |
|
136 | - * |
|
137 | - * @param array $matches The matches for links within the content |
|
138 | - * |
|
139 | - * @return string The parsed link string. |
|
140 | - */ |
|
141 | - public function parse_article_link( $matches ) { |
|
142 | - return $this->parse_link( 'outbound-article', $matches ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Parse the widget content for links |
|
147 | - * |
|
148 | - * @since 6.0.0 |
|
149 | - * @access public |
|
150 | - * |
|
151 | - * @param string $text The text to parse. |
|
152 | - * |
|
153 | - * @return string The resulting content. |
|
154 | - */ |
|
155 | - public function widget_content( $text ) { |
|
156 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_widget_link' ), $text ); |
|
157 | - return $text; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Parse widget link |
|
162 | - * |
|
163 | - * @since 6.0.0 |
|
164 | - * @access public |
|
165 | - * |
|
166 | - * @param array $matches The matches for links within the content |
|
167 | - * |
|
168 | - * @return string The parsed link string. |
|
169 | - */ |
|
170 | - public function parse_widget_link( $matches ) { |
|
171 | - return $this->parse_link( 'outbound-widget', $matches ); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Parse the nav menu content for links |
|
176 | - * |
|
177 | - * @since 6.0.0 |
|
178 | - * @access public |
|
179 | - * |
|
180 | - * @param string $text The text to parse. |
|
181 | - * |
|
182 | - * @return string The resulting content. |
|
183 | - */ |
|
184 | - public function nav_menu( $text ) { |
|
185 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_nav_menu_link' ), $text ); |
|
186 | - return $text; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Parse nav menu link |
|
191 | - * |
|
192 | - * @since 6.0.0 |
|
193 | - * @access public |
|
194 | - * |
|
195 | - * @param array $matches The matches for links within the content |
|
196 | - * |
|
197 | - * @return string The parsed link string. |
|
198 | - */ |
|
199 | - public function parse_nav_menu_link( $matches ) { |
|
200 | - return $this->parse_link( 'outbound-menu', $matches ); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Parse comment text for links |
|
205 | - * |
|
206 | - * @since 6.0.0 |
|
207 | - * @access public |
|
208 | - * |
|
209 | - * @param string $text The text to parse. |
|
210 | - * |
|
211 | - * @return string The resulting content. |
|
212 | - */ |
|
213 | - public function comment_text( $text ) { |
|
214 | - if ( ! is_feed() ) { |
|
215 | - $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_comment_link' ), $text ); |
|
216 | - } |
|
217 | - |
|
218 | - return $text; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Parse comment link |
|
223 | - * |
|
224 | - * @since 6.0.0 |
|
225 | - * @access public |
|
226 | - * |
|
227 | - * @param array $matches The matches for links within the content |
|
228 | - * |
|
229 | - * @return string The parsed link string. |
|
230 | - */ |
|
231 | - public function parse_comment_link( $matches ) { |
|
232 | - return $this->parse_link( 'outbound-comment', $matches ); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Merge the existing onclick with a new one and append it |
|
238 | - * |
|
239 | - * @since 6.0.0 |
|
240 | - * @access public |
|
241 | - * |
|
242 | - * @param string $link_attribute The new onclick value to append. |
|
243 | - * @param string $onclick The existing onclick value. |
|
244 | - * |
|
245 | - * @return string The resulting link attribute for onclick. |
|
246 | - */ |
|
247 | - public function output_add_onclick( $link_attribute, $onclick ) { |
|
248 | - if ( preg_match( '/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { |
|
249 | - $onclick_with_double = str_replace( "'", '"', $onclick ); |
|
250 | - $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\''; |
|
251 | - $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
|
252 | - |
|
253 | - $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute ); |
|
254 | - $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute ); |
|
255 | - |
|
256 | - return $link_attribute; |
|
257 | - } else if ( preg_match( '/onclick=[\'\"](.*?)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { // if not closed, see #33 |
|
258 | - $onclick_with_double = str_replace( "'", '"', $onclick ); |
|
259 | - if ( strlen( trim ( $matches[1] ) ) > 0 ) { |
|
260 | - $js_snippet_single = 'onclick=\'' . $matches[1] . '; ' . $onclick_with_double . '\''; |
|
261 | - $js_snippet_double = 'onclick="' . $matches[1] . '; ' . $onclick . '"'; |
|
262 | - } else { |
|
263 | - $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\''; |
|
264 | - $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
|
265 | - } |
|
266 | - |
|
267 | - $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute ); |
|
268 | - $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute ); |
|
269 | - |
|
270 | - return $link_attribute; |
|
271 | - } else { |
|
272 | - if ( ! empty( $onclick ) && is_string( $onclick ) ) { |
|
273 | - return 'onclick="' . $onclick . '" ' . $link_attribute; |
|
274 | - } else { |
|
275 | - return $link_attribute; |
|
276 | - } |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Generate the full URL. |
|
282 | - * |
|
283 | - * Takes an existing link that's missing it's protocol |
|
284 | - * and pre-pends the protocol to it. |
|
285 | - * |
|
286 | - * @since 6.0.0 |
|
287 | - * @access public |
|
288 | - * |
|
289 | - * @param MonsterInsights_Link $link The protocol-less link. |
|
290 | - * |
|
291 | - * @return string The resulting link (with pre-pended protocol). |
|
292 | - */ |
|
293 | - public function make_full_url( $link ) { |
|
294 | - $protocol = ''; |
|
295 | - switch ( $link->type ) { |
|
296 | - case 'download': |
|
297 | - case 'internal': |
|
298 | - case 'internal-as-outbound': |
|
299 | - case 'outbound': |
|
300 | - $protocol = ! empty( $link->protocol ) ? $link->protocol . '://' : ''; |
|
301 | - break; |
|
302 | - case 'email': |
|
303 | - $protocol = 'mailto:'; |
|
304 | - break; |
|
305 | - } |
|
306 | - |
|
307 | - return $protocol . $link->original_url; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Get the output tracking link |
|
312 | - * |
|
313 | - * @since 6.0.0 |
|
314 | - * @access protected |
|
315 | - * |
|
316 | - * @param string $category The category of the link (ex: outbound-widget). |
|
317 | - * @param array $matches The matches found for links within the content. |
|
318 | - * |
|
319 | - * @return string The resulting link. |
|
320 | - */ |
|
321 | - protected function parse_link( $category, $matches ) { |
|
322 | - return $this->output_parse_link( $category, new MonsterInsights_Link( $this->base, $category, $matches ) ); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Trims the track_internal_as_label option to prevent commas and whitespaces. |
|
327 | - * |
|
328 | - * @since 6.0.0 |
|
329 | - * @access protected |
|
330 | - * |
|
331 | - * @return string The internal label to use. |
|
332 | - */ |
|
333 | - protected function sanitize_internal_label() { |
|
334 | - $label = monsterinsights_get_option( 'track_internal_as_label', '' ); |
|
335 | - if ( ! empty( $label ) && is_string( $label ) ) { |
|
336 | - $label = trim( $label, ',' ); |
|
337 | - $label = trim( $label ); |
|
338 | - } |
|
339 | - |
|
340 | - // If the label is empty, set a default value |
|
341 | - if ( empty( $label ) ) { |
|
342 | - $label = 'int'; |
|
343 | - } |
|
344 | - |
|
345 | - return $label; |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Create the event tracking link. |
|
350 | - * |
|
351 | - * @since 6.0.0 |
|
352 | - * @access protected |
|
353 | - * |
|
354 | - * @param string $category The category of the label (ex: outbound-widget ). |
|
355 | - * @param MonsterInsights_Link $link_target The link object we're working on. |
|
356 | - * |
|
357 | - * @return string The resultant new <a> tag to use. |
|
358 | - */ |
|
359 | - protected function output_parse_link( $category, $link_target ) { |
|
360 | - $object_name = '__gaTracker'; // $this->tracking === 'analytics' |
|
361 | - if ( $this->tracking === 'ga' ) { |
|
362 | - $object_name = '_gaq.push'; |
|
363 | - } |
|
364 | - |
|
365 | - // bail early for links that we can't handle |
|
366 | - if ( $link_target->type === 'internal' ) { |
|
367 | - return $link_target->hyperlink; |
|
368 | - } |
|
369 | - |
|
370 | - $onclick = null; |
|
371 | - $full_url = $this->make_full_url( $link_target ); |
|
372 | - switch ( $link_target->type ) { |
|
373 | - case 'download': |
|
374 | - if ( $this->tracking === 'ga' ){ |
|
375 | - if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) { |
|
376 | - $onclick = $object_name . "(['_trackPageview','download/" . esc_js( $full_url ) . "']);"; |
|
377 | - } else { |
|
378 | - $onclick = $object_name . "(['_trackEvent','download','" . esc_js( $full_url ) . "']);"; |
|
379 | - } |
|
380 | - } else { |
|
381 | - if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) { |
|
382 | - $onclick = $object_name . "('send', 'pageview', '" . esc_js( $full_url ) . "');"; |
|
383 | - } else { |
|
384 | - $onclick = $object_name . "('send', 'event', 'download', '" . esc_js( $full_url ) . "');"; |
|
385 | - } |
|
386 | - } |
|
387 | - break; |
|
388 | - case 'email': |
|
389 | - if ( $this->tracking === 'ga' ){ |
|
390 | - $onclick = $object_name . "(['_trackEvent','mailto','" . esc_js( $link_target->original_url ) . "']);"; |
|
391 | - } else { |
|
392 | - $onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js( $link_target->original_url ) . "');"; |
|
393 | - } |
|
394 | - break; |
|
395 | - case 'internal-as-outbound': |
|
396 | - if ( $this->tracking === 'ga' ){ |
|
397 | - $category = $this->sanitize_internal_label(); |
|
398 | - $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);"; |
|
399 | - } else { |
|
400 | - $category = $this->sanitize_internal_label(); |
|
401 | - $onclick = $object_name . "('send', '" . esc_js( monsterinsights_get_option('track_download_as', '' ) ) . "', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');"; |
|
402 | - } |
|
403 | - break; |
|
404 | - case 'outbound': |
|
405 | - if ( $this->tracking === 'ga' ){ |
|
406 | - $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);"; |
|
407 | - } else { |
|
408 | - $onclick = $object_name . "('send', 'event', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');"; |
|
409 | - } |
|
410 | - break; |
|
411 | - } |
|
412 | - |
|
413 | - $link_target->link_attributes = $this->output_add_onclick( $link_target->link_attributes, $onclick ); |
|
414 | - |
|
415 | - if ( ! empty( $link_target->link_attributes ) ) { |
|
416 | - return '<a href="' . $full_url . '" ' . trim( $link_target->link_attributes ) . '>' . $link_target->link_text . '</a>'; |
|
417 | - } |
|
418 | - |
|
419 | - return '<a href="' . $full_url . '">' . $link_target->link_text . '</a>'; |
|
420 | - } |
|
29 | + /** |
|
30 | + * Holds the name of the events type. |
|
31 | + * |
|
32 | + * @since 6.0.0 |
|
33 | + * @access public |
|
34 | + * |
|
35 | + * @var string $name Name of the events type. |
|
36 | + */ |
|
37 | + public $name = 'php'; |
|
38 | + |
|
39 | + /** |
|
40 | + * Version of the events class. |
|
41 | + * |
|
42 | + * @since 6.0.0 |
|
43 | + * @access public |
|
44 | + * |
|
45 | + * @var string $version Version of the events class. |
|
46 | + */ |
|
47 | + public $version = '1.0.0'; |
|
48 | + |
|
49 | + /** |
|
50 | + * Holds the name of the tracking type. |
|
51 | + * |
|
52 | + * @since 6.0.0 |
|
53 | + * @access public |
|
54 | + * |
|
55 | + * @var string $name Name of the tracking type. |
|
56 | + */ |
|
57 | + public $tracking = 'ga'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Primary class constructor. |
|
61 | + * |
|
62 | + * @since 6.0.0 |
|
63 | + * @access public |
|
64 | + */ |
|
65 | + public function __construct() { |
|
66 | + $this->base = MonsterInsights(); |
|
67 | + $this->tracking = monsterinsights_get_option( 'tracking_mode', false ); |
|
68 | + $events = monsterinsights_get_option( 'events_mode', false ); |
|
69 | + |
|
70 | + if ( $events === 'php' && ( $this->tracking === 'ga' || $this->tracking === 'analytics' ) ) { |
|
71 | + require_once plugin_dir_path( $this->base->file ) . 'includes/frontend/events/class-link.php'; |
|
72 | + add_filter( 'the_content', array( $this, 'the_content' ), 99 ); |
|
73 | + add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 ); |
|
74 | + add_filter( 'widget_text', array( $this, 'widget_content' ), 99 ); |
|
75 | + add_filter( 'wp_list_bookmarks', array( $this, 'widget_content' ), 99 ); |
|
76 | + add_filter( 'comment_text', array( $this, 'comment_text' ), 99 ); |
|
77 | + add_filter( 'wp_nav_menu', array( $this, 'nav_menu' ), 99 ); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Get the regular expression used in ga.js and analytics.js PHP tracking to detect links |
|
83 | + * |
|
84 | + * @since 6.0.0 |
|
85 | + * @access protected |
|
86 | + * |
|
87 | + * @todo If we don't remove this soon, it'd be far superior to use a real DOM parser. |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + protected function get_link_regex() { |
|
92 | + return '/' |
|
93 | + . '<a' // matches the characters <a literally |
|
94 | + . '\s' // Match any sort of whitespace |
|
95 | + . '([^>]*)' // 1. match a single character not present in the list (Between 0 and * times) |
|
96 | + . '\s' // match any white space character |
|
97 | + . 'href=' // matches the characters href= literally |
|
98 | + . '([\'\"])' // 2. match a single or a double quote |
|
99 | + . '(' // 3. matches the link protocol (between 0 and 1 times) |
|
100 | + . '([a-zA-Z]+)' // 4. matches the link protocol name |
|
101 | + . ':' // matches the character : literally |
|
102 | + . '(?:\/\/)??' // matches the characters |
|
103 | + . ')??' // literally (between 0 and 1 times) |
|
104 | + . '(.*)' // 5. matches any character (except newline) (Between 0 and * times) |
|
105 | + . '\2' // matches the same quote (2nd capturing group) as was used to open the href value |
|
106 | + . '([^>]*)' // 6. match a single character not present in the list below |
|
107 | + . '>' // matches the characters > literally |
|
108 | + . '(.*)' // 7. matches any character (except newline) (Between 0 and * times) |
|
109 | + . '<\/a>' // matches the characters </a> literally |
|
110 | + . '/isU'; // case insensitive, single line, ungreedy |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Parse the_content or the_excerpt for links |
|
116 | + * |
|
117 | + * @since 6.0.0 |
|
118 | + * @access public |
|
119 | + * |
|
120 | + * @param string $text Text to parse |
|
121 | + * |
|
122 | + * @return string The resulting content. |
|
123 | + */ |
|
124 | + public function the_content( $text ) { |
|
125 | + if ( ! is_feed() ) { |
|
126 | + $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_article_link' ), $text ); |
|
127 | + } |
|
128 | + return $text; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Parse article link |
|
133 | + * |
|
134 | + * @since 6.0.0 |
|
135 | + * @access public |
|
136 | + * |
|
137 | + * @param array $matches The matches for links within the content |
|
138 | + * |
|
139 | + * @return string The parsed link string. |
|
140 | + */ |
|
141 | + public function parse_article_link( $matches ) { |
|
142 | + return $this->parse_link( 'outbound-article', $matches ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Parse the widget content for links |
|
147 | + * |
|
148 | + * @since 6.0.0 |
|
149 | + * @access public |
|
150 | + * |
|
151 | + * @param string $text The text to parse. |
|
152 | + * |
|
153 | + * @return string The resulting content. |
|
154 | + */ |
|
155 | + public function widget_content( $text ) { |
|
156 | + $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_widget_link' ), $text ); |
|
157 | + return $text; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Parse widget link |
|
162 | + * |
|
163 | + * @since 6.0.0 |
|
164 | + * @access public |
|
165 | + * |
|
166 | + * @param array $matches The matches for links within the content |
|
167 | + * |
|
168 | + * @return string The parsed link string. |
|
169 | + */ |
|
170 | + public function parse_widget_link( $matches ) { |
|
171 | + return $this->parse_link( 'outbound-widget', $matches ); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Parse the nav menu content for links |
|
176 | + * |
|
177 | + * @since 6.0.0 |
|
178 | + * @access public |
|
179 | + * |
|
180 | + * @param string $text The text to parse. |
|
181 | + * |
|
182 | + * @return string The resulting content. |
|
183 | + */ |
|
184 | + public function nav_menu( $text ) { |
|
185 | + $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_nav_menu_link' ), $text ); |
|
186 | + return $text; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Parse nav menu link |
|
191 | + * |
|
192 | + * @since 6.0.0 |
|
193 | + * @access public |
|
194 | + * |
|
195 | + * @param array $matches The matches for links within the content |
|
196 | + * |
|
197 | + * @return string The parsed link string. |
|
198 | + */ |
|
199 | + public function parse_nav_menu_link( $matches ) { |
|
200 | + return $this->parse_link( 'outbound-menu', $matches ); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Parse comment text for links |
|
205 | + * |
|
206 | + * @since 6.0.0 |
|
207 | + * @access public |
|
208 | + * |
|
209 | + * @param string $text The text to parse. |
|
210 | + * |
|
211 | + * @return string The resulting content. |
|
212 | + */ |
|
213 | + public function comment_text( $text ) { |
|
214 | + if ( ! is_feed() ) { |
|
215 | + $text = preg_replace_callback( $this->get_link_regex(), array( $this, 'parse_comment_link' ), $text ); |
|
216 | + } |
|
217 | + |
|
218 | + return $text; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Parse comment link |
|
223 | + * |
|
224 | + * @since 6.0.0 |
|
225 | + * @access public |
|
226 | + * |
|
227 | + * @param array $matches The matches for links within the content |
|
228 | + * |
|
229 | + * @return string The parsed link string. |
|
230 | + */ |
|
231 | + public function parse_comment_link( $matches ) { |
|
232 | + return $this->parse_link( 'outbound-comment', $matches ); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Merge the existing onclick with a new one and append it |
|
238 | + * |
|
239 | + * @since 6.0.0 |
|
240 | + * @access public |
|
241 | + * |
|
242 | + * @param string $link_attribute The new onclick value to append. |
|
243 | + * @param string $onclick The existing onclick value. |
|
244 | + * |
|
245 | + * @return string The resulting link attribute for onclick. |
|
246 | + */ |
|
247 | + public function output_add_onclick( $link_attribute, $onclick ) { |
|
248 | + if ( preg_match( '/onclick=[\'\"](.*?;)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { |
|
249 | + $onclick_with_double = str_replace( "'", '"', $onclick ); |
|
250 | + $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\''; |
|
251 | + $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
|
252 | + |
|
253 | + $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute ); |
|
254 | + $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute ); |
|
255 | + |
|
256 | + return $link_attribute; |
|
257 | + } else if ( preg_match( '/onclick=[\'\"](.*?)[\'\"]/i', $link_attribute, $matches ) > 0 && is_string( $onclick ) ) { // if not closed, see #33 |
|
258 | + $onclick_with_double = str_replace( "'", '"', $onclick ); |
|
259 | + if ( strlen( trim ( $matches[1] ) ) > 0 ) { |
|
260 | + $js_snippet_single = 'onclick=\'' . $matches[1] . '; ' . $onclick_with_double . '\''; |
|
261 | + $js_snippet_double = 'onclick="' . $matches[1] . '; ' . $onclick . '"'; |
|
262 | + } else { |
|
263 | + $js_snippet_single = 'onclick=\'' . $matches[1] . ' ' . $onclick_with_double . '\''; |
|
264 | + $js_snippet_double = 'onclick="' . $matches[1] . ' ' . $onclick . '"'; |
|
265 | + } |
|
266 | + |
|
267 | + $link_attribute = str_replace( 'onclick="' . $matches[1] . '"', $js_snippet_double, $link_attribute ); |
|
268 | + $link_attribute = str_replace( "onclick='" . $matches[1] . "'", $js_snippet_single, $link_attribute ); |
|
269 | + |
|
270 | + return $link_attribute; |
|
271 | + } else { |
|
272 | + if ( ! empty( $onclick ) && is_string( $onclick ) ) { |
|
273 | + return 'onclick="' . $onclick . '" ' . $link_attribute; |
|
274 | + } else { |
|
275 | + return $link_attribute; |
|
276 | + } |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Generate the full URL. |
|
282 | + * |
|
283 | + * Takes an existing link that's missing it's protocol |
|
284 | + * and pre-pends the protocol to it. |
|
285 | + * |
|
286 | + * @since 6.0.0 |
|
287 | + * @access public |
|
288 | + * |
|
289 | + * @param MonsterInsights_Link $link The protocol-less link. |
|
290 | + * |
|
291 | + * @return string The resulting link (with pre-pended protocol). |
|
292 | + */ |
|
293 | + public function make_full_url( $link ) { |
|
294 | + $protocol = ''; |
|
295 | + switch ( $link->type ) { |
|
296 | + case 'download': |
|
297 | + case 'internal': |
|
298 | + case 'internal-as-outbound': |
|
299 | + case 'outbound': |
|
300 | + $protocol = ! empty( $link->protocol ) ? $link->protocol . '://' : ''; |
|
301 | + break; |
|
302 | + case 'email': |
|
303 | + $protocol = 'mailto:'; |
|
304 | + break; |
|
305 | + } |
|
306 | + |
|
307 | + return $protocol . $link->original_url; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get the output tracking link |
|
312 | + * |
|
313 | + * @since 6.0.0 |
|
314 | + * @access protected |
|
315 | + * |
|
316 | + * @param string $category The category of the link (ex: outbound-widget). |
|
317 | + * @param array $matches The matches found for links within the content. |
|
318 | + * |
|
319 | + * @return string The resulting link. |
|
320 | + */ |
|
321 | + protected function parse_link( $category, $matches ) { |
|
322 | + return $this->output_parse_link( $category, new MonsterInsights_Link( $this->base, $category, $matches ) ); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Trims the track_internal_as_label option to prevent commas and whitespaces. |
|
327 | + * |
|
328 | + * @since 6.0.0 |
|
329 | + * @access protected |
|
330 | + * |
|
331 | + * @return string The internal label to use. |
|
332 | + */ |
|
333 | + protected function sanitize_internal_label() { |
|
334 | + $label = monsterinsights_get_option( 'track_internal_as_label', '' ); |
|
335 | + if ( ! empty( $label ) && is_string( $label ) ) { |
|
336 | + $label = trim( $label, ',' ); |
|
337 | + $label = trim( $label ); |
|
338 | + } |
|
339 | + |
|
340 | + // If the label is empty, set a default value |
|
341 | + if ( empty( $label ) ) { |
|
342 | + $label = 'int'; |
|
343 | + } |
|
344 | + |
|
345 | + return $label; |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Create the event tracking link. |
|
350 | + * |
|
351 | + * @since 6.0.0 |
|
352 | + * @access protected |
|
353 | + * |
|
354 | + * @param string $category The category of the label (ex: outbound-widget ). |
|
355 | + * @param MonsterInsights_Link $link_target The link object we're working on. |
|
356 | + * |
|
357 | + * @return string The resultant new <a> tag to use. |
|
358 | + */ |
|
359 | + protected function output_parse_link( $category, $link_target ) { |
|
360 | + $object_name = '__gaTracker'; // $this->tracking === 'analytics' |
|
361 | + if ( $this->tracking === 'ga' ) { |
|
362 | + $object_name = '_gaq.push'; |
|
363 | + } |
|
364 | + |
|
365 | + // bail early for links that we can't handle |
|
366 | + if ( $link_target->type === 'internal' ) { |
|
367 | + return $link_target->hyperlink; |
|
368 | + } |
|
369 | + |
|
370 | + $onclick = null; |
|
371 | + $full_url = $this->make_full_url( $link_target ); |
|
372 | + switch ( $link_target->type ) { |
|
373 | + case 'download': |
|
374 | + if ( $this->tracking === 'ga' ){ |
|
375 | + if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) { |
|
376 | + $onclick = $object_name . "(['_trackPageview','download/" . esc_js( $full_url ) . "']);"; |
|
377 | + } else { |
|
378 | + $onclick = $object_name . "(['_trackEvent','download','" . esc_js( $full_url ) . "']);"; |
|
379 | + } |
|
380 | + } else { |
|
381 | + if ( monsterinsights_get_option('track_download_as', '' ) === 'pageview' ) { |
|
382 | + $onclick = $object_name . "('send', 'pageview', '" . esc_js( $full_url ) . "');"; |
|
383 | + } else { |
|
384 | + $onclick = $object_name . "('send', 'event', 'download', '" . esc_js( $full_url ) . "');"; |
|
385 | + } |
|
386 | + } |
|
387 | + break; |
|
388 | + case 'email': |
|
389 | + if ( $this->tracking === 'ga' ){ |
|
390 | + $onclick = $object_name . "(['_trackEvent','mailto','" . esc_js( $link_target->original_url ) . "']);"; |
|
391 | + } else { |
|
392 | + $onclick = $object_name . "('send', 'event', 'mailto', '" . esc_js( $link_target->original_url ) . "');"; |
|
393 | + } |
|
394 | + break; |
|
395 | + case 'internal-as-outbound': |
|
396 | + if ( $this->tracking === 'ga' ){ |
|
397 | + $category = $this->sanitize_internal_label(); |
|
398 | + $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);"; |
|
399 | + } else { |
|
400 | + $category = $this->sanitize_internal_label(); |
|
401 | + $onclick = $object_name . "('send', '" . esc_js( monsterinsights_get_option('track_download_as', '' ) ) . "', '" . esc_js( $link_target->category ) . '-' . esc_js( $category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');"; |
|
402 | + } |
|
403 | + break; |
|
404 | + case 'outbound': |
|
405 | + if ( $this->tracking === 'ga' ){ |
|
406 | + $onclick = $object_name . "(['_trackEvent', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "']);"; |
|
407 | + } else { |
|
408 | + $onclick = $object_name . "('send', 'event', '" . esc_js( $link_target->category ) . "', '" . esc_js( $full_url ) . "', '" . esc_js( strip_tags( $link_target->link_text ) ) . "');"; |
|
409 | + } |
|
410 | + break; |
|
411 | + } |
|
412 | + |
|
413 | + $link_target->link_attributes = $this->output_add_onclick( $link_target->link_attributes, $onclick ); |
|
414 | + |
|
415 | + if ( ! empty( $link_target->link_attributes ) ) { |
|
416 | + return '<a href="' . $full_url . '" ' . trim( $link_target->link_attributes ) . '>' . $link_target->link_text . '</a>'; |
|
417 | + } |
|
418 | + |
|
419 | + return '<a href="' . $full_url . '">' . $link_target->link_text . '</a>'; |
|
420 | + } |
|
421 | 421 | } |
422 | 422 | \ No newline at end of file |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | * @param string $category The category of the url (ex: outbound-link). |
136 | 136 | * @param array $matches Matches found for the hyperlink. |
137 | 137 | */ |
138 | - public function __construct( $base, $category, $matches ) { |
|
139 | - $this->base = $base; |
|
138 | + public function __construct($base, $category, $matches) { |
|
139 | + $this->base = $base; |
|
140 | 140 | $this->category = $category; |
141 | 141 | $this->original_url = $matches[5]; |
142 | 142 | $this->domain = $this->get_domain(); |
143 | - $this->extension = substr( strrchr( $this->original_url, '.' ), 1 ); |
|
143 | + $this->extension = substr(strrchr($this->original_url, '.'), 1); |
|
144 | 144 | $this->host = $this->domain['host']; |
145 | - $this->link_attributes = trim( $matches[1] . ' ' . $matches[6] ); |
|
145 | + $this->link_attributes = trim($matches[1] . ' ' . $matches[6]); |
|
146 | 146 | $this->link_text = $matches[7]; |
147 | 147 | $this->hyperlink = $matches[0]; |
148 | 148 | $this->protocol = $matches[4]; |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | $hostPattern = '/^(https?:\/\/)?([^\/]+)/i'; |
161 | 161 | $domainPatternUS = '/[^\.\/]+\.[^\.\/]+$/'; |
162 | 162 | $domainPatternUK = '/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/'; |
163 | - $matching = preg_match( $hostPattern, $this->original_url, $matches ); |
|
164 | - if ( $matching ) { |
|
163 | + $matching = preg_match($hostPattern, $this->original_url, $matches); |
|
164 | + if ($matching) { |
|
165 | 165 | $host = $matches[2]; |
166 | - if ( preg_match( '/.*\..*\..*\..*$/', $host ) ) { |
|
167 | - preg_match( $domainPatternUK, $host, $matches ); |
|
166 | + if (preg_match('/.*\..*\..*\..*$/', $host)) { |
|
167 | + preg_match($domainPatternUK, $host, $matches); |
|
168 | 168 | } else { |
169 | - preg_match( $domainPatternUS, $host, $matches ); |
|
169 | + preg_match($domainPatternUS, $host, $matches); |
|
170 | 170 | } |
171 | 171 | |
172 | - if ( isset( $matches[0] ) ) { |
|
173 | - return array( 'domain' => $matches[0], 'host' => $host ); |
|
172 | + if (isset($matches[0])) { |
|
173 | + return array('domain' => $matches[0], 'host' => $host); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | return false; |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | * @return string The type of link. |
186 | 186 | */ |
187 | 187 | protected function get_target_type() { |
188 | - $download_extensions = explode( ',', str_replace( '.', '', monsterinsights_get_option( 'extensions_of_files', '' ) ) ); |
|
189 | - $download_extensions = array_map( 'trim', $download_extensions ); |
|
188 | + $download_extensions = explode(',', str_replace('.', '', monsterinsights_get_option('extensions_of_files', ''))); |
|
189 | + $download_extensions = array_map('trim', $download_extensions); |
|
190 | 190 | $full_url = $this->protocol . '://' . $this->domain['domain']; |
191 | - if ( $this->protocol == 'mailto' ) { |
|
191 | + if ($this->protocol == 'mailto') { |
|
192 | 192 | $type = 'email'; |
193 | - } else if ( in_array( $this->extension, $download_extensions ) ) { |
|
193 | + } else if (in_array($this->extension, $download_extensions)) { |
|
194 | 194 | $type = 'download'; |
195 | - } else if ( in_array( $this->protocol, array( 'http', 'https') ) && $full_url !== rtrim( home_url(), '\/' ) ) { |
|
195 | + } else if (in_array($this->protocol, array('http', 'https')) && $full_url !== rtrim(home_url(), '\/')) { |
|
196 | 196 | $type = 'outbound'; |
197 | 197 | } else { |
198 | 198 | $type = $this->parse_internal_link_type(); |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * @return string The type of link. |
210 | 210 | */ |
211 | 211 | protected function parse_internal_link_type() { |
212 | - $out_links = explode( ',', monsterinsights_get_option( 'track_internal_as_outbound', '' ) ); |
|
213 | - $out_links = array_unique( array_map( 'trim', $out_links ) ); |
|
214 | - if ( ! empty( $this->original_url ) && count( $out_links ) >= 1 ) { |
|
215 | - foreach ( $out_links as $out ) { |
|
216 | - if ( ! empty( $out ) && strpos( $this->original_url, $out ) !== false ) { |
|
212 | + $out_links = explode(',', monsterinsights_get_option('track_internal_as_outbound', '')); |
|
213 | + $out_links = array_unique(array_map('trim', $out_links)); |
|
214 | + if ( ! empty($this->original_url) && count($out_links) >= 1) { |
|
215 | + foreach ($out_links as $out) { |
|
216 | + if ( ! empty($out) && strpos($this->original_url, $out) !== false) { |
|
217 | 217 | return 'internal-as-outbound'; |
218 | 218 | } |
219 | 219 | } |
@@ -11,213 +11,213 @@ |
||
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
14 | - exit; |
|
14 | + exit; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | class MonsterInsights_Link { |
18 | - /** |
|
19 | - * Holds the base class object. |
|
20 | - * |
|
21 | - * @since 6.0.0 |
|
22 | - * @access public |
|
23 | - * |
|
24 | - * @var object $base Base class object. |
|
25 | - */ |
|
26 | - public $base; |
|
18 | + /** |
|
19 | + * Holds the base class object. |
|
20 | + * |
|
21 | + * @since 6.0.0 |
|
22 | + * @access public |
|
23 | + * |
|
24 | + * @var object $base Base class object. |
|
25 | + */ |
|
26 | + public $base; |
|
27 | 27 | |
28 | - /** |
|
29 | - * The category of the link. |
|
30 | - * |
|
31 | - * @since 6.0.0 |
|
32 | - * @access public |
|
33 | - * |
|
34 | - * @var string $category Category of the link. |
|
35 | - */ |
|
36 | - public $category; |
|
28 | + /** |
|
29 | + * The category of the link. |
|
30 | + * |
|
31 | + * @since 6.0.0 |
|
32 | + * @access public |
|
33 | + * |
|
34 | + * @var string $category Category of the link. |
|
35 | + */ |
|
36 | + public $category; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the domain and host. False if empty. |
|
40 | - * |
|
41 | - * @since 6.0.0 |
|
42 | - * @access public |
|
43 | - * |
|
44 | - * @var array|bool $domain Domain of link. |
|
45 | - */ |
|
46 | - public $domain; |
|
38 | + /** |
|
39 | + * Get the domain and host. False if empty. |
|
40 | + * |
|
41 | + * @since 6.0.0 |
|
42 | + * @access public |
|
43 | + * |
|
44 | + * @var array|bool $domain Domain of link. |
|
45 | + */ |
|
46 | + public $domain; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Extension of the url. |
|
50 | - * |
|
51 | - * @since 6.0.0 |
|
52 | - * @access public |
|
53 | - * |
|
54 | - * @var string $extension File extension in given url. |
|
55 | - */ |
|
56 | - public $extension; |
|
48 | + /** |
|
49 | + * Extension of the url. |
|
50 | + * |
|
51 | + * @since 6.0.0 |
|
52 | + * @access public |
|
53 | + * |
|
54 | + * @var string $extension File extension in given url. |
|
55 | + */ |
|
56 | + public $extension; |
|
57 | 57 | |
58 | - /** |
|
59 | - * Host of the URL. |
|
60 | - * |
|
61 | - * @since 6.0.0 |
|
62 | - * @access public |
|
63 | - * |
|
64 | - * @var string $host Host of given url. |
|
65 | - */ |
|
66 | - public $host; |
|
58 | + /** |
|
59 | + * Host of the URL. |
|
60 | + * |
|
61 | + * @since 6.0.0 |
|
62 | + * @access public |
|
63 | + * |
|
64 | + * @var string $host Host of given url. |
|
65 | + */ |
|
66 | + public $host; |
|
67 | 67 | |
68 | - /** |
|
69 | - * The link attributes of the URL. |
|
70 | - * |
|
71 | - * @since 6.0.0 |
|
72 | - * @access public |
|
73 | - * |
|
74 | - * @var string $link_attributes Link attributes of given hyperlink. |
|
75 | - */ |
|
76 | - public $link_attributes; |
|
68 | + /** |
|
69 | + * The link attributes of the URL. |
|
70 | + * |
|
71 | + * @since 6.0.0 |
|
72 | + * @access public |
|
73 | + * |
|
74 | + * @var string $link_attributes Link attributes of given hyperlink. |
|
75 | + */ |
|
76 | + public $link_attributes; |
|
77 | 77 | |
78 | - /** |
|
79 | - * The text of the link. |
|
80 | - * |
|
81 | - * @since 6.0.0 |
|
82 | - * @access public |
|
83 | - * |
|
84 | - * @var string $link_text Text of given hyperlink. |
|
85 | - */ |
|
86 | - public $link_text; |
|
78 | + /** |
|
79 | + * The text of the link. |
|
80 | + * |
|
81 | + * @since 6.0.0 |
|
82 | + * @access public |
|
83 | + * |
|
84 | + * @var string $link_text Text of given hyperlink. |
|
85 | + */ |
|
86 | + public $link_text; |
|
87 | 87 | |
88 | - /** |
|
89 | - * The full url without the protocol. |
|
90 | - * |
|
91 | - * @since 6.0.0 |
|
92 | - * @access public |
|
93 | - * |
|
94 | - * @var string $original_url The full url without the protocol. |
|
95 | - */ |
|
96 | - public $original_url; |
|
88 | + /** |
|
89 | + * The full url without the protocol. |
|
90 | + * |
|
91 | + * @since 6.0.0 |
|
92 | + * @access public |
|
93 | + * |
|
94 | + * @var string $original_url The full url without the protocol. |
|
95 | + */ |
|
96 | + public $original_url; |
|
97 | 97 | |
98 | - /** |
|
99 | - * The protocol of the url. |
|
100 | - * |
|
101 | - * @since 6.0.0 |
|
102 | - * @access public |
|
103 | - * |
|
104 | - * @var string $protocol The protocol of the link. |
|
105 | - */ |
|
106 | - public $protocol; |
|
98 | + /** |
|
99 | + * The protocol of the url. |
|
100 | + * |
|
101 | + * @since 6.0.0 |
|
102 | + * @access public |
|
103 | + * |
|
104 | + * @var string $protocol The protocol of the link. |
|
105 | + */ |
|
106 | + public $protocol; |
|
107 | 107 | |
108 | - /** |
|
109 | - * The type of the URL - for example: internal as outbound, outbound, internal. |
|
110 | - * |
|
111 | - * @since 6.0.0 |
|
112 | - * @access public |
|
113 | - * |
|
114 | - * @var string $type The type of the link. |
|
115 | - */ |
|
116 | - public $type; |
|
108 | + /** |
|
109 | + * The type of the URL - for example: internal as outbound, outbound, internal. |
|
110 | + * |
|
111 | + * @since 6.0.0 |
|
112 | + * @access public |
|
113 | + * |
|
114 | + * @var string $type The type of the link. |
|
115 | + */ |
|
116 | + public $type; |
|
117 | 117 | |
118 | - /** |
|
119 | - * The full hyperlink. |
|
120 | - * |
|
121 | - * @since 6.0.0 |
|
122 | - * @access public |
|
123 | - * |
|
124 | - * @var string $hyperlink The hyperlink. |
|
125 | - */ |
|
126 | - public $hyperlink; |
|
118 | + /** |
|
119 | + * The full hyperlink. |
|
120 | + * |
|
121 | + * @since 6.0.0 |
|
122 | + * @access public |
|
123 | + * |
|
124 | + * @var string $hyperlink The hyperlink. |
|
125 | + */ |
|
126 | + public $hyperlink; |
|
127 | 127 | |
128 | - /** |
|
129 | - * Constructor of the class. |
|
130 | - * |
|
131 | - * @since 6.0.0 |
|
132 | - * @access public |
|
133 | - * |
|
134 | - * @param MonsterInsights $base The base plugin object. |
|
135 | - * @param string $category The category of the url (ex: outbound-link). |
|
136 | - * @param array $matches Matches found for the hyperlink. |
|
137 | - */ |
|
138 | - public function __construct( $base, $category, $matches ) { |
|
139 | - $this->base = $base; |
|
140 | - $this->category = $category; |
|
141 | - $this->original_url = $matches[5]; |
|
142 | - $this->domain = $this->get_domain(); |
|
143 | - $this->extension = substr( strrchr( $this->original_url, '.' ), 1 ); |
|
144 | - $this->host = $this->domain['host']; |
|
145 | - $this->link_attributes = trim( $matches[1] . ' ' . $matches[6] ); |
|
146 | - $this->link_text = $matches[7]; |
|
147 | - $this->hyperlink = $matches[0]; |
|
148 | - $this->protocol = $matches[4]; |
|
149 | - $this->type = $this->get_target_type(); |
|
150 | - } |
|
151 | - /** |
|
152 | - * Parse the domain. |
|
153 | - * |
|
154 | - * @since 6.0.0 |
|
155 | - * @access public |
|
156 | - * |
|
157 | - * @return array|bool The domain/host of the link. |
|
158 | - */ |
|
159 | - public function get_domain() { |
|
160 | - $hostPattern = '/^(https?:\/\/)?([^\/]+)/i'; |
|
161 | - $domainPatternUS = '/[^\.\/]+\.[^\.\/]+$/'; |
|
162 | - $domainPatternUK = '/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/'; |
|
163 | - $matching = preg_match( $hostPattern, $this->original_url, $matches ); |
|
164 | - if ( $matching ) { |
|
165 | - $host = $matches[2]; |
|
166 | - if ( preg_match( '/.*\..*\..*\..*$/', $host ) ) { |
|
167 | - preg_match( $domainPatternUK, $host, $matches ); |
|
168 | - } else { |
|
169 | - preg_match( $domainPatternUS, $host, $matches ); |
|
170 | - } |
|
128 | + /** |
|
129 | + * Constructor of the class. |
|
130 | + * |
|
131 | + * @since 6.0.0 |
|
132 | + * @access public |
|
133 | + * |
|
134 | + * @param MonsterInsights $base The base plugin object. |
|
135 | + * @param string $category The category of the url (ex: outbound-link). |
|
136 | + * @param array $matches Matches found for the hyperlink. |
|
137 | + */ |
|
138 | + public function __construct( $base, $category, $matches ) { |
|
139 | + $this->base = $base; |
|
140 | + $this->category = $category; |
|
141 | + $this->original_url = $matches[5]; |
|
142 | + $this->domain = $this->get_domain(); |
|
143 | + $this->extension = substr( strrchr( $this->original_url, '.' ), 1 ); |
|
144 | + $this->host = $this->domain['host']; |
|
145 | + $this->link_attributes = trim( $matches[1] . ' ' . $matches[6] ); |
|
146 | + $this->link_text = $matches[7]; |
|
147 | + $this->hyperlink = $matches[0]; |
|
148 | + $this->protocol = $matches[4]; |
|
149 | + $this->type = $this->get_target_type(); |
|
150 | + } |
|
151 | + /** |
|
152 | + * Parse the domain. |
|
153 | + * |
|
154 | + * @since 6.0.0 |
|
155 | + * @access public |
|
156 | + * |
|
157 | + * @return array|bool The domain/host of the link. |
|
158 | + */ |
|
159 | + public function get_domain() { |
|
160 | + $hostPattern = '/^(https?:\/\/)?([^\/]+)/i'; |
|
161 | + $domainPatternUS = '/[^\.\/]+\.[^\.\/]+$/'; |
|
162 | + $domainPatternUK = '/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/'; |
|
163 | + $matching = preg_match( $hostPattern, $this->original_url, $matches ); |
|
164 | + if ( $matching ) { |
|
165 | + $host = $matches[2]; |
|
166 | + if ( preg_match( '/.*\..*\..*\..*$/', $host ) ) { |
|
167 | + preg_match( $domainPatternUK, $host, $matches ); |
|
168 | + } else { |
|
169 | + preg_match( $domainPatternUS, $host, $matches ); |
|
170 | + } |
|
171 | 171 | |
172 | - if ( isset( $matches[0] ) ) { |
|
173 | - return array( 'domain' => $matches[0], 'host' => $host ); |
|
174 | - } |
|
175 | - } |
|
176 | - return false; |
|
177 | - } |
|
172 | + if ( isset( $matches[0] ) ) { |
|
173 | + return array( 'domain' => $matches[0], 'host' => $host ); |
|
174 | + } |
|
175 | + } |
|
176 | + return false; |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Getting the type for current target. |
|
181 | - * |
|
182 | - * @since 6.0.0 |
|
183 | - * @access protected |
|
184 | - * |
|
185 | - * @return string The type of link. |
|
186 | - */ |
|
187 | - protected function get_target_type() { |
|
188 | - $download_extensions = explode( ',', str_replace( '.', '', monsterinsights_get_option( 'extensions_of_files', '' ) ) ); |
|
189 | - $download_extensions = array_map( 'trim', $download_extensions ); |
|
190 | - $full_url = $this->protocol . '://' . $this->domain['domain']; |
|
191 | - if ( $this->protocol == 'mailto' ) { |
|
192 | - $type = 'email'; |
|
193 | - } else if ( in_array( $this->extension, $download_extensions ) ) { |
|
194 | - $type = 'download'; |
|
195 | - } else if ( in_array( $this->protocol, array( 'http', 'https') ) && $full_url !== rtrim( home_url(), '\/' ) ) { |
|
196 | - $type = 'outbound'; |
|
197 | - } else { |
|
198 | - $type = $this->parse_internal_link_type(); |
|
199 | - } |
|
200 | - return $type; |
|
201 | - } |
|
179 | + /** |
|
180 | + * Getting the type for current target. |
|
181 | + * |
|
182 | + * @since 6.0.0 |
|
183 | + * @access protected |
|
184 | + * |
|
185 | + * @return string The type of link. |
|
186 | + */ |
|
187 | + protected function get_target_type() { |
|
188 | + $download_extensions = explode( ',', str_replace( '.', '', monsterinsights_get_option( 'extensions_of_files', '' ) ) ); |
|
189 | + $download_extensions = array_map( 'trim', $download_extensions ); |
|
190 | + $full_url = $this->protocol . '://' . $this->domain['domain']; |
|
191 | + if ( $this->protocol == 'mailto' ) { |
|
192 | + $type = 'email'; |
|
193 | + } else if ( in_array( $this->extension, $download_extensions ) ) { |
|
194 | + $type = 'download'; |
|
195 | + } else if ( in_array( $this->protocol, array( 'http', 'https') ) && $full_url !== rtrim( home_url(), '\/' ) ) { |
|
196 | + $type = 'outbound'; |
|
197 | + } else { |
|
198 | + $type = $this->parse_internal_link_type(); |
|
199 | + } |
|
200 | + return $type; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Parse the type for outbound links. |
|
205 | - * |
|
206 | - * @since 6.0.0 |
|
207 | - * @access protected |
|
208 | - * |
|
209 | - * @return string The type of link. |
|
210 | - */ |
|
211 | - protected function parse_internal_link_type() { |
|
212 | - $out_links = explode( ',', monsterinsights_get_option( 'track_internal_as_outbound', '' ) ); |
|
213 | - $out_links = array_unique( array_map( 'trim', $out_links ) ); |
|
214 | - if ( ! empty( $this->original_url ) && count( $out_links ) >= 1 ) { |
|
215 | - foreach ( $out_links as $out ) { |
|
216 | - if ( ! empty( $out ) && strpos( $this->original_url, $out ) !== false ) { |
|
217 | - return 'internal-as-outbound'; |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - return 'internal'; |
|
222 | - } |
|
203 | + /** |
|
204 | + * Parse the type for outbound links. |
|
205 | + * |
|
206 | + * @since 6.0.0 |
|
207 | + * @access protected |
|
208 | + * |
|
209 | + * @return string The type of link. |
|
210 | + */ |
|
211 | + protected function parse_internal_link_type() { |
|
212 | + $out_links = explode( ',', monsterinsights_get_option( 'track_internal_as_outbound', '' ) ); |
|
213 | + $out_links = array_unique( array_map( 'trim', $out_links ) ); |
|
214 | + if ( ! empty( $this->original_url ) && count( $out_links ) >= 1 ) { |
|
215 | + foreach ( $out_links as $out ) { |
|
216 | + if ( ! empty( $out ) && strpos( $this->original_url, $out ) !== false ) { |
|
217 | + return 'internal-as-outbound'; |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + return 'internal'; |
|
222 | + } |
|
223 | 223 | } |
224 | 224 | \ No newline at end of file |
@@ -1,63 +1,63 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
6 | 6 | function monsterinsights_get_mp_api_url( ) { |
7 | - if ( monsterinsights_is_debug_mode() ) { |
|
7 | + if (monsterinsights_is_debug_mode()) { |
|
8 | 8 | return 'https://www.google-analytics.com/debug/collect'; |
9 | 9 | } else { |
10 | 10 | return 'https://ssl.google-analytics.com/collect'; |
11 | 11 | } |
12 | 12 | } |
13 | 13 | |
14 | -function monsterinsights_mp_api_call( $args = array() ) { |
|
14 | +function monsterinsights_mp_api_call($args = array()) { |
|
15 | 15 | $user_agent = ''; |
16 | - if ( ! empty( $args['user-agent'] ) ) { |
|
16 | + if ( ! empty($args['user-agent'])) { |
|
17 | 17 | $user_agent = $args['user-agent']; |
18 | - unset( $args['user-agent'] ); |
|
18 | + unset($args['user-agent']); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | $payment_id = 0; |
22 | - if ( ! empty( $args['payment_id'] ) ) { |
|
22 | + if ( ! empty($args['payment_id'])) { |
|
23 | 23 | $payment_id = $args['payment_id']; |
24 | - unset( $args['payment_id'] ); |
|
24 | + unset($args['payment_id']); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | $defaults = array( |
28 | 28 | 't' => 'event', // Required: Hit type |
29 | - 'ec' => '', // Optional: Event category |
|
30 | - 'ea' => '', // Optional: Event Action |
|
31 | - 'el' => '', // Optional: Event Label |
|
32 | - 'ev' => null, // Optional: Event Value |
|
29 | + 'ec' => '', // Optional: Event category |
|
30 | + 'ea' => '', // Optional: Event Action |
|
31 | + 'el' => '', // Optional: Event Label |
|
32 | + 'ev' => null, // Optional: Event Value |
|
33 | 33 | ); |
34 | 34 | |
35 | - $body = array_merge( $defaults , $args ); |
|
35 | + $body = array_merge($defaults, $args); |
|
36 | 36 | |
37 | 37 | // We want to get the user's IP address when possible |
38 | - $ip = ''; |
|
39 | - if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) && ! filter_var( $_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP ) === false ) { |
|
38 | + $ip = ''; |
|
39 | + if ( ! empty($_SERVER['HTTP_CLIENT_IP']) && ! filter_var($_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP) === false) { |
|
40 | 40 | $ip = $_SERVER['HTTP_CLIENT_IP']; |
41 | - } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! filter_var( $_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP ) === false ) { |
|
41 | + } elseif ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR']) && ! filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP) === false) { |
|
42 | 42 | $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
43 | 43 | } else { |
44 | 44 | $ip = $_SERVER['REMOTE_ADDR']; |
45 | 45 | } |
46 | 46 | |
47 | 47 | // If possible, let's get the user's language |
48 | - $user_language = isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) : array(); |
|
49 | - $user_language = reset( $user_language ); |
|
50 | - $user_language = sanitize_text_field( $user_language ); |
|
48 | + $user_language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) : array(); |
|
49 | + $user_language = reset($user_language); |
|
50 | + $user_language = sanitize_text_field($user_language); |
|
51 | 51 | |
52 | 52 | $default_body = array( |
53 | 53 | // Required: Version |
54 | 54 | 'v' => '1', |
55 | 55 | |
56 | 56 | // Required: UA code |
57 | - 'tid' => monsterinsights_get_ua_to_output( array( 'ecommerce' => $args ) ), |
|
57 | + 'tid' => monsterinsights_get_ua_to_output(array('ecommerce' => $args)), |
|
58 | 58 | |
59 | 59 | // Required: User visitor ID |
60 | - 'cid' => monsterinsights_get_client_id( $payment_id ), |
|
60 | + 'cid' => monsterinsights_get_client_id($payment_id), |
|
61 | 61 | |
62 | 62 | // Required: Type of hit (either pageview or event) |
63 | 63 | 't' => 'pageview', // Required - Hit type |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | 'ni' => true, |
67 | 67 | |
68 | 68 | // Optional: Document Host Name |
69 | - 'dh' => str_replace( array( 'http://', 'https://' ), '', site_url() ), |
|
69 | + 'dh' => str_replace(array('http://', 'https://'), '', site_url()), |
|
70 | 70 | |
71 | 71 | // Optional: Requested URI |
72 | 72 | 'dp' => $_SERVER['REQUEST_URI'], |
@@ -81,25 +81,25 @@ discard block |
||
81 | 81 | 'uip' => $ip, |
82 | 82 | |
83 | 83 | // Optional: User Agent |
84 | - 'ua' => ! empty( $user_agent ) ? $user_agent : $_SERVER['HTTP_USER_AGENT'], |
|
84 | + 'ua' => ! empty($user_agent) ? $user_agent : $_SERVER['HTTP_USER_AGENT'], |
|
85 | 85 | |
86 | 86 | // Optional: Time of the event |
87 | 87 | 'z' => time() |
88 | 88 | ); |
89 | 89 | |
90 | - $body = wp_parse_args( $body, $default_body ); |
|
90 | + $body = wp_parse_args($body, $default_body); |
|
91 | 91 | // $body = apply_filters( 'monsterinsights_mp_api_call', $body ); |
92 | 92 | |
93 | 93 | |
94 | 94 | // Ensure that the CID is not empty |
95 | - if ( empty( $body['cid'] ) ) { |
|
95 | + if (empty($body['cid'])) { |
|
96 | 96 | $body['cid'] = monsterinsights_generate_uuid(); |
97 | 97 | } |
98 | 98 | |
99 | 99 | // Unset empty values to reduce request size |
100 | - foreach ( $body as $key => $value ) { |
|
101 | - if ( empty( $value ) ) { |
|
102 | - unset( $body[ $key ] ); |
|
100 | + foreach ($body as $key => $value) { |
|
101 | + if (empty($value)) { |
|
102 | + unset($body[$key]); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -107,15 +107,15 @@ discard block |
||
107 | 107 | $args = array( |
108 | 108 | 'method' => 'POST', |
109 | 109 | 'timeout' => '5', |
110 | - 'blocking' => ( $debug_mode ) ? true : false, |
|
110 | + 'blocking' => ($debug_mode) ? true : false, |
|
111 | 111 | 'body' => $body, |
112 | 112 | ); |
113 | 113 | |
114 | - if ( ! empty( $user_agent ) ) { |
|
114 | + if ( ! empty($user_agent)) { |
|
115 | 115 | $args['user-agent'] = $user_agent; |
116 | 116 | } |
117 | 117 | |
118 | - $response = wp_remote_post( monsterinsights_get_mp_api_url(), $args ); |
|
118 | + $response = wp_remote_post(monsterinsights_get_mp_api_url(), $args); |
|
119 | 119 | |
120 | 120 | // |
121 | 121 | //if ( $debug_mode ) { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | return $response; |
126 | 126 | } |
127 | 127 | |
128 | -function monsterinsights_mp_track_event_call( $args = array() ) { |
|
128 | +function monsterinsights_mp_track_event_call($args = array()) { |
|
129 | 129 | $default_args = array( |
130 | 130 | // Change the default type to event |
131 | 131 | 't' => 'event', |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | // Optional: Event Value |
143 | 143 | 'ev' => null, |
144 | 144 | ); |
145 | - $args = wp_parse_args( $args, $default_args ); |
|
145 | + $args = wp_parse_args($args, $default_args); |
|
146 | 146 | //$args = apply_filters( 'monsterinsights_mp_track_event_call', $args ); |
147 | 147 | |
148 | - return monsterinsights_mp_api_call( $args ); |
|
148 | + return monsterinsights_mp_api_call($args); |
|
149 | 149 | } |
150 | 150 | \ No newline at end of file |
@@ -1,149 +1,149 @@ |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; // Exit if accessed directly |
|
3 | + exit; // Exit if accessed directly |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | function monsterinsights_get_mp_api_url( ) { |
7 | - if ( monsterinsights_is_debug_mode() ) { |
|
8 | - return 'https://www.google-analytics.com/debug/collect'; |
|
9 | - } else { |
|
10 | - return 'https://ssl.google-analytics.com/collect'; |
|
11 | - } |
|
7 | + if ( monsterinsights_is_debug_mode() ) { |
|
8 | + return 'https://www.google-analytics.com/debug/collect'; |
|
9 | + } else { |
|
10 | + return 'https://ssl.google-analytics.com/collect'; |
|
11 | + } |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function monsterinsights_mp_api_call( $args = array() ) { |
15 | - $user_agent = ''; |
|
16 | - if ( ! empty( $args['user-agent'] ) ) { |
|
17 | - $user_agent = $args['user-agent']; |
|
18 | - unset( $args['user-agent'] ); |
|
19 | - } |
|
20 | - |
|
21 | - $payment_id = 0; |
|
22 | - if ( ! empty( $args['payment_id'] ) ) { |
|
23 | - $payment_id = $args['payment_id']; |
|
24 | - unset( $args['payment_id'] ); |
|
25 | - } |
|
26 | - |
|
27 | - $defaults = array( |
|
28 | - 't' => 'event', // Required: Hit type |
|
29 | - 'ec' => '', // Optional: Event category |
|
30 | - 'ea' => '', // Optional: Event Action |
|
31 | - 'el' => '', // Optional: Event Label |
|
32 | - 'ev' => null, // Optional: Event Value |
|
33 | - ); |
|
34 | - |
|
35 | - $body = array_merge( $defaults , $args ); |
|
36 | - |
|
37 | - // We want to get the user's IP address when possible |
|
38 | - $ip = ''; |
|
39 | - if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) && ! filter_var( $_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP ) === false ) { |
|
40 | - $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
41 | - } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! filter_var( $_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP ) === false ) { |
|
42 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
43 | - } else { |
|
44 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
45 | - } |
|
46 | - |
|
47 | - // If possible, let's get the user's language |
|
48 | - $user_language = isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) : array(); |
|
49 | - $user_language = reset( $user_language ); |
|
50 | - $user_language = sanitize_text_field( $user_language ); |
|
51 | - |
|
52 | - $default_body = array( |
|
53 | - // Required: Version |
|
54 | - 'v' => '1', |
|
15 | + $user_agent = ''; |
|
16 | + if ( ! empty( $args['user-agent'] ) ) { |
|
17 | + $user_agent = $args['user-agent']; |
|
18 | + unset( $args['user-agent'] ); |
|
19 | + } |
|
20 | + |
|
21 | + $payment_id = 0; |
|
22 | + if ( ! empty( $args['payment_id'] ) ) { |
|
23 | + $payment_id = $args['payment_id']; |
|
24 | + unset( $args['payment_id'] ); |
|
25 | + } |
|
26 | + |
|
27 | + $defaults = array( |
|
28 | + 't' => 'event', // Required: Hit type |
|
29 | + 'ec' => '', // Optional: Event category |
|
30 | + 'ea' => '', // Optional: Event Action |
|
31 | + 'el' => '', // Optional: Event Label |
|
32 | + 'ev' => null, // Optional: Event Value |
|
33 | + ); |
|
34 | + |
|
35 | + $body = array_merge( $defaults , $args ); |
|
36 | + |
|
37 | + // We want to get the user's IP address when possible |
|
38 | + $ip = ''; |
|
39 | + if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) && ! filter_var( $_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP ) === false ) { |
|
40 | + $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
41 | + } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! filter_var( $_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP ) === false ) { |
|
42 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
43 | + } else { |
|
44 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
45 | + } |
|
46 | + |
|
47 | + // If possible, let's get the user's language |
|
48 | + $user_language = isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) : array(); |
|
49 | + $user_language = reset( $user_language ); |
|
50 | + $user_language = sanitize_text_field( $user_language ); |
|
51 | + |
|
52 | + $default_body = array( |
|
53 | + // Required: Version |
|
54 | + 'v' => '1', |
|
55 | 55 | |
56 | - // Required: UA code |
|
57 | - 'tid' => monsterinsights_get_ua_to_output( array( 'ecommerce' => $args ) ), |
|
56 | + // Required: UA code |
|
57 | + 'tid' => monsterinsights_get_ua_to_output( array( 'ecommerce' => $args ) ), |
|
58 | 58 | |
59 | - // Required: User visitor ID |
|
60 | - 'cid' => monsterinsights_get_client_id( $payment_id ), |
|
59 | + // Required: User visitor ID |
|
60 | + 'cid' => monsterinsights_get_client_id( $payment_id ), |
|
61 | 61 | |
62 | - // Required: Type of hit (either pageview or event) |
|
63 | - 't' => 'pageview', // Required - Hit type |
|
62 | + // Required: Type of hit (either pageview or event) |
|
63 | + 't' => 'pageview', // Required - Hit type |
|
64 | 64 | |
65 | - // Optional: Was the event a non-interaction event (for bounce purposes) |
|
66 | - 'ni' => true, |
|
65 | + // Optional: Was the event a non-interaction event (for bounce purposes) |
|
66 | + 'ni' => true, |
|
67 | 67 | |
68 | - // Optional: Document Host Name |
|
69 | - 'dh' => str_replace( array( 'http://', 'https://' ), '', site_url() ), |
|
68 | + // Optional: Document Host Name |
|
69 | + 'dh' => str_replace( array( 'http://', 'https://' ), '', site_url() ), |
|
70 | 70 | |
71 | - // Optional: Requested URI |
|
72 | - 'dp' => $_SERVER['REQUEST_URI'], |
|
71 | + // Optional: Requested URI |
|
72 | + 'dp' => $_SERVER['REQUEST_URI'], |
|
73 | 73 | |
74 | - // Optional: Page Title |
|
75 | - 'dt' => get_the_title(), |
|
74 | + // Optional: Page Title |
|
75 | + 'dt' => get_the_title(), |
|
76 | 76 | |
77 | - // Optional: User language |
|
78 | - 'ul' => $user_language, |
|
77 | + // Optional: User language |
|
78 | + 'ul' => $user_language, |
|
79 | 79 | |
80 | - // Optional: User IP address |
|
81 | - 'uip' => $ip, |
|
80 | + // Optional: User IP address |
|
81 | + 'uip' => $ip, |
|
82 | 82 | |
83 | - // Optional: User Agent |
|
84 | - 'ua' => ! empty( $user_agent ) ? $user_agent : $_SERVER['HTTP_USER_AGENT'], |
|
83 | + // Optional: User Agent |
|
84 | + 'ua' => ! empty( $user_agent ) ? $user_agent : $_SERVER['HTTP_USER_AGENT'], |
|
85 | 85 | |
86 | - // Optional: Time of the event |
|
87 | - 'z' => time() |
|
88 | - ); |
|
86 | + // Optional: Time of the event |
|
87 | + 'z' => time() |
|
88 | + ); |
|
89 | 89 | |
90 | - $body = wp_parse_args( $body, $default_body ); |
|
91 | - // $body = apply_filters( 'monsterinsights_mp_api_call', $body ); |
|
90 | + $body = wp_parse_args( $body, $default_body ); |
|
91 | + // $body = apply_filters( 'monsterinsights_mp_api_call', $body ); |
|
92 | 92 | |
93 | 93 | |
94 | - // Ensure that the CID is not empty |
|
95 | - if ( empty( $body['cid'] ) ) { |
|
96 | - $body['cid'] = monsterinsights_generate_uuid(); |
|
97 | - } |
|
94 | + // Ensure that the CID is not empty |
|
95 | + if ( empty( $body['cid'] ) ) { |
|
96 | + $body['cid'] = monsterinsights_generate_uuid(); |
|
97 | + } |
|
98 | 98 | |
99 | - // Unset empty values to reduce request size |
|
100 | - foreach ( $body as $key => $value ) { |
|
101 | - if ( empty( $value ) ) { |
|
102 | - unset( $body[ $key ] ); |
|
103 | - } |
|
104 | - } |
|
99 | + // Unset empty values to reduce request size |
|
100 | + foreach ( $body as $key => $value ) { |
|
101 | + if ( empty( $value ) ) { |
|
102 | + unset( $body[ $key ] ); |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - $debug_mode = monsterinsights_is_debug_mode(); |
|
107 | - $args = array( |
|
108 | - 'method' => 'POST', |
|
109 | - 'timeout' => '5', |
|
110 | - 'blocking' => ( $debug_mode ) ? true : false, |
|
111 | - 'body' => $body, |
|
112 | - ); |
|
106 | + $debug_mode = monsterinsights_is_debug_mode(); |
|
107 | + $args = array( |
|
108 | + 'method' => 'POST', |
|
109 | + 'timeout' => '5', |
|
110 | + 'blocking' => ( $debug_mode ) ? true : false, |
|
111 | + 'body' => $body, |
|
112 | + ); |
|
113 | 113 | |
114 | - if ( ! empty( $user_agent ) ) { |
|
115 | - $args['user-agent'] = $user_agent; |
|
116 | - } |
|
114 | + if ( ! empty( $user_agent ) ) { |
|
115 | + $args['user-agent'] = $user_agent; |
|
116 | + } |
|
117 | 117 | |
118 | - $response = wp_remote_post( monsterinsights_get_mp_api_url(), $args ); |
|
118 | + $response = wp_remote_post( monsterinsights_get_mp_api_url(), $args ); |
|
119 | 119 | |
120 | - // |
|
121 | - //if ( $debug_mode ) { |
|
122 | - // monsterinsights_debug_output( $body ); |
|
123 | - // monsterinsights_debug_output( $response ); |
|
124 | - //} |
|
125 | - return $response; |
|
120 | + // |
|
121 | + //if ( $debug_mode ) { |
|
122 | + // monsterinsights_debug_output( $body ); |
|
123 | + // monsterinsights_debug_output( $response ); |
|
124 | + //} |
|
125 | + return $response; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | function monsterinsights_mp_track_event_call( $args = array() ) { |
129 | - $default_args = array( |
|
130 | - // Change the default type to event |
|
131 | - 't' => 'event', |
|
129 | + $default_args = array( |
|
130 | + // Change the default type to event |
|
131 | + 't' => 'event', |
|
132 | 132 | |
133 | - // Required: Event Category |
|
134 | - 'ec' => '', |
|
133 | + // Required: Event Category |
|
134 | + 'ec' => '', |
|
135 | 135 | |
136 | - // Required: Event Action |
|
137 | - 'ea' => '', |
|
136 | + // Required: Event Action |
|
137 | + 'ea' => '', |
|
138 | 138 | |
139 | - // Required: Event Label |
|
140 | - 'el' => '', |
|
139 | + // Required: Event Label |
|
140 | + 'el' => '', |
|
141 | 141 | |
142 | - // Optional: Event Value |
|
143 | - 'ev' => null, |
|
144 | - ); |
|
145 | - $args = wp_parse_args( $args, $default_args ); |
|
146 | - //$args = apply_filters( 'monsterinsights_mp_track_event_call', $args ); |
|
142 | + // Optional: Event Value |
|
143 | + 'ev' => null, |
|
144 | + ); |
|
145 | + $args = wp_parse_args( $args, $default_args ); |
|
146 | + //$args = apply_filters( 'monsterinsights_mp_track_event_call', $args ); |
|
147 | 147 | |
148 | - return monsterinsights_mp_api_call( $args ); |
|
148 | + return monsterinsights_mp_api_call( $args ); |
|
149 | 149 | } |
150 | 150 | \ No newline at end of file |
@@ -1,43 +1,43 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | +if ( ! defined('ABSPATH')) { |
|
5 | 5 | exit; |
6 | 6 | } |
7 | 7 | |
8 | -function monsterinsights_registered_settings_filter( $settings ) { |
|
9 | - $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' ); |
|
10 | - $events_tracking = monsterinsights_get_option( 'events_mode', 'js' ); |
|
8 | +function monsterinsights_registered_settings_filter($settings) { |
|
9 | + $tracking_mode = monsterinsights_get_option('tracking_mode', 'analytics'); |
|
10 | + $events_tracking = monsterinsights_get_option('events_mode', 'js'); |
|
11 | 11 | |
12 | 12 | // both |
13 | - if ( ! empty( $settings['engagement']['events_mode'] ) ) { |
|
14 | - if ( $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
13 | + if ( ! empty($settings['engagement']['events_mode'])) { |
|
14 | + if ($tracking_mode === 'ga' && ! monsterinsights_is_debug_mode()) { |
|
15 | 15 | // if we're not using Universal Analytics, we can't do JS events tracking |
16 | - unset( $settings['engagement']['events_mode']['options']['js'] ); |
|
16 | + unset($settings['engagement']['events_mode']['options']['js']); |
|
17 | 17 | } else { |
18 | - if ( $tracking_mode !== 'ga' && $events_tracking !== 'php' && ! monsterinsights_is_debug_mode() ) { |
|
18 | + if ($tracking_mode !== 'ga' && $events_tracking !== 'php' && ! monsterinsights_is_debug_mode()) { |
|
19 | 19 | // if we're not using PHP events tracking, turn it off |
20 | - unset( $settings['engagement']['events_mode']['options']['php'] ); |
|
20 | + unset($settings['engagement']['events_mode']['options']['php']); |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | } |
24 | - if ( ! empty( $settings['demographics']['demographics'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
24 | + if ( ! empty($settings['demographics']['demographics']) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode()) { |
|
25 | 25 | // Events relies on universal tracking |
26 | - $url = esc_url( wp_nonce_url( add_query_arg( array( 'monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics' ) ), 'monsterinsights-switch-to-analyticsjs-nonce' ) ); |
|
26 | + $url = esc_url(wp_nonce_url(add_query_arg(array('monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics')), 'monsterinsights-switch-to-analyticsjs-nonce')); |
|
27 | 27 | $settings['demographics']['demographics']['type'] = 'notice'; |
28 | - $settings['demographics']['demographics']['desc'] = sprintf( esc_html__( 'Demographics and Interests tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); |
|
28 | + $settings['demographics']['demographics']['desc'] = sprintf(esc_html__('Demographics and Interests tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress'), '<a href="' . $url . '">', '</a>'); |
|
29 | 29 | } |
30 | - if ( ! empty( $settings['links']['enhanced_link_attribution'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
30 | + if ( ! empty($settings['links']['enhanced_link_attribution']) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode()) { |
|
31 | 31 | // This relies on universal tracking |
32 | - $url = esc_url( wp_nonce_url( add_query_arg( array( 'monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics' ) ), 'monsterinsights-switch-to-analyticsjs-nonce' ) ); |
|
32 | + $url = esc_url(wp_nonce_url(add_query_arg(array('monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics')), 'monsterinsights-switch-to-analyticsjs-nonce')); |
|
33 | 33 | $settings['links']['enhanced_link_attribution']['type'] = 'notice'; |
34 | - $settings['links']['enhanced_link_attribution']['desc'] = sprintf( esc_html__( 'Enhanced Link Attribution tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); |
|
34 | + $settings['links']['enhanced_link_attribution']['desc'] = sprintf(esc_html__('Enhanced Link Attribution tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress'), '<a href="' . $url . '">', '</a>'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | |
38 | - if ( ! empty( $settings['compatibility']['subdomain_tracking'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
39 | - $settings['links']['enhanced_link_attribution']['name'] = __( 'Subdomain tracking:', 'google-analytics-for-wordpress' ); |
|
40 | - $settings['links']['enhanced_link_attribution']['desc'] = sprintf( esc_html__( 'This allows you to set the domain that\'s set by %1$s for tracking subdomains. If empty, this will not be set. Can be used to set localhost for ga.js tracking.', 'google-analytics-for-wordpress' ), '<a href="https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._setDomainName" target="_blank" rel="noopener noreferrer" referrer="no-referrer"><code>_setDomainName</code></a>' ); |
|
38 | + if ( ! empty($settings['compatibility']['subdomain_tracking']) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode()) { |
|
39 | + $settings['links']['enhanced_link_attribution']['name'] = __('Subdomain tracking:', 'google-analytics-for-wordpress'); |
|
40 | + $settings['links']['enhanced_link_attribution']['desc'] = sprintf(esc_html__('This allows you to set the domain that\'s set by %1$s for tracking subdomains. If empty, this will not be set. Can be used to set localhost for ga.js tracking.', 'google-analytics-for-wordpress'), '<a href="https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._setDomainName" target="_blank" rel="noopener noreferrer" referrer="no-referrer"><code>_setDomainName</code></a>'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | |
@@ -46,128 +46,128 @@ discard block |
||
46 | 46 | $settings['social']['social_notice'] = array( |
47 | 47 | 'id' => 'social_notice', |
48 | 48 | 'no_label' => true, |
49 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
49 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
50 | 50 | 'type' => 'upgrade_notice', |
51 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Social tracking to see who's clicking on your social share links, so you can track and maximize your social sharing exposure.", 'google-analytics-for-wordpress' ) |
|
51 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can add Social tracking to see who's clicking on your social share links, so you can track and maximize your social sharing exposure.", 'google-analytics-for-wordpress') |
|
52 | 52 | ); |
53 | 53 | |
54 | 54 | // Ads |
55 | 55 | $settings['ads']['ads_notice'] = array( |
56 | 56 | 'id' => 'ads_notice', |
57 | 57 | 'no_label' => true, |
58 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
58 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
59 | 59 | 'type' => 'upgrade_notice', |
60 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Ads tracking to see who's clicking on your Google Ads, so you can increase your revenue.", 'google-analytics-for-wordpress' ) |
|
60 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can add Ads tracking to see who's clicking on your Google Ads, so you can increase your revenue.", 'google-analytics-for-wordpress') |
|
61 | 61 | ); |
62 | 62 | |
63 | 63 | // Forms |
64 | 64 | $settings['forms']['forms_notice'] = array( |
65 | 65 | 'id' => 'forms_notice', |
66 | 66 | 'no_label' => true, |
67 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
67 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
68 | 68 | 'type' => 'upgrade_notice', |
69 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Forms tracking to see who's seeing and submitting your forms, so you can increase your conversion rate.", 'google-analytics-for-wordpress' ) |
|
69 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can add Forms tracking to see who's seeing and submitting your forms, so you can increase your conversion rate.", 'google-analytics-for-wordpress') |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | // Media |
73 | 73 | $settings['media']['media_notice'] = array( |
74 | 74 | 'id' => 'media_notice', |
75 | 75 | 'no_label' => true, |
76 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
76 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
77 | 77 | 'type' => 'upgrade_notice', |
78 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Media tracking to see who's interacting with the media on your site, so you know what your users are most interested in on your site. You can use this to tailor future content to meet your audience's interest to promote repeat visitors and expand your average user's time spent visiting your website on each visit.", 'google-analytics-for-wordpress' ) |
|
78 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can add Media tracking to see who's interacting with the media on your site, so you know what your users are most interested in on your site. You can use this to tailor future content to meet your audience's interest to promote repeat visitors and expand your average user's time spent visiting your website on each visit.", 'google-analytics-for-wordpress') |
|
79 | 79 | ); |
80 | 80 | |
81 | 81 | // Membership |
82 | 82 | $settings['membership']['membership_notice'] = array( |
83 | 83 | 'id' => 'membership_notice', |
84 | 84 | 'no_label' => true, |
85 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
85 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
86 | 86 | 'type' => 'upgrade_notice', |
87 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Membership tracking.", 'google-analytics-for-wordpress' ) |
|
87 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can add Membership tracking.", 'google-analytics-for-wordpress') |
|
88 | 88 | ); |
89 | 89 | |
90 | 90 | // Dimensions |
91 | 91 | $settings['dimensions']['dimensions_notice'] = array( |
92 | 92 | 'id' => 'dimensions_notice', |
93 | 93 | 'no_label' => true, |
94 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
94 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
95 | 95 | 'type' => 'upgrade_notice', |
96 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Custom Dimensions and track who's the most popular author on your site, which post types get the most traffic, and more. Why not check it out?", 'google-analytics-for-wordpress' ) |
|
96 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can add Custom Dimensions and track who's the most popular author on your site, which post types get the most traffic, and more. Why not check it out?", 'google-analytics-for-wordpress') |
|
97 | 97 | ); |
98 | 98 | |
99 | 99 | // Performance |
100 | 100 | $settings['performance']['performance_notice'] = array( |
101 | 101 | 'id' => 'performance_notice', |
102 | 102 | 'no_label' => true, |
103 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
103 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
104 | 104 | 'type' => 'upgrade_notice', |
105 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can adjust the sample rate so you don't exceed Google Analytics' processing limit. You can also use it to enable Google Optimize for A/B testing and personalization.", 'google-analytics-for-wordpress' ) |
|
105 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can adjust the sample rate so you don't exceed Google Analytics' processing limit. You can also use it to enable Google Optimize for A/B testing and personalization.", 'google-analytics-for-wordpress') |
|
106 | 106 | ); |
107 | 107 | |
108 | 108 | // Reporting |
109 | 109 | $settings['reporting']['reporting_notice'] = array( |
110 | 110 | 'id' => 'reporting_notice', |
111 | 111 | 'no_label' => true, |
112 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
112 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
113 | 113 | 'type' => 'upgrade_notice', |
114 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable enhanced reporting.", 'google-analytics-for-wordpress' ) |
|
114 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can enable enhanced reporting.", 'google-analytics-for-wordpress') |
|
115 | 115 | ); |
116 | 116 | |
117 | 117 | // Google AMP |
118 | 118 | $settings['amp']['amp_notice'] = array( |
119 | 119 | 'id' => 'amp_notice', |
120 | 120 | 'no_label' => true, |
121 | - 'name' => __( 'Want to use track users visiting your AMP pages?', 'google-analytics-for-wordpress'), |
|
121 | + 'name' => __('Want to use track users visiting your AMP pages?', 'google-analytics-for-wordpress'), |
|
122 | 122 | 'type' => 'upgrade_notice', |
123 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable AMP page tracking.", 'google-analytics-for-wordpress' ) |
|
123 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can enable AMP page tracking.", 'google-analytics-for-wordpress') |
|
124 | 124 | ); |
125 | 125 | |
126 | 126 | // Google Optimize |
127 | 127 | $settings['goptimize']['goptimize_notice'] = array( |
128 | 128 | 'id' => 'goptimize_notice', |
129 | 129 | 'no_label' => true, |
130 | - 'name' => __( 'Want to use Google Optimize to retarget your website vistors and perform A/B split tests with ease?', 'google-analytics-for-wordpress'), |
|
130 | + 'name' => __('Want to use Google Optimize to retarget your website vistors and perform A/B split tests with ease?', 'google-analytics-for-wordpress'), |
|
131 | 131 | 'type' => 'upgrade_notice', |
132 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable Google Optimize.", 'google-analytics-for-wordpress' ) |
|
132 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can enable Google Optimize.", 'google-analytics-for-wordpress') |
|
133 | 133 | ); |
134 | 134 | |
135 | 135 | // Facebook Instant Articles |
136 | 136 | $settings['fbia']['fbia_notice'] = array( |
137 | 137 | 'id' => 'fbia_notice', |
138 | 138 | 'no_label' => true, |
139 | - 'name' => __( 'Want to expand your website audience beyond your website with Facebook Instant Articles?', 'google-analytics-for-wordpress'), |
|
139 | + 'name' => __('Want to expand your website audience beyond your website with Facebook Instant Articles?', 'google-analytics-for-wordpress'), |
|
140 | 140 | 'type' => 'upgrade_notice', |
141 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can track your Facebook Instant Article visitors with MonsterInsights.", 'google-analytics-for-wordpress' ) |
|
141 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can track your Facebook Instant Article visitors with MonsterInsights.", 'google-analytics-for-wordpress') |
|
142 | 142 | ); |
143 | 143 | |
144 | 144 | // Bounce Reduction |
145 | 145 | $settings['bounce']['bounce_notice'] = array( |
146 | 146 | 'id' => 'bounce_notice', |
147 | 147 | 'no_label' => true, |
148 | - 'name' => __( 'Want to adjust your website bounce rate?', 'google-analytics-for-wordpress'), |
|
148 | + 'name' => __('Want to adjust your website bounce rate?', 'google-analytics-for-wordpress'), |
|
149 | 149 | 'type' => 'upgrade_notice', |
150 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can adjust your Google Analytics bounce rate with MonsterInsights.", 'google-analytics-for-wordpress' ) |
|
150 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can adjust your Google Analytics bounce rate with MonsterInsights.", 'google-analytics-for-wordpress') |
|
151 | 151 | ); |
152 | 152 | |
153 | 153 | // Notifications |
154 | 154 | $settings['notifications']['notifications_notice'] = array( |
155 | 155 | 'id' => 'notifications_notice', |
156 | 156 | 'no_label' => true, |
157 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
157 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
158 | 158 | 'type' => 'upgrade_notice', |
159 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable notifications.", 'google-analytics-for-wordpress' ) |
|
159 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can enable notifications.", 'google-analytics-for-wordpress') |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | // eCommerce |
163 | 163 | $settings['ecommerce']['ecommerce_notice'] = array( |
164 | 164 | 'id' => 'ecommerce_notice', |
165 | 165 | 'no_label' => true, |
166 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
166 | + 'name' => __('Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
167 | 167 | 'type' => 'upgrade_notice', |
168 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Ecommerce tracking to see who's buying your product, what's the most popular item on your store, the average order value, and tons more.", 'google-analytics-for-wordpress' ) |
|
168 | + 'desc' => esc_html__("By upgrading to MonsterInsights Pro, you can add Ecommerce tracking to see who's buying your product, what's the most popular item on your store, the average order value, and tons more.", 'google-analytics-for-wordpress') |
|
169 | 169 | ); |
170 | 170 | |
171 | 171 | return $settings; |
172 | 172 | } |
173 | -add_filter( 'monsterinsights_registered_settings', 'monsterinsights_registered_settings_filter' ); |
|
173 | +add_filter('monsterinsights_registered_settings', 'monsterinsights_registered_settings_filter'); |
@@ -2,172 +2,172 @@ |
||
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
5 | - exit; |
|
5 | + exit; |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | function monsterinsights_registered_settings_filter( $settings ) { |
9 | - $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' ); |
|
10 | - $events_tracking = monsterinsights_get_option( 'events_mode', 'js' ); |
|
11 | - |
|
12 | - // both |
|
13 | - if ( ! empty( $settings['engagement']['events_mode'] ) ) { |
|
14 | - if ( $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
15 | - // if we're not using Universal Analytics, we can't do JS events tracking |
|
16 | - unset( $settings['engagement']['events_mode']['options']['js'] ); |
|
17 | - } else { |
|
18 | - if ( $tracking_mode !== 'ga' && $events_tracking !== 'php' && ! monsterinsights_is_debug_mode() ) { |
|
19 | - // if we're not using PHP events tracking, turn it off |
|
20 | - unset( $settings['engagement']['events_mode']['options']['php'] ); |
|
21 | - } |
|
22 | - } |
|
23 | - } |
|
24 | - if ( ! empty( $settings['demographics']['demographics'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
25 | - // Events relies on universal tracking |
|
26 | - $url = esc_url( wp_nonce_url( add_query_arg( array( 'monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics' ) ), 'monsterinsights-switch-to-analyticsjs-nonce' ) ); |
|
27 | - $settings['demographics']['demographics']['type'] = 'notice'; |
|
28 | - $settings['demographics']['demographics']['desc'] = sprintf( esc_html__( 'Demographics and Interests tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); |
|
29 | - } |
|
30 | - if ( ! empty( $settings['links']['enhanced_link_attribution'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
31 | - // This relies on universal tracking |
|
32 | - $url = esc_url( wp_nonce_url( add_query_arg( array( 'monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics' ) ), 'monsterinsights-switch-to-analyticsjs-nonce' ) ); |
|
33 | - $settings['links']['enhanced_link_attribution']['type'] = 'notice'; |
|
34 | - $settings['links']['enhanced_link_attribution']['desc'] = sprintf( esc_html__( 'Enhanced Link Attribution tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - if ( ! empty( $settings['compatibility']['subdomain_tracking'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
39 | - $settings['links']['enhanced_link_attribution']['name'] = __( 'Subdomain tracking:', 'google-analytics-for-wordpress' ); |
|
40 | - $settings['links']['enhanced_link_attribution']['desc'] = sprintf( esc_html__( 'This allows you to set the domain that\'s set by %1$s for tracking subdomains. If empty, this will not be set. Can be used to set localhost for ga.js tracking.', 'google-analytics-for-wordpress' ), '<a href="https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._setDomainName" target="_blank" rel="noopener noreferrer" referrer="no-referrer"><code>_setDomainName</code></a>' ); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - // Addons: |
|
45 | - // Social |
|
46 | - $settings['social']['social_notice'] = array( |
|
47 | - 'id' => 'social_notice', |
|
48 | - 'no_label' => true, |
|
49 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
50 | - 'type' => 'upgrade_notice', |
|
51 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Social tracking to see who's clicking on your social share links, so you can track and maximize your social sharing exposure.", 'google-analytics-for-wordpress' ) |
|
52 | - ); |
|
53 | - |
|
54 | - // Ads |
|
55 | - $settings['ads']['ads_notice'] = array( |
|
56 | - 'id' => 'ads_notice', |
|
57 | - 'no_label' => true, |
|
58 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
59 | - 'type' => 'upgrade_notice', |
|
60 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Ads tracking to see who's clicking on your Google Ads, so you can increase your revenue.", 'google-analytics-for-wordpress' ) |
|
61 | - ); |
|
62 | - |
|
63 | - // Forms |
|
64 | - $settings['forms']['forms_notice'] = array( |
|
65 | - 'id' => 'forms_notice', |
|
66 | - 'no_label' => true, |
|
67 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
68 | - 'type' => 'upgrade_notice', |
|
69 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Forms tracking to see who's seeing and submitting your forms, so you can increase your conversion rate.", 'google-analytics-for-wordpress' ) |
|
70 | - ); |
|
71 | - |
|
72 | - // Media |
|
73 | - $settings['media']['media_notice'] = array( |
|
74 | - 'id' => 'media_notice', |
|
75 | - 'no_label' => true, |
|
76 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
77 | - 'type' => 'upgrade_notice', |
|
78 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Media tracking to see who's interacting with the media on your site, so you know what your users are most interested in on your site. You can use this to tailor future content to meet your audience's interest to promote repeat visitors and expand your average user's time spent visiting your website on each visit.", 'google-analytics-for-wordpress' ) |
|
79 | - ); |
|
80 | - |
|
81 | - // Membership |
|
82 | - $settings['membership']['membership_notice'] = array( |
|
83 | - 'id' => 'membership_notice', |
|
84 | - 'no_label' => true, |
|
85 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
86 | - 'type' => 'upgrade_notice', |
|
87 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Membership tracking.", 'google-analytics-for-wordpress' ) |
|
88 | - ); |
|
89 | - |
|
90 | - // Dimensions |
|
91 | - $settings['dimensions']['dimensions_notice'] = array( |
|
92 | - 'id' => 'dimensions_notice', |
|
93 | - 'no_label' => true, |
|
94 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
95 | - 'type' => 'upgrade_notice', |
|
96 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Custom Dimensions and track who's the most popular author on your site, which post types get the most traffic, and more. Why not check it out?", 'google-analytics-for-wordpress' ) |
|
97 | - ); |
|
98 | - |
|
99 | - // Performance |
|
100 | - $settings['performance']['performance_notice'] = array( |
|
101 | - 'id' => 'performance_notice', |
|
102 | - 'no_label' => true, |
|
103 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
104 | - 'type' => 'upgrade_notice', |
|
105 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can adjust the sample rate so you don't exceed Google Analytics' processing limit. You can also use it to enable Google Optimize for A/B testing and personalization.", 'google-analytics-for-wordpress' ) |
|
106 | - ); |
|
107 | - |
|
108 | - // Reporting |
|
109 | - $settings['reporting']['reporting_notice'] = array( |
|
110 | - 'id' => 'reporting_notice', |
|
111 | - 'no_label' => true, |
|
112 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
113 | - 'type' => 'upgrade_notice', |
|
114 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable enhanced reporting.", 'google-analytics-for-wordpress' ) |
|
115 | - ); |
|
116 | - |
|
117 | - // Google AMP |
|
118 | - $settings['amp']['amp_notice'] = array( |
|
119 | - 'id' => 'amp_notice', |
|
120 | - 'no_label' => true, |
|
121 | - 'name' => __( 'Want to use track users visiting your AMP pages?', 'google-analytics-for-wordpress'), |
|
122 | - 'type' => 'upgrade_notice', |
|
123 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable AMP page tracking.", 'google-analytics-for-wordpress' ) |
|
124 | - ); |
|
125 | - |
|
126 | - // Google Optimize |
|
127 | - $settings['goptimize']['goptimize_notice'] = array( |
|
128 | - 'id' => 'goptimize_notice', |
|
129 | - 'no_label' => true, |
|
130 | - 'name' => __( 'Want to use Google Optimize to retarget your website vistors and perform A/B split tests with ease?', 'google-analytics-for-wordpress'), |
|
131 | - 'type' => 'upgrade_notice', |
|
132 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable Google Optimize.", 'google-analytics-for-wordpress' ) |
|
133 | - ); |
|
134 | - |
|
135 | - // Facebook Instant Articles |
|
136 | - $settings['fbia']['fbia_notice'] = array( |
|
137 | - 'id' => 'fbia_notice', |
|
138 | - 'no_label' => true, |
|
139 | - 'name' => __( 'Want to expand your website audience beyond your website with Facebook Instant Articles?', 'google-analytics-for-wordpress'), |
|
140 | - 'type' => 'upgrade_notice', |
|
141 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can track your Facebook Instant Article visitors with MonsterInsights.", 'google-analytics-for-wordpress' ) |
|
142 | - ); |
|
143 | - |
|
144 | - // Bounce Reduction |
|
145 | - $settings['bounce']['bounce_notice'] = array( |
|
146 | - 'id' => 'bounce_notice', |
|
147 | - 'no_label' => true, |
|
148 | - 'name' => __( 'Want to adjust your website bounce rate?', 'google-analytics-for-wordpress'), |
|
149 | - 'type' => 'upgrade_notice', |
|
150 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can adjust your Google Analytics bounce rate with MonsterInsights.", 'google-analytics-for-wordpress' ) |
|
151 | - ); |
|
152 | - |
|
153 | - // Notifications |
|
154 | - $settings['notifications']['notifications_notice'] = array( |
|
155 | - 'id' => 'notifications_notice', |
|
156 | - 'no_label' => true, |
|
157 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
158 | - 'type' => 'upgrade_notice', |
|
159 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable notifications.", 'google-analytics-for-wordpress' ) |
|
160 | - ); |
|
161 | - |
|
162 | - // eCommerce |
|
163 | - $settings['ecommerce']['ecommerce_notice'] = array( |
|
164 | - 'id' => 'ecommerce_notice', |
|
165 | - 'no_label' => true, |
|
166 | - 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
167 | - 'type' => 'upgrade_notice', |
|
168 | - 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Ecommerce tracking to see who's buying your product, what's the most popular item on your store, the average order value, and tons more.", 'google-analytics-for-wordpress' ) |
|
169 | - ); |
|
170 | - |
|
171 | - return $settings; |
|
9 | + $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' ); |
|
10 | + $events_tracking = monsterinsights_get_option( 'events_mode', 'js' ); |
|
11 | + |
|
12 | + // both |
|
13 | + if ( ! empty( $settings['engagement']['events_mode'] ) ) { |
|
14 | + if ( $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
15 | + // if we're not using Universal Analytics, we can't do JS events tracking |
|
16 | + unset( $settings['engagement']['events_mode']['options']['js'] ); |
|
17 | + } else { |
|
18 | + if ( $tracking_mode !== 'ga' && $events_tracking !== 'php' && ! monsterinsights_is_debug_mode() ) { |
|
19 | + // if we're not using PHP events tracking, turn it off |
|
20 | + unset( $settings['engagement']['events_mode']['options']['php'] ); |
|
21 | + } |
|
22 | + } |
|
23 | + } |
|
24 | + if ( ! empty( $settings['demographics']['demographics'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
25 | + // Events relies on universal tracking |
|
26 | + $url = esc_url( wp_nonce_url( add_query_arg( array( 'monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics' ) ), 'monsterinsights-switch-to-analyticsjs-nonce' ) ); |
|
27 | + $settings['demographics']['demographics']['type'] = 'notice'; |
|
28 | + $settings['demographics']['demographics']['desc'] = sprintf( esc_html__( 'Demographics and Interests tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); |
|
29 | + } |
|
30 | + if ( ! empty( $settings['links']['enhanced_link_attribution'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
31 | + // This relies on universal tracking |
|
32 | + $url = esc_url( wp_nonce_url( add_query_arg( array( 'monsterinsights-action' => 'switch_to_analyticsjs', 'return' => 'demographics' ) ), 'monsterinsights-switch-to-analyticsjs-nonce' ) ); |
|
33 | + $settings['links']['enhanced_link_attribution']['type'] = 'notice'; |
|
34 | + $settings['links']['enhanced_link_attribution']['desc'] = sprintf( esc_html__( 'Enhanced Link Attribution tracking is only available on Universal Tracking (analytics.js). You\'re currently using deprecated ga.js tracking. We recommend switching to analytics.js, as it is significantly more accurate than ga.js, and allows for additional functionality (like the more accurate Javascript based events tracking we offer). Further Google Analytics has deprecated support for ga.js, and it may stop working at any time when Google decides to disable it from their server. To switch to using the newer Universal Analytics (analytics.js) %1$sclick here%2$s.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + if ( ! empty( $settings['compatibility']['subdomain_tracking'] ) && $tracking_mode === 'ga' && ! monsterinsights_is_debug_mode() ) { |
|
39 | + $settings['links']['enhanced_link_attribution']['name'] = __( 'Subdomain tracking:', 'google-analytics-for-wordpress' ); |
|
40 | + $settings['links']['enhanced_link_attribution']['desc'] = sprintf( esc_html__( 'This allows you to set the domain that\'s set by %1$s for tracking subdomains. If empty, this will not be set. Can be used to set localhost for ga.js tracking.', 'google-analytics-for-wordpress' ), '<a href="https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._setDomainName" target="_blank" rel="noopener noreferrer" referrer="no-referrer"><code>_setDomainName</code></a>' ); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + // Addons: |
|
45 | + // Social |
|
46 | + $settings['social']['social_notice'] = array( |
|
47 | + 'id' => 'social_notice', |
|
48 | + 'no_label' => true, |
|
49 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
50 | + 'type' => 'upgrade_notice', |
|
51 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Social tracking to see who's clicking on your social share links, so you can track and maximize your social sharing exposure.", 'google-analytics-for-wordpress' ) |
|
52 | + ); |
|
53 | + |
|
54 | + // Ads |
|
55 | + $settings['ads']['ads_notice'] = array( |
|
56 | + 'id' => 'ads_notice', |
|
57 | + 'no_label' => true, |
|
58 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
59 | + 'type' => 'upgrade_notice', |
|
60 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Ads tracking to see who's clicking on your Google Ads, so you can increase your revenue.", 'google-analytics-for-wordpress' ) |
|
61 | + ); |
|
62 | + |
|
63 | + // Forms |
|
64 | + $settings['forms']['forms_notice'] = array( |
|
65 | + 'id' => 'forms_notice', |
|
66 | + 'no_label' => true, |
|
67 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
68 | + 'type' => 'upgrade_notice', |
|
69 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Forms tracking to see who's seeing and submitting your forms, so you can increase your conversion rate.", 'google-analytics-for-wordpress' ) |
|
70 | + ); |
|
71 | + |
|
72 | + // Media |
|
73 | + $settings['media']['media_notice'] = array( |
|
74 | + 'id' => 'media_notice', |
|
75 | + 'no_label' => true, |
|
76 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
77 | + 'type' => 'upgrade_notice', |
|
78 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Media tracking to see who's interacting with the media on your site, so you know what your users are most interested in on your site. You can use this to tailor future content to meet your audience's interest to promote repeat visitors and expand your average user's time spent visiting your website on each visit.", 'google-analytics-for-wordpress' ) |
|
79 | + ); |
|
80 | + |
|
81 | + // Membership |
|
82 | + $settings['membership']['membership_notice'] = array( |
|
83 | + 'id' => 'membership_notice', |
|
84 | + 'no_label' => true, |
|
85 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
86 | + 'type' => 'upgrade_notice', |
|
87 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Membership tracking.", 'google-analytics-for-wordpress' ) |
|
88 | + ); |
|
89 | + |
|
90 | + // Dimensions |
|
91 | + $settings['dimensions']['dimensions_notice'] = array( |
|
92 | + 'id' => 'dimensions_notice', |
|
93 | + 'no_label' => true, |
|
94 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
95 | + 'type' => 'upgrade_notice', |
|
96 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Custom Dimensions and track who's the most popular author on your site, which post types get the most traffic, and more. Why not check it out?", 'google-analytics-for-wordpress' ) |
|
97 | + ); |
|
98 | + |
|
99 | + // Performance |
|
100 | + $settings['performance']['performance_notice'] = array( |
|
101 | + 'id' => 'performance_notice', |
|
102 | + 'no_label' => true, |
|
103 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
104 | + 'type' => 'upgrade_notice', |
|
105 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can adjust the sample rate so you don't exceed Google Analytics' processing limit. You can also use it to enable Google Optimize for A/B testing and personalization.", 'google-analytics-for-wordpress' ) |
|
106 | + ); |
|
107 | + |
|
108 | + // Reporting |
|
109 | + $settings['reporting']['reporting_notice'] = array( |
|
110 | + 'id' => 'reporting_notice', |
|
111 | + 'no_label' => true, |
|
112 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
113 | + 'type' => 'upgrade_notice', |
|
114 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable enhanced reporting.", 'google-analytics-for-wordpress' ) |
|
115 | + ); |
|
116 | + |
|
117 | + // Google AMP |
|
118 | + $settings['amp']['amp_notice'] = array( |
|
119 | + 'id' => 'amp_notice', |
|
120 | + 'no_label' => true, |
|
121 | + 'name' => __( 'Want to use track users visiting your AMP pages?', 'google-analytics-for-wordpress'), |
|
122 | + 'type' => 'upgrade_notice', |
|
123 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable AMP page tracking.", 'google-analytics-for-wordpress' ) |
|
124 | + ); |
|
125 | + |
|
126 | + // Google Optimize |
|
127 | + $settings['goptimize']['goptimize_notice'] = array( |
|
128 | + 'id' => 'goptimize_notice', |
|
129 | + 'no_label' => true, |
|
130 | + 'name' => __( 'Want to use Google Optimize to retarget your website vistors and perform A/B split tests with ease?', 'google-analytics-for-wordpress'), |
|
131 | + 'type' => 'upgrade_notice', |
|
132 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable Google Optimize.", 'google-analytics-for-wordpress' ) |
|
133 | + ); |
|
134 | + |
|
135 | + // Facebook Instant Articles |
|
136 | + $settings['fbia']['fbia_notice'] = array( |
|
137 | + 'id' => 'fbia_notice', |
|
138 | + 'no_label' => true, |
|
139 | + 'name' => __( 'Want to expand your website audience beyond your website with Facebook Instant Articles?', 'google-analytics-for-wordpress'), |
|
140 | + 'type' => 'upgrade_notice', |
|
141 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can track your Facebook Instant Article visitors with MonsterInsights.", 'google-analytics-for-wordpress' ) |
|
142 | + ); |
|
143 | + |
|
144 | + // Bounce Reduction |
|
145 | + $settings['bounce']['bounce_notice'] = array( |
|
146 | + 'id' => 'bounce_notice', |
|
147 | + 'no_label' => true, |
|
148 | + 'name' => __( 'Want to adjust your website bounce rate?', 'google-analytics-for-wordpress'), |
|
149 | + 'type' => 'upgrade_notice', |
|
150 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can adjust your Google Analytics bounce rate with MonsterInsights.", 'google-analytics-for-wordpress' ) |
|
151 | + ); |
|
152 | + |
|
153 | + // Notifications |
|
154 | + $settings['notifications']['notifications_notice'] = array( |
|
155 | + 'id' => 'notifications_notice', |
|
156 | + 'no_label' => true, |
|
157 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
158 | + 'type' => 'upgrade_notice', |
|
159 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can enable notifications.", 'google-analytics-for-wordpress' ) |
|
160 | + ); |
|
161 | + |
|
162 | + // eCommerce |
|
163 | + $settings['ecommerce']['ecommerce_notice'] = array( |
|
164 | + 'id' => 'ecommerce_notice', |
|
165 | + 'no_label' => true, |
|
166 | + 'name' => __( 'Want to increase your traffic, conversion, & engagement?', 'google-analytics-for-wordpress'), |
|
167 | + 'type' => 'upgrade_notice', |
|
168 | + 'desc' => esc_html__( "By upgrading to MonsterInsights Pro, you can add Ecommerce tracking to see who's buying your product, what's the most popular item on your store, the average order value, and tons more.", 'google-analytics-for-wordpress' ) |
|
169 | + ); |
|
170 | + |
|
171 | + return $settings; |
|
172 | 172 | } |
173 | 173 | add_filter( 'monsterinsights_registered_settings', 'monsterinsights_registered_settings_filter' ); |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | 7 | function monsterinsights_tools_url_builder() { |
8 | - ob_start();?> |
|
8 | + ob_start(); ?> |
|
9 | 9 | <div class="monsterinsights-upsell-under-box"> |
10 | - <h2><?php esc_html_e( "Want even more fine tuned control over your website analytics?", 'google-analytics-for-wordpress' ); ?></h2> |
|
11 | - <p class="monsterinsights-upsell-lite-text"><?php esc_html_e( "By upgrading to MonsterInsights Pro, you can unlock the MonsterInsights URL builder that helps you better track your advertising and email marketing campaigns.", 'google-analytics-for-wordpress' ); ?></p> |
|
12 | - <p><a href="<?php echo monsterinsights_get_upgrade_link(); ?>" class="button button-primary"><?php esc_html_e( "Click here to Upgrade", 'google-analytics-for-wordpress' ); ?></a></p> |
|
10 | + <h2><?php esc_html_e("Want even more fine tuned control over your website analytics?", 'google-analytics-for-wordpress'); ?></h2> |
|
11 | + <p class="monsterinsights-upsell-lite-text"><?php esc_html_e("By upgrading to MonsterInsights Pro, you can unlock the MonsterInsights URL builder that helps you better track your advertising and email marketing campaigns.", 'google-analytics-for-wordpress'); ?></p> |
|
12 | + <p><a href="<?php echo monsterinsights_get_upgrade_link(); ?>" class="button button-primary"><?php esc_html_e("Click here to Upgrade", 'google-analytics-for-wordpress'); ?></a></p> |
|
13 | 13 | </div> |
14 | 14 | <?php |
15 | 15 | echo ob_get_clean(); |
16 | 16 | } |
17 | -add_action( 'monsterinsights_tools_url_builder_tab', 'monsterinsights_tools_url_builder' ); |
|
18 | 17 | \ No newline at end of file |
18 | +add_action('monsterinsights_tools_url_builder_tab', 'monsterinsights_tools_url_builder'); |
|
19 | 19 | \ No newline at end of file |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; |
|
4 | + exit; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function monsterinsights_tools_url_builder() { |
8 | - ob_start();?> |
|
8 | + ob_start();?> |
|
9 | 9 | <div class="monsterinsights-upsell-under-box"> |
10 | 10 | <h2><?php esc_html_e( "Want even more fine tuned control over your website analytics?", 'google-analytics-for-wordpress' ); ?></h2> |
11 | 11 | <p class="monsterinsights-upsell-lite-text"><?php esc_html_e( "By upgrading to MonsterInsights Pro, you can unlock the MonsterInsights URL builder that helps you better track your advertising and email marketing campaigns.", 'google-analytics-for-wordpress' ); ?></p> |
12 | 12 | <p><a href="<?php echo monsterinsights_get_upgrade_link(); ?>" class="button button-primary"><?php esc_html_e( "Click here to Upgrade", 'google-analytics-for-wordpress' ); ?></a></p> |
13 | 13 | </div> |
14 | 14 | <?php |
15 | - echo ob_get_clean(); |
|
15 | + echo ob_get_clean(); |
|
16 | 16 | } |
17 | 17 | add_action( 'monsterinsights_tools_url_builder_tab', 'monsterinsights_tools_url_builder' ); |
18 | 18 | \ No newline at end of file |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
13 | +if ( ! defined('ABSPATH')) exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Callback for displaying the UI for support tab. |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | <div id="monsterinsights-settings-general"> |
26 | 26 | <?php |
27 | 27 | // Output any notices now |
28 | - do_action( 'monsterinsights_settings_support_tab_notice' ); |
|
28 | + do_action('monsterinsights_settings_support_tab_notice'); |
|
29 | 29 | ?> |
30 | 30 | <?php //Status page coming soon. ?> |
31 | 31 | <!-- <hr /> --> |
@@ -10,7 +10,9 @@ |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
13 | +if ( ! defined( 'ABSPATH' ) ) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * Callback for displaying the UI for support tab. |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | // Add default |
23 | 23 | //do_action( 'monsterinsights_after_install_routine', $version ); |
24 | 24 | |
25 | -function monsterinsights_lite_upgrade_from_yoast( $key, $network ) { |
|
26 | - if ( $network ) { |
|
25 | +function monsterinsights_lite_upgrade_from_yoast($key, $network) { |
|
26 | + if ($network) { |
|
27 | 27 | $option = array(); |
28 | 28 | $option['key'] = $key; |
29 | 29 | $option['type'] = ''; |
30 | 30 | $option['is_expired'] = false; |
31 | 31 | $option['is_disabled'] = false; |
32 | 32 | $option['is_invalid'] = false; |
33 | - update_site_option( 'monsterinsights_license', $option ); |
|
33 | + update_site_option('monsterinsights_license', $option); |
|
34 | 34 | } else { |
35 | 35 | $option = array(); |
36 | 36 | $option['key'] = $key; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $option['is_expired'] = false; |
39 | 39 | $option['is_disabled'] = false; |
40 | 40 | $option['is_invalid'] = false; |
41 | - update_option( 'monsterinsights_license', $option ); |
|
41 | + update_option('monsterinsights_license', $option); |
|
42 | 42 | } |
43 | 43 | } |
44 | -add_action( 'monsterinsights_upgrade_from_yoast', 'monsterinsights_lite_upgrade_from_yoast', 10, 2 ); |
|
44 | +add_action('monsterinsights_upgrade_from_yoast', 'monsterinsights_lite_upgrade_from_yoast', 10, 2); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
14 | - exit; |
|
14 | + exit; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | // @todo: Add defaults for new installs |
@@ -23,22 +23,22 @@ discard block |
||
23 | 23 | //do_action( 'monsterinsights_after_install_routine', $version ); |
24 | 24 | |
25 | 25 | function monsterinsights_lite_upgrade_from_yoast( $key, $network ) { |
26 | - if ( $network ) { |
|
27 | - $option = array(); |
|
28 | - $option['key'] = $key; |
|
29 | - $option['type'] = ''; |
|
30 | - $option['is_expired'] = false; |
|
31 | - $option['is_disabled'] = false; |
|
32 | - $option['is_invalid'] = false; |
|
33 | - update_site_option( 'monsterinsights_license', $option ); |
|
34 | - } else { |
|
35 | - $option = array(); |
|
36 | - $option['key'] = $key; |
|
37 | - $option['type'] = ''; |
|
38 | - $option['is_expired'] = false; |
|
39 | - $option['is_disabled'] = false; |
|
40 | - $option['is_invalid'] = false; |
|
41 | - update_option( 'monsterinsights_license', $option ); |
|
42 | - } |
|
26 | + if ( $network ) { |
|
27 | + $option = array(); |
|
28 | + $option['key'] = $key; |
|
29 | + $option['type'] = ''; |
|
30 | + $option['is_expired'] = false; |
|
31 | + $option['is_disabled'] = false; |
|
32 | + $option['is_invalid'] = false; |
|
33 | + update_site_option( 'monsterinsights_license', $option ); |
|
34 | + } else { |
|
35 | + $option = array(); |
|
36 | + $option['key'] = $key; |
|
37 | + $option['type'] = ''; |
|
38 | + $option['is_expired'] = false; |
|
39 | + $option['is_disabled'] = false; |
|
40 | + $option['is_invalid'] = false; |
|
41 | + update_option( 'monsterinsights_license', $option ); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | add_action( 'monsterinsights_upgrade_from_yoast', 'monsterinsights_lite_upgrade_from_yoast', 10, 2 ); |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | 'scopes' => $scopes, |
17 | 17 | ); |
18 | 18 | |
19 | - $config = apply_filters( 'monsterinsights_lite_google_app_config', $config ); |
|
19 | + $config = apply_filters('monsterinsights_lite_google_app_config', $config); |
|
20 | 20 | $config['scopes'] = $scopes; // Scopes requested are not changeable to minimize breakage. |
21 | 21 | return $config; |
22 | 22 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/src/Google/autoload.php'; |
26 | 26 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/class-ga-client.php'; |
27 | 27 | $config = monsterinsights_google_app_config(); |
28 | - $client = new MonsterInsights_GA_Client( $config, 'lite' ); |
|
28 | + $client = new MonsterInsights_GA_Client($config, 'lite'); |
|
29 | 29 | return $client; |
30 | 30 | } |
31 | 31 | |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/src/Google/autoload.php'; |
34 | 34 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/class-ga-client.php'; |
35 | 35 | $config = monsterinsights_google_app_config(); |
36 | - $client = new MonsterInsights_GA_Client( $config, 'test_lite' ); |
|
36 | + $client = new MonsterInsights_GA_Client($config, 'test_lite'); |
|
37 | 37 | return $client; |
38 | 38 | } |
39 | 39 | |
40 | -function monsterinsights_set_client_oauth_version(){ |
|
41 | - monsterinsights_update_option( 'oauth_version', '1.0' ); |
|
40 | +function monsterinsights_set_client_oauth_version() { |
|
41 | + monsterinsights_update_option('oauth_version', '1.0'); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | function monsterinsights_get_report_date_range() { |
45 | 45 | return array( |
46 | - 'start' => date( 'Y-m-d', strtotime( '-1 month' ) ), |
|
47 | - 'end' => date( 'Y-m-d', strtotime( 'yesterday' ) ), |
|
46 | + 'start' => date('Y-m-d', strtotime('-1 month')), |
|
47 | + 'end' => date('Y-m-d', strtotime('yesterday')), |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -1,49 +1,49 @@ |
||
1 | 1 | <?php |
2 | 2 | function monsterinsights_google_app_config() { |
3 | - // We'll go ahead and ask for these permissions on new installs |
|
4 | - $scopes = array( |
|
5 | - 'https://www.googleapis.com/auth/analytics.readonly', |
|
6 | - 'https://www.googleapis.com/auth/analytics', |
|
7 | - // 'https://www.googleapis.com/auth/analytics.manage.users', |
|
8 | - // 'https://www.googleapis.com/auth/tagmanager.readonly', |
|
9 | - // 'https://www.googleapis.com/auth/webmasters.readonly' |
|
10 | - ); |
|
11 | - $config = array( |
|
12 | - 'application_name' => 'Google Analytics by MonsterInsights', |
|
13 | - 'client_id' => '346753076522-21smrc6aq0hq8oij8001s57dfoo8igf5.apps.googleusercontent.com', |
|
14 | - 'client_secret' => '5oWaEGFgp-bSrY6vWBmdPfIF', |
|
15 | - 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob', |
|
16 | - 'scopes' => $scopes, |
|
17 | - ); |
|
3 | + // We'll go ahead and ask for these permissions on new installs |
|
4 | + $scopes = array( |
|
5 | + 'https://www.googleapis.com/auth/analytics.readonly', |
|
6 | + 'https://www.googleapis.com/auth/analytics', |
|
7 | + // 'https://www.googleapis.com/auth/analytics.manage.users', |
|
8 | + // 'https://www.googleapis.com/auth/tagmanager.readonly', |
|
9 | + // 'https://www.googleapis.com/auth/webmasters.readonly' |
|
10 | + ); |
|
11 | + $config = array( |
|
12 | + 'application_name' => 'Google Analytics by MonsterInsights', |
|
13 | + 'client_id' => '346753076522-21smrc6aq0hq8oij8001s57dfoo8igf5.apps.googleusercontent.com', |
|
14 | + 'client_secret' => '5oWaEGFgp-bSrY6vWBmdPfIF', |
|
15 | + 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob', |
|
16 | + 'scopes' => $scopes, |
|
17 | + ); |
|
18 | 18 | |
19 | - $config = apply_filters( 'monsterinsights_lite_google_app_config', $config ); |
|
20 | - $config['scopes'] = $scopes; // Scopes requested are not changeable to minimize breakage. |
|
21 | - return $config; |
|
19 | + $config = apply_filters( 'monsterinsights_lite_google_app_config', $config ); |
|
20 | + $config['scopes'] = $scopes; // Scopes requested are not changeable to minimize breakage. |
|
21 | + return $config; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | function monsterinsights_create_client() { |
25 | - require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/src/Google/autoload.php'; |
|
26 | - require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/class-ga-client.php'; |
|
27 | - $config = monsterinsights_google_app_config(); |
|
28 | - $client = new MonsterInsights_GA_Client( $config, 'lite' ); |
|
29 | - return $client; |
|
25 | + require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/src/Google/autoload.php'; |
|
26 | + require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/class-ga-client.php'; |
|
27 | + $config = monsterinsights_google_app_config(); |
|
28 | + $client = new MonsterInsights_GA_Client( $config, 'lite' ); |
|
29 | + return $client; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | function monsterinsights_create_test_client() { |
33 | - require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/src/Google/autoload.php'; |
|
34 | - require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/class-ga-client.php'; |
|
35 | - $config = monsterinsights_google_app_config(); |
|
36 | - $client = new MonsterInsights_GA_Client( $config, 'test_lite' ); |
|
37 | - return $client; |
|
33 | + require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/src/Google/autoload.php'; |
|
34 | + require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/google/class-ga-client.php'; |
|
35 | + $config = monsterinsights_google_app_config(); |
|
36 | + $client = new MonsterInsights_GA_Client( $config, 'test_lite' ); |
|
37 | + return $client; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | function monsterinsights_set_client_oauth_version(){ |
41 | - monsterinsights_update_option( 'oauth_version', '1.0' ); |
|
41 | + monsterinsights_update_option( 'oauth_version', '1.0' ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | function monsterinsights_get_report_date_range() { |
45 | - return array( |
|
46 | - 'start' => date( 'Y-m-d', strtotime( '-1 month' ) ), |
|
47 | - 'end' => date( 'Y-m-d', strtotime( 'yesterday' ) ), |
|
48 | - ); |
|
45 | + return array( |
|
46 | + 'start' => date( 'Y-m-d', strtotime( '-1 month' ) ), |
|
47 | + 'end' => date( 'Y-m-d', strtotime( 'yesterday' ) ), |
|
48 | + ); |
|
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! class_exists( 'AM_Deactivation_Survey' ) ) { |
|
2 | +if ( ! class_exists('AM_Deactivation_Survey')) { |
|
3 | 3 | /** |
4 | 4 | * Awesome Motive Deactivation Survey. |
5 | 5 | * |
@@ -44,14 +44,14 @@ discard block |
||
44 | 44 | * @param string $name Plugin name. |
45 | 45 | * @param string $plugin Plugin slug. |
46 | 46 | */ |
47 | - public function __construct( $name = '', $plugin = '' ) { |
|
47 | + public function __construct($name = '', $plugin = '') { |
|
48 | 48 | |
49 | 49 | $this->name = $name; |
50 | 50 | $this->plugin = $plugin; |
51 | 51 | |
52 | - add_action( 'admin_print_scripts', array( $this, 'js' ), 20 ); |
|
53 | - add_action( 'admin_print_scripts', array( $this, 'css' ) ); |
|
54 | - add_action( 'admin_footer', array( $this, 'modal' ) ); |
|
52 | + add_action('admin_print_scripts', array($this, 'js'), 20); |
|
53 | + add_action('admin_print_scripts', array($this, 'css')); |
|
54 | + add_action('admin_footer', array($this, 'modal')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function is_plugin_page() { |
64 | 64 | |
65 | - return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) ); |
|
65 | + return (in_array(get_current_screen()->id, array('plugins', 'plugins-network'), true)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function js() { |
74 | 74 | |
75 | - if ( ! $this->is_plugin_page() ) { |
|
75 | + if ( ! $this->is_plugin_page()) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | ?> |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | $form.submit(function(event) { |
106 | 106 | event.preventDefault(); |
107 | 107 | if (! $form.find('input[type=radio]:checked').val()) { |
108 | - $form.find('.am-deactivate-survey-footer').prepend('<span class="error"><?php echo esc_js( __( 'Please select an option', 'google-analytics-for-wordpress' ) ); ?></span>'); |
|
108 | + $form.find('.am-deactivate-survey-footer').prepend('<span class="error"><?php echo esc_js(__('Please select an option', 'google-analytics-for-wordpress')); ?></span>'); |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | var data = { |
112 | 112 | code: $form.find('.selected input[type=radio]').val(), |
113 | 113 | reason: $form.find('.selected .am-deactivate-survey-option-reason').text(), |
114 | 114 | details: $form.find('.selected input[type=text]').val(), |
115 | - site: '<?php echo esc_url( home_url() ); ?>', |
|
116 | - plugin: '<?php echo sanitize_key( $this->name ); ?>' |
|
115 | + site: '<?php echo esc_url(home_url()); ?>', |
|
116 | + plugin: '<?php echo sanitize_key($this->name); ?>' |
|
117 | 117 | } |
118 | 118 | var submitSurvey = $.post('<?php echo $this->api_url; ?>', data); |
119 | 119 | submitSurvey.always(function() { |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function css() { |
142 | 142 | |
143 | - if ( ! $this->is_plugin_page() ) { |
|
143 | + if ( ! $this->is_plugin_page()) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | ?> |
@@ -224,51 +224,51 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function modal() { |
226 | 226 | |
227 | - if ( ! $this->is_plugin_page() ) { |
|
227 | + if ( ! $this->is_plugin_page()) { |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
231 | 231 | $options = array( |
232 | 232 | 1 => array( |
233 | - 'title' => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ), |
|
233 | + 'title' => esc_html__('I no longer need the plugin', 'google-analytics-for-wordpress'), |
|
234 | 234 | ), |
235 | 235 | 2 => array( |
236 | - 'title' => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ), |
|
237 | - 'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ), |
|
236 | + 'title' => esc_html__('I\'m switching to a different plugin', 'google-analytics-for-wordpress'), |
|
237 | + 'details' => esc_html__('Please share which plugin', 'google-analytics-for-wordpress'), |
|
238 | 238 | ), |
239 | 239 | 3 => array( |
240 | - 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ), |
|
240 | + 'title' => esc_html__('I couldn\'t get the plugin to work', 'google-analytics-for-wordpress'), |
|
241 | 241 | ), |
242 | 242 | 4 => array( |
243 | - 'title' => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ), |
|
243 | + 'title' => esc_html__('It\'s a temporary deactivation', 'google-analytics-for-wordpress'), |
|
244 | 244 | ), |
245 | 245 | 5 => array( |
246 | - 'title' => esc_html__( 'Other', 'google-analytics-for-wordpress' ), |
|
247 | - 'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ), |
|
246 | + 'title' => esc_html__('Other', 'google-analytics-for-wordpress'), |
|
247 | + 'details' => esc_html__('Please share the reason', 'google-analytics-for-wordpress'), |
|
248 | 248 | ), |
249 | 249 | ); |
250 | 250 | ?> |
251 | 251 | <div class="am-deactivate-survey-modal" id="am-deactivate-survey-<?php echo $this->plugin; ?>"> |
252 | 252 | <div class="am-deactivate-survey-wrap"> |
253 | 253 | <form class="am-deactivate-survey" method="post"> |
254 | - <span class="am-deactivate-survey-title"><span class="dashicons dashicons-testimonial"></span><?php echo ' ' . esc_html__( 'Quick Feedback', 'google-analytics-for-wordpress' ); ?></span> |
|
255 | - <span class="am-deactivate-survey-desc"><?php echo sprintf( esc_html__('If you have a moment, please share why you are deactivating %s:', 'google-analytics-for-wordpress' ), $this->name ); ?></span> |
|
254 | + <span class="am-deactivate-survey-title"><span class="dashicons dashicons-testimonial"></span><?php echo ' ' . esc_html__('Quick Feedback', 'google-analytics-for-wordpress'); ?></span> |
|
255 | + <span class="am-deactivate-survey-desc"><?php echo sprintf(esc_html__('If you have a moment, please share why you are deactivating %s:', 'google-analytics-for-wordpress'), $this->name); ?></span> |
|
256 | 256 | <div class="am-deactivate-survey-options"> |
257 | - <?php foreach ( $options as $id => $option ) : ?> |
|
257 | + <?php foreach ($options as $id => $option) : ?> |
|
258 | 258 | <div class="am-deactivate-survey-option"> |
259 | 259 | <label for="am-deactivate-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="am-deactivate-survey-option-label"> |
260 | 260 | <input id="am-deactivate-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="am-deactivate-survey-option-input" type="radio" name="code" value="<?php echo $id; ?>" /> |
261 | 261 | <span class="am-deactivate-survey-option-reason"><?php echo $option['title']; ?></span> |
262 | 262 | </label> |
263 | - <?php if ( ! empty( $option['details'] ) ) : ?> |
|
263 | + <?php if ( ! empty($option['details'])) : ?> |
|
264 | 264 | <input class="am-deactivate-survey-option-details" type="text" placeholder="<?php echo $option['details']; ?>" /> |
265 | 265 | <?php endif; ?> |
266 | 266 | </div> |
267 | 267 | <?php endforeach; ?> |
268 | 268 | </div> |
269 | 269 | <div class="am-deactivate-survey-footer"> |
270 | - <button type="submit" class="am-deactivate-survey-submit button button-primary button-large"><?php echo sprintf( esc_html__('Submit %s Deactivate', 'google-analytics-for-wordpress' ), '&' ); ?></button> |
|
271 | - <a href="#" class="am-deactivate-survey-deactivate"><?php echo sprintf( esc_html__('Skip %s Deactivate', 'google-analytics-for-wordpress' ), '&' ); ?></a> |
|
270 | + <button type="submit" class="am-deactivate-survey-submit button button-primary button-large"><?php echo sprintf(esc_html__('Submit %s Deactivate', 'google-analytics-for-wordpress'), '&'); ?></button> |
|
271 | + <a href="#" class="am-deactivate-survey-deactivate"><?php echo sprintf(esc_html__('Skip %s Deactivate', 'google-analytics-for-wordpress'), '&'); ?></a> |
|
272 | 272 | </div> |
273 | 273 | </form> |
274 | 274 | </div> |
@@ -1,81 +1,81 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! class_exists( 'AM_Deactivation_Survey' ) ) { |
3 | - /** |
|
4 | - * Awesome Motive Deactivation Survey. |
|
5 | - * |
|
6 | - * This prompts the user for more details when they deactivate the plugin. |
|
7 | - * |
|
8 | - * @version 1.1.0 |
|
9 | - * @package AwesomeMotive |
|
10 | - * @author Jared Atchison |
|
11 | - * @license GPL-2.0+ |
|
12 | - * @copyright Copyright (c) 2017 |
|
13 | - */ |
|
14 | - class AM_Deactivation_Survey { |
|
3 | + /** |
|
4 | + * Awesome Motive Deactivation Survey. |
|
5 | + * |
|
6 | + * This prompts the user for more details when they deactivate the plugin. |
|
7 | + * |
|
8 | + * @version 1.1.0 |
|
9 | + * @package AwesomeMotive |
|
10 | + * @author Jared Atchison |
|
11 | + * @license GPL-2.0+ |
|
12 | + * @copyright Copyright (c) 2017 |
|
13 | + */ |
|
14 | + class AM_Deactivation_Survey { |
|
15 | 15 | |
16 | - /** |
|
17 | - * The API URL we are calling. |
|
18 | - * |
|
19 | - * @since 1.0.0 |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $api_url = 'https://api.awesomemotive.com/v1/deactivation-survey/'; |
|
16 | + /** |
|
17 | + * The API URL we are calling. |
|
18 | + * |
|
19 | + * @since 1.0.0 |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $api_url = 'https://api.awesomemotive.com/v1/deactivation-survey/'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Name for this plugin. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public $name; |
|
24 | + /** |
|
25 | + * Name for this plugin. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public $name; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Unique slug for this plugin. |
|
34 | - * |
|
35 | - * @since 1.0.0 |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $plugin; |
|
32 | + /** |
|
33 | + * Unique slug for this plugin. |
|
34 | + * |
|
35 | + * @since 1.0.0 |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $plugin; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Primary class constructor. |
|
42 | - * |
|
43 | - * @since 1.0.0 |
|
44 | - * @param string $name Plugin name. |
|
45 | - * @param string $plugin Plugin slug. |
|
46 | - */ |
|
47 | - public function __construct( $name = '', $plugin = '' ) { |
|
40 | + /** |
|
41 | + * Primary class constructor. |
|
42 | + * |
|
43 | + * @since 1.0.0 |
|
44 | + * @param string $name Plugin name. |
|
45 | + * @param string $plugin Plugin slug. |
|
46 | + */ |
|
47 | + public function __construct( $name = '', $plugin = '' ) { |
|
48 | 48 | |
49 | - $this->name = $name; |
|
50 | - $this->plugin = $plugin; |
|
49 | + $this->name = $name; |
|
50 | + $this->plugin = $plugin; |
|
51 | 51 | |
52 | - add_action( 'admin_print_scripts', array( $this, 'js' ), 20 ); |
|
53 | - add_action( 'admin_print_scripts', array( $this, 'css' ) ); |
|
54 | - add_action( 'admin_footer', array( $this, 'modal' ) ); |
|
55 | - } |
|
52 | + add_action( 'admin_print_scripts', array( $this, 'js' ), 20 ); |
|
53 | + add_action( 'admin_print_scripts', array( $this, 'css' ) ); |
|
54 | + add_action( 'admin_footer', array( $this, 'modal' ) ); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Checks if current admin screen is the plugins page. |
|
59 | - * |
|
60 | - * @since 1.0.0 |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public function is_plugin_page() { |
|
57 | + /** |
|
58 | + * Checks if current admin screen is the plugins page. |
|
59 | + * |
|
60 | + * @since 1.0.0 |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public function is_plugin_page() { |
|
64 | 64 | |
65 | - return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) ); |
|
66 | - } |
|
65 | + return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) ); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Survey javascript. |
|
70 | - * |
|
71 | - * @since 1.0.0 |
|
72 | - */ |
|
73 | - public function js() { |
|
68 | + /** |
|
69 | + * Survey javascript. |
|
70 | + * |
|
71 | + * @since 1.0.0 |
|
72 | + */ |
|
73 | + public function js() { |
|
74 | 74 | |
75 | - if ( ! $this->is_plugin_page() ) { |
|
76 | - return; |
|
77 | - } |
|
78 | - ?> |
|
75 | + if ( ! $this->is_plugin_page() ) { |
|
76 | + return; |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | <script type="text/javascript"> |
80 | 80 | jQuery(function($){ |
81 | 81 | var $deactivateLink = $('#the-list').find('[data-slug="<?php echo $this->plugin; ?>"] span.deactivate a'), |
@@ -131,19 +131,19 @@ discard block |
||
131 | 131 | }); |
132 | 132 | </script> |
133 | 133 | <?php |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Survey CSS. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - */ |
|
141 | - public function css() { |
|
136 | + /** |
|
137 | + * Survey CSS. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + */ |
|
141 | + public function css() { |
|
142 | 142 | |
143 | - if ( ! $this->is_plugin_page() ) { |
|
144 | - return; |
|
145 | - } |
|
146 | - ?> |
|
143 | + if ( ! $this->is_plugin_page() ) { |
|
144 | + return; |
|
145 | + } |
|
146 | + ?> |
|
147 | 147 | <style type="text/css"> |
148 | 148 | .am-deactivate-survey-modal { |
149 | 149 | display: none; |
@@ -215,39 +215,39 @@ discard block |
||
215 | 215 | } |
216 | 216 | </style> |
217 | 217 | <?php |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Survey modal. |
|
222 | - * |
|
223 | - * @since 1.0.0 |
|
224 | - */ |
|
225 | - public function modal() { |
|
220 | + /** |
|
221 | + * Survey modal. |
|
222 | + * |
|
223 | + * @since 1.0.0 |
|
224 | + */ |
|
225 | + public function modal() { |
|
226 | 226 | |
227 | - if ( ! $this->is_plugin_page() ) { |
|
228 | - return; |
|
229 | - } |
|
227 | + if ( ! $this->is_plugin_page() ) { |
|
228 | + return; |
|
229 | + } |
|
230 | 230 | |
231 | - $options = array( |
|
232 | - 1 => array( |
|
233 | - 'title' => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ), |
|
234 | - ), |
|
235 | - 2 => array( |
|
236 | - 'title' => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ), |
|
237 | - 'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ), |
|
238 | - ), |
|
239 | - 3 => array( |
|
240 | - 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ), |
|
241 | - ), |
|
242 | - 4 => array( |
|
243 | - 'title' => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ), |
|
244 | - ), |
|
245 | - 5 => array( |
|
246 | - 'title' => esc_html__( 'Other', 'google-analytics-for-wordpress' ), |
|
247 | - 'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ), |
|
248 | - ), |
|
249 | - ); |
|
250 | - ?> |
|
231 | + $options = array( |
|
232 | + 1 => array( |
|
233 | + 'title' => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ), |
|
234 | + ), |
|
235 | + 2 => array( |
|
236 | + 'title' => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ), |
|
237 | + 'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ), |
|
238 | + ), |
|
239 | + 3 => array( |
|
240 | + 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ), |
|
241 | + ), |
|
242 | + 4 => array( |
|
243 | + 'title' => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ), |
|
244 | + ), |
|
245 | + 5 => array( |
|
246 | + 'title' => esc_html__( 'Other', 'google-analytics-for-wordpress' ), |
|
247 | + 'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ), |
|
248 | + ), |
|
249 | + ); |
|
250 | + ?> |
|
251 | 251 | <div class="am-deactivate-survey-modal" id="am-deactivate-survey-<?php echo $this->plugin; ?>"> |
252 | 252 | <div class="am-deactivate-survey-wrap"> |
253 | 253 | <form class="am-deactivate-survey" method="post"> |
@@ -274,6 +274,6 @@ discard block |
||
274 | 274 | </div> |
275 | 275 | </div> |
276 | 276 | <?php |
277 | - } |
|
278 | - } |
|
277 | + } |
|
278 | + } |
|
279 | 279 | } // End if(). |
280 | 280 | \ No newline at end of file |