tracking.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Author: ExactMetrics team
  4. * Author URI: https://exactmetrics.com
  5. * Copyright 2018 ExactMetrics team
  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. if ( ! class_exists( 'GADWP_Tracking' ) ) {
  13. class GADWP_Tracking {
  14. private $gadwp;
  15. public $analytics;
  16. public $analytics_amp;
  17. public $tagmanager;
  18. public function __construct() {
  19. $this->gadwp = GADWP();
  20. $this->init();
  21. }
  22. public function tracking_code() { // Removed since 5.0
  23. GADWP_Tools::doing_it_wrong( __METHOD__, __( "This method is deprecated, read the documentation!", 'google-analytics-dashboard-for-wp' ), '5.0' );
  24. }
  25. public static function gadwp_user_optout( $atts, $content = "" ) {
  26. if ( ! isset( $atts['html_tag'] ) ) {
  27. $atts['html_tag'] = 'a';
  28. }
  29. if ( 'a' == $atts['html_tag'] ) {
  30. return '<a href="#" class="gadwp_useroptout" onclick="gaOptout()">' . esc_html( $content ) . '</a>';
  31. } else if ( 'button' == $atts['html_tag'] ) {
  32. return '<button class="gadwp_useroptout" onclick="gaOptout()">' . esc_html( $content ) . '</button>';
  33. }
  34. }
  35. public function init() {
  36. // excluded roles
  37. if ( GADWP_Tools::check_roles( $this->gadwp->config->options['track_exclude'], true ) || ( $this->gadwp->config->options['superadmin_tracking'] && current_user_can( 'manage_network' ) ) ) {
  38. return;
  39. }
  40. if ( 'universal' == $this->gadwp->config->options['tracking_type'] && $this->gadwp->config->options['tableid_jail'] ) {
  41. // Analytics
  42. require_once 'tracking-analytics.php';
  43. if ( 1 == $this->gadwp->config->options['ga_with_gtag'] ) {
  44. $this->analytics = new GADWP_Tracking_GlobalSiteTag();
  45. } else {
  46. $this->analytics = new GADWP_Tracking_Analytics();
  47. }
  48. if ( $this->gadwp->config->options['amp_tracking_analytics'] ) {
  49. $this->analytics_amp = new GADWP_Tracking_Analytics_AMP();
  50. }
  51. }
  52. if ( 'tagmanager' == $this->gadwp->config->options['tracking_type'] && $this->gadwp->config->options['web_containerid'] ) {
  53. // Tag Manager
  54. require_once 'tracking-tagmanager.php';
  55. $this->tagmanager = new GADWP_Tracking_TagManager();
  56. }
  57. add_shortcode( 'gadwp_useroptout', array( $this, 'gadwp_user_optout' ) );
  58. }
  59. }
  60. }