Changeset 1933857
- Timestamp:
- 08/31/2018 01:31:25 PM (8 years ago)
- Location:
- matomo-tracker
- Files:
-
- 3 added
- 7 edited
-
assets/screenshot-1.png (modified) (previous)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/inc/admin/class-admin.php (modified) (7 diffs)
-
trunk/inc/admin/js (added)
-
trunk/inc/admin/js/matomo-tracker-admin.js (added)
-
trunk/inc/admin/views/html-matomo-tracker-admin-display.php (modified) (1 diff)
-
trunk/inc/core/class-init.php (modified) (6 diffs)
-
trunk/inc/frontend/class-frontend.php (modified) (1 diff)
-
trunk/inc/frontend/track.js (added)
-
trunk/matomo-tracker.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
matomo-tracker/trunk/README.txt
r1894061 r1933857 4 4 Tags: matomo, piwik, analytics, tracking code 5 5 Requires at least: 3.0.1 6 Tested up to: 4.9. 66 Tested up to: 4.9.8 7 7 Requires PHP: 5.6.0 8 Stable tag: 1. 1.08 Stable tag: 1.2.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 56 56 = 1.1.0 = 57 57 * Tracking Mode selection added : You can now choose between Javscript or Php tracking Mode 58 59 = 1.2.0 = 60 * JS Tracking Mode is no more including inline javascript and now calls a JS File 61 * JS Tracking file loading mode is now customizable (defer, async or nothing) 62 * JS Tracking file can be disallowed in robots.txt -
matomo-tracker/trunk/inc/admin/class-admin.php
r1885339 r1933857 42 42 */ 43 43 private $plugin_text_domain; 44 45 private $plugin_name_dir; 46 private $plugin_name_url; 44 47 45 48 /** … … 51 54 * @param string $plugin_text_domain The text domain of this plugin. 52 55 */ 53 public function __construct( $plugin_name, $version, $plugin_text_domain ) {56 public function __construct( $plugin_name, $version, $plugin_text_domain, $plugin_name_dir, $plugin_name_url ) { 54 57 55 58 $this->plugin_name = $plugin_name; 56 59 $this->version = $version; 57 60 $this->plugin_text_domain = $plugin_text_domain; 61 62 $this->plugin_name_dir = $plugin_name_dir; 63 $this->plugin_name_url = $plugin_name_url; 58 64 59 65 } … … 87 93 * @since 1.0.0 88 94 */ 89 /*public function enqueue_scripts() {95 public function enqueue_scripts() { 90 96 /* 91 97 * This function is provided for demonstration purposes only. … … 99 105 * class. 100 106 */ 101 /* 107 102 108 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/matomo-tracker-admin.js', array( 'jquery' ), $this->version, false ); 103 109 104 110 } 105 */ 111 106 112 public function display_plugin_setup_page() { 107 113 include_once( 'views/html-matomo-tracker-admin-display.php' ); … … 130 136 $matomoId = $_POST[$this->plugin_name.'-tracking-id'] ? (int) $_POST[$this->plugin_name.'-tracking-id'] : ''; 131 137 $matomoMode = $_POST[$this->plugin_name.'-tracking-mode'] ? $_POST[$this->plugin_name.'-tracking-mode'] : ''; 138 $matomoJsMode = $_POST[$this->plugin_name.'-javascript-mode'] ? $_POST[$this->plugin_name.'-javascript-mode'] : 'defer'; 139 $matomoDisallowRobot = $_POST[$this->plugin_name.'-javascript-disallow-robot'] ? $_POST[$this->plugin_name.'-javascript-disallow-robot'] : 'y'; 132 140 133 141 if (empty($matomoUrl)) { … … 169 177 } else { 170 178 add_option( $this->plugin_name.'-tracking-mode', $matomoMode); 171 } 179 } 180 if ( get_option( $this->plugin_name.'-javascript-mode' ) !== false ) { 181 update_option( $this->plugin_name.'-javascript-mode', $matomoJsMode ); 182 } else { 183 add_option( $this->plugin_name.'-javascript-mode', $matomoJsMode); 184 } 185 if ( get_option( $this->plugin_name.'-javascript-disallow-robot' ) !== false ) { 186 update_option( $this->plugin_name.'-javascript-disallow-robot', $matomoDisallowRobot ); 187 } else { 188 add_option( $this->plugin_name.'-javascript-disallow-robot', $matomoDisallowRobot); 189 } 172 190 $admin_notice = "success"; 173 191 $messageLog .= 'Settings saved'; 174 192 } 175 176 193 if ( $matomoMode == 'js' ) $this->update_tracker_settings(); 177 194 $this->custom_redirect( $admin_notice, $messageLog); 178 195 die(); … … 183 200 ) ); 184 201 } 202 } 203 204 private function update_tracker_settings() { 205 if ( get_option( $this->plugin_name.'-tracking-mode' ) == 'js' &&!empty(get_option( $this->plugin_name.'-url' )) && !empty(get_option( $this->plugin_name.'-tracking-id' )) && !empty(get_option( $this->plugin_name.'-token' )) ) { 206 $piwikId = get_option( $this->plugin_name.'-tracking-id' ); 207 208 $piwikFileDir = $this->plugin_name_url . 'inc/frontend/'; 209 $piwikJsFile = $this->plugin_name_dir . 'inc/frontend/track.js'; 210 $js = 'var _paq = _paq || []; _paq.push(["trackPageView"]); _paq.push(["enableLinkTracking"]); (function() { var u="'. $piwikFileDir .'piwik.php"; _paq.push(["setTrackerUrl", u]); _paq.push(["setSiteId", "'. $piwikId .'"]); var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript"; g.async=true; g.defer=true; g.src=u; s.parentNode.insertBefore(g,s); })();'; 211 file_put_contents($piwikJsFile, $js); 212 } 213 185 214 } 186 215 -
matomo-tracker/trunk/inc/admin/views/html-matomo-tracker-admin-display.php
r1885339 r1933857 69 69 </td> 70 70 </tr> 71 <tr id="matomoJsMode" valign="top"> 72 <th scope="row"> 73 <label for="<?php echo $this->plugin_name; ?>-javascript-mode"> 74 <span><?php esc_attr_e('Javascript Loading Mode', $this->plugin_text_domain); ?></span> 75 </label> 76 </th> 77 <td> 78 <select id="<?php echo $this->plugin_name; ?>-javascript-mode" name="<?php echo $this->plugin_name; ?>-javascript-mode"> 79 <option value="defer"<?php if (( get_option( $this->plugin_name.'-javascript-mode' ) == 'defer') || empty(get_option( $this->plugin_name.'-javascript-mode' )) ) echo ' selected'; ?>>defer</option> 80 <option value="async"<?php if ( get_option( $this->plugin_name.'-javascript-mode' ) == 'async') echo ' selected'; ?>>async</option> 81 <option value="none"<?php if ( get_option( $this->plugin_name.'-javascript-mode' ) == 'none') echo ' selected'; ?>>none</option> 82 </select> 83 </td> 84 </tr> 85 <tr id="matomoJsDisallowRobot" valign="top"> 86 <th scope="row"> 87 <label for="<?php echo $this->plugin_name; ?>-javascript-disallow-robot"> 88 <span><?php esc_attr_e('Disallow JS File in robot.txt', $this->plugin_text_domain); ?></span> 89 </label> 90 </th> 91 <td> 92 <select id="<?php echo $this->plugin_name; ?>-javascript-disallow-robot" name="<?php echo $this->plugin_name; ?>-javascript-disallow-robot"> 93 <option value="y"<?php if (( get_option( $this->plugin_name.'-javascript-disallow-robot' ) == 'y') || empty(get_option( $this->plugin_name.'-javascript-disallow-robot' )) ) echo ' selected'; ?>>Yes</option> 94 <option value="n"<?php if ( get_option( $this->plugin_name.'-javascript-disallow-robot' ) == 'n') echo ' selected'; ?>>No</option> 95 </select> 96 <p id="<?php echo $this->plugin_name; ?>-javascript-disallow-robot-description" class="description"> 97 <?php esc_attr_e('If activated this option will disallow js file in robot.txt', $this->plugin_text_domain); ?> 98 </p> 99 </td> 100 </tr> 71 101 <tr valign="top"> 72 102 <th scope="row"> -
matomo-tracker/trunk/inc/core/class-init.php
r1885339 r1933857 51 51 */ 52 52 protected $plugin_text_domain; 53 54 protected $plugin_name_dir; 55 protected $plugin_name_url; 53 56 54 57 /** … … 59 62 $this->plugin_name = NS\PLUGIN_NAME; 60 63 $this->version = NS\PLUGIN_VERSION; 61 $this->plugin_basename = NS\PLUGIN_BASENAME; 62 $this->plugin_text_domain = NS\PLUGIN_TEXT_DOMAIN; 64 $this->plugin_basename = NS\PLUGIN_BASENAME; 65 $this->plugin_text_domain = NS\PLUGIN_TEXT_DOMAIN; 66 67 $this->plugin_name_dir = NS\PLUGIN_NAME_DIR; 68 $this->plugin_name_url = NS\PLUGIN_NAME_URL; 63 69 64 70 $this->load_dependencies(); … … 107 113 private function define_admin_hooks() { 108 114 109 $plugin_admin = new Admin\Admin( $this->get_plugin_name(), $this->get_version(), $this->get_plugin_text_domain() );115 $plugin_admin = new Admin\Admin( $this->get_plugin_name(), $this->get_version(), $this->get_plugin_text_domain(), $this->get_plugin_name_dir(), $this->get_plugin_name_url() ); 110 116 111 117 //$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); 112 //$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );118 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); 113 119 114 120 /* … … 127 133 $this->loader->add_action( 'admin_post_matomo_tracker_form_response', $plugin_admin, 'check_for_event_submissions'); 128 134 $this->loader->add_action( 'admin_notices', $plugin_admin, 'print_plugin_admin_notices'); 135 $this->loader->add_action( 'upgrader_process_complete', $plugin_admin, 'update_tracker_settings'); 136 129 137 } 130 138 … … 145 153 } else { 146 154 $this->loader->add_action( 'wp_footer', $plugin_public, 'add_tracking_code_footer' ); 155 if ( empty(get_option( $this->plugin_name.'-javascript-disallow-robot' )) || get_option( $this->plugin_name.'-javascript-disallow-robot') == 'y' ) { 156 $this->loader->add_filter( 'robots_txt', $plugin_public, 'disallow_javascript_tracking', 10, 2 ); 157 } 147 158 } 148 159 … … 192 203 return $this->plugin_text_domain; 193 204 } 205 206 public function get_plugin_name_dir() { 207 return $this->plugin_name_dir; 208 } 209 210 public function get_plugin_name_url() { 211 return $this->plugin_name_url; 212 } 213 194 214 195 215 } -
matomo-tracker/trunk/inc/frontend/class-frontend.php
r1885339 r1933857 108 108 public function add_tracking_code_footer() { 109 109 if ( !empty(get_option( $this->plugin_name.'-url' )) && !empty(get_option( $this->plugin_name.'-tracking-id' )) && !empty(get_option( $this->plugin_name.'-token' )) ) { 110 $piwikId = get_option( $this->plugin_name.'-tracking-id' );111 110 $piwikFileDir = plugin_dir_url( __FILE__ ); 112 echo '<script type="text/javascript">var _paq = _paq || []; _paq.push(["trackPageView"]); _paq.push(["enableLinkTracking"]); (function() { var u="'. $piwikFileDir .'piwik.php"; _paq.push(["setTrackerUrl", u]); _paq.push(["setSiteId", "'. $piwikId .'"]); var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript"; g.async=true; g.defer=true; g.src=u; s.parentNode.insertBefore(g,s); })();</script>'; 111 $matomoJsMode = get_option( $this->plugin_name.'-javascript-mode' ); 112 $matomoScript = "<script type='text/javascript'"; 113 if ($matomoJsMode == 'defer') $matomoScript .= " defer='defer'"; 114 if ($matomoJsMode == 'async') $matomoScript .= " async='async'"; 115 $matomoScript .= " src='".$piwikFileDir."track.js'></script>"; 116 echo $matomoScript; 113 117 } 118 } 119 120 public function disallow_javascript_tracking( $output, $public ) { 121 if ( '1' === $public ) { 122 $output .= "Disallow: /wp-content/plugins/matomo-tracker/inc/frontend/track.js\n"; 123 } 124 return $output; 114 125 } 115 126 -
matomo-tracker/trunk/matomo-tracker.php
r1885339 r1933857 16 16 * Plugin URI: https://wordpress.org/plugins/matomo-tracker/ 17 17 * Description: Matomo tracker adds matomo (formerly piwik) tracking code to your website while hiding your matomo installation url 18 * Version: 1. 1.018 * Version: 1.2.0 19 19 * Author: Niroma 20 20 * Author URI: https://www.niroma.net/ … … 40 40 define( NS . 'PLUGIN_NAME', 'matomo-tracker' ); 41 41 42 define( NS . 'PLUGIN_VERSION', '1. 1.0' );42 define( NS . 'PLUGIN_VERSION', '1.2.0' ); 43 43 44 44 define( NS . 'PLUGIN_NAME_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.