| 1 |
<?php |
| 2 |
/** |
| 3 |
* Author: Alin Marcu |
| 4 |
* Copyright 2019 Alin Marcu |
| 5 |
* Author URI: https://deconf.com |
| 6 |
* License: GPLv2 or later |
| 7 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if ( ! defined( 'ABSPATH' ) ) |
| 11 |
exit(); |
| 12 |
|
| 13 |
if ( ! class_exists( 'CAWP_Tracking' ) ) { |
| 14 |
|
| 15 |
final class CAWP_Tracking { |
| 16 |
|
| 17 |
private $cawp; |
| 18 |
|
| 19 |
public function __construct() { |
| 20 |
$this->cawp = CAWP(); |
| 21 |
/** |
| 22 |
* Add verification META |
| 23 |
*/ |
| 24 |
add_action( 'wp_head', array( $this, 'output' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
public function output() { |
| 28 |
global $current_user; |
| 29 |
$custom_tracking = ""; |
| 30 |
wp_get_current_user(); |
| 31 |
if ( $current_user->user_login ) { |
| 32 |
if ( ( $this->cawp->config->options['track_username'] ) and ( ( $this->cawp->config->options['track_email'] ) ) ) { |
| 33 |
$custom_tracking = "<script type=\"text/javascript\"> |
| 34 |
var clicky_custom = clicky_custom || {}; |
| 35 |
clicky_custom.visitor = clicky_custom.visitor || {}; |
| 36 |
clicky_custom.visitor [\"username\"] = '" . $current_user->user_login . "'; |
| 37 |
clicky_custom.visitor [\"email\"] = '" . $current_user->user_email . "'; |
| 38 |
</script>\n"; |
| 39 |
} else if ( $this->cawp->config->options['track_username'] ) { |
| 40 |
$custom_tracking = "<script type=\"text/javascript\"> |
| 41 |
var clicky_custom = clicky_custom || {}; |
| 42 |
clicky_custom.visitor = clicky_custom.visitor || {}; |
| 43 |
clicky_custom.visitor [\"username\"] = '" . $current_user->user_login . "'; |
| 44 |
</script>\n"; |
| 45 |
} else if ( $this->cawp->config->options['track_email'] ) { |
| 46 |
$custom_tracking = "<script type=\"text/javascript\"> |
| 47 |
var clicky_custom = clicky_custom || {}; |
| 48 |
clicky_custom.visitor = clicky_custom.visitor || {}; |
| 49 |
clicky_custom.visitor [\"email\"] = '" . $current_user->user_email . "'; |
| 50 |
</script>\n"; |
| 51 |
} |
| 52 |
} |
| 53 |
$video_tracking = ""; |
| 54 |
if ( $this->cawp->config->options['track_youtube'] ) { |
| 55 |
$video_tracking .= "<script src='//static.getclicky.com/inc/javascript/video/youtube.js'></script>"; |
| 56 |
} |
| 57 |
if ( $this->cawp->config->options['track_html5'] ) { |
| 58 |
$custom_tracking .= "<script type=\"text/javascript\"> |
| 59 |
var clicky_custom = clicky_custom || {}; |
| 60 |
clicky_custom.html_media_track = 1; |
| 61 |
</script>\n"; |
| 62 |
} |
| 63 |
if ( $this->cawp->config->options['track_outbound'] ) { |
| 64 |
$ca_olp = explode( ',', $this->cawp->config->options['track_outbound'] ); |
| 65 |
$ca_olp_string = ""; |
| 66 |
foreach ( $ca_olp as $key => $pattern ) { |
| 67 |
$ca_olp_string .= "'" . esc_js($pattern) . "'" . ","; |
| 68 |
} |
| 69 |
$ca_olp_string = '[' . rtrim( $ca_olp_string, ',' ) . ']'; |
| 70 |
$custom_tracking .= "<script type=\"text/javascript\"> |
| 71 |
var clicky_custom = clicky_custom || {}; |
| 72 |
clicky_custom.outbound_pattern = $ca_olp_string; |
| 73 |
</script>\n"; |
| 74 |
} |
| 75 |
$main_tracking = '<script async src="//static.getclicky.com/' . esc_js($this->cawp->config->options['siteid']) . '.js"></script>'; |
| 76 |
$tracking = "\n<!-- BEGIN Clicky Analytics v" . CAWP_CURRENT_VERSION . " Tracking - https://wordpress.org/plugins/clicky-analytics/ -->\n"; |
| 77 |
$tracking .= $custom_tracking . "\n" . $main_tracking . "\n" . $video_tracking; |
| 78 |
$tracking .= "\n<!-- END Clicky Analytics v" . CAWP_CURRENT_VERSION . " Tracking -->\n\n"; |
| 79 |
echo $tracking; |
| 80 |
} |
| 81 |
} |
| 82 |
} |