Changeset 1016725
- Timestamp:
- 10/30/2014 02:48:25 PM (11 years ago)
- Location:
- google-analytics-site-wide/trunk
- Files:
-
- 1 deleted
- 4 edited
-
assets (deleted)
-
dc-google-analytics.php (modified) (6 diffs)
-
languages/dc_gasw_textdomain-sv_SE.mo (modified) (previous)
-
languages/dc_gasw_textdomain-sv_SE.po (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
google-analytics-site-wide/trunk/dc-google-analytics.php
r1016487 r1016725 1 1 <?php 2 2 /* 3 Plugin Name: Google Analytics Site Wide4 Plugin URI: http://dcweb.nu5 Description: A simple plugin for adding Google Analytics tracking code site wide for wp network6 Version: 1.07 Author: Daniel Söderström8 Author URI: http://dcweb.nu/9 License: GPL3 Plugin Name: Google Analytics Site Wide 4 Plugin URI: http://dcweb.nu 5 Description: A simple plugin for adding Google Analytics tracking code site wide for wp network 6 Version: 1.0 7 Author: Daniel Söderström 8 Author URI: http://dcweb.nu/ 9 License: GPL 10 10 */ 11 11 … … 17 17 18 18 private static $instance; 19 private $excluded_sites = array(); 19 20 20 21 /** … … 48 49 add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) ); 49 50 50 51 if( get_site_option( 'dc-ga-location') == 'dc-ga-location-header') 52 add_action( 'wp_head', array( $this, 'render_ga_code' ) ); 53 else 54 add_action( 'wp_footer', array( $this, 'render_ga_code' ) ); 55 51 if(! is_admin() ){ 52 $this->excluded_sites = $this->set_excluded_sites(); 53 $this->add_tracking_code(); 54 } 55 } 56 57 /** 58 * Store excluded sites if there is 59 */ 60 private function set_excluded_sites(){ 61 62 // get ids from site option, remove whitespaces. 63 $sites = str_replace(' ', ',', get_site_option( 'dc-ga-exclude-sites' ) ); 64 $sites = explode( ',', $sites ); 65 66 $excluded = array(); 67 foreach( $sites as $site ){ 68 69 // only save digits 70 if( is_numeric( $site ) ){ 71 $excluded[] = '_' . $site . '_'; // add som separators so we can use in_array 72 } 73 74 } 75 76 if( !empty( $excluded ) ) 77 return $excluded; 78 79 return false; 80 81 } 82 83 /** 84 * Adding google code to header or footer if site is not excluded 85 */ 86 public function add_tracking_code(){ 87 88 // create a search needle for current site id 89 $search = '_' . get_current_blog_id() . '_'; 90 91 // check if current site is excluded 92 if( !in_array( $search, $this->excluded_sites )){ 93 94 // where to put google code 95 if( get_site_option( 'dc-ga-location') == 'dc-ga-location-header') 96 add_action( 'wp_head', array( $this, 'render_ga_code' ) ); 97 else 98 add_action( 'wp_footer', array( $this, 'render_ga_code' ) ); 99 100 } 101 56 102 } 57 103 … … 68 114 public function render_ga_code() { 69 115 $tracking_code = get_site_option( 'dc-ga-code'); 116 70 117 $tracking_domain = get_site_option( 'dc-ga-domain'); 71 118 if(empty ($tracking_domain )) 119 $tracking_domain = 'auto'; 120 121 $disable_universal = get_site_option( 'dc-ga-universal' ); 122 72 123 // bail if empty 73 124 if(empty( $tracking_code )) 74 125 return false; 126 127 // print old analytics script if universal disabled 128 if( $disable_universal == 1 ) : 75 129 ?> 76 <script> 77 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 78 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 79 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 80 })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 81 82 ga('create', '<?php echo $tracking_code ?>', '<?php echo $tracking_domain ?>'); 83 ga('send', 'pageview'); 84 </script> 130 <script> 131 var _gaq = _gaq || []; 132 _gaq.push(['_setAccount', '<?php echo $tracking_code ?>']); 133 _gaq.push(['_trackPageview']); 134 135 (function() { 136 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 137 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 138 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 139 })(); 140 141 </script> 142 143 <?php else: ?> 144 145 <script> 146 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 147 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 148 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 149 })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 150 151 ga('create', '<?php echo $tracking_code ?>', '<?php echo $tracking_domain ?>'); 152 ga('send', 'pageview'); 153 </script> 154 155 <?php endif; ?> 156 85 157 <?php 86 158 } 87 159 160 88 161 /** 89 162 * Save network settings 90 163 */ 91 164 public static function save_network_settings() { 92 $posted_settings = array_map( 'sanitize_text_field', $_POST['ccga'] ); 93 94 foreach ( $posted_settings as $name => $value ) { 165 166 $post_options = array_map( 'sanitize_text_field', $_POST['ccga'] ); 167 168 // delete checkbox value for disable universal 169 delete_site_option( 'dc-ga-universal' ); 170 171 foreach ( $post_options as $name => $value ) { 95 172 update_site_option( $name, $value ); 96 173 } 174 97 175 } 98 176 … … 116 194 <label><input type="radio" name="ccga[<?php echo $setting['name']; ?>]" id="<?php echo $s['id'] ?>" value="<?php echo $s['id']; ?>" <?php echo checked( $s['id'], get_site_option( $setting['name'] ) ); ?>/><?php echo $s['desc'] ?></label><br /> 117 195 <?php endforeach; ?> 196 197 <?php elseif ($setting['type'] == 'checkbox'): ?> 198 <label><input type="<?php echo $setting['type'];?>" name="ccga[<?php echo $setting['name']; ?>]" value="1" <?php echo checked( '1', get_site_option( $setting['name'] ) ); ?> /><?php _e('Disable Universal Analytics', DC_TEXTDOMAIN ) ?></label> 199 <p class="description"><?php echo $setting['desc']; ?></p> 118 200 119 201 <?php else: ?> … … 151 233 'size' => '40' 152 234 ); 235 236 $settings[] = array( 237 'id' => 'dc-ga-universal', 238 'name' => 'dc-ga-universal', 239 'title' => __( 'Disable Universal Analytics', DC_TEXTDOMAIN ), 240 'desc' => __('Default setting is for Universal Analytics, check this option if you need to use ga.js', DC_TEXTDOMAIN ), 241 'type' => 'checkbox' 242 ); 243 244 245 $settings[] = array( 246 'id' => 'dc-ga-exclude-sites', 247 'name' => 'dc-ga-exclude-sites', 248 'title' => __( 'Excluded sites', DC_TEXTDOMAIN ), 249 'desc' => __('Enter the id for the site you wish to exclude (use a comma separated list for multiple sites).', DC_TEXTDOMAIN ), 250 'type' => 'text', 251 'size' => '40' 252 ); 153 253 154 254 $settings[] = array( -
google-analytics-site-wide/trunk/languages/dc_gasw_textdomain-sv_SE.po
r1016487 r1016725 4 4 "Report-Msgid-Bugs-To: \n" 5 5 "POT-Creation-Date: \n" 6 "PO-Revision-Date: 2014-10-29 09:32:07+0000\n"6 "PO-Revision-Date: 2014-10-29 20:27:01+0000\n" 7 7 "Last-Translator: admin <[email protected]>\n" 8 8 "Language-Team: \n" … … 21 21 "X-Textdomain-Support: yes" 22 22 23 #: dc-google-analytics.php: 12323 #: dc-google-analytics.php:221 24 24 #@ dc_gasw_textdomain 25 25 msgid "Google Analytics Tracking Code" 26 26 msgstr "Spårningskod" 27 27 28 #: dc-google-analytics.php: 13228 #: dc-google-analytics.php:230 29 29 #@ dc_gasw_textdomain 30 30 msgid "Domain" 31 31 msgstr "Domän" 32 32 33 #: dc-google-analytics.php: 14033 #: dc-google-analytics.php:256 34 34 #@ dc_gasw_textdomain 35 35 msgid "Location" 36 36 msgstr "Placering" 37 37 38 #: dc-google-analytics.php: 9238 #: dc-google-analytics.php:183 39 39 #@ dc_gasw_textdomain 40 40 msgid "Google Analytics - Site Wide" 41 41 msgstr "" 42 42 43 #: dc-google-analytics.php: 13343 #: dc-google-analytics.php:231 44 44 #@ dc_gasw_textdomain 45 45 msgid " Enter the domain (domainname.se, exclude http:// and www) that is registred for your tracking code." 46 46 msgstr "Ange toppdomän utan http:// eller www (domannamn.se) som är registrerad för spårningskoden." 47 47 48 #: dc-google-analytics.php: 14648 #: dc-google-analytics.php:262 49 49 #@ dc_gasw_textdomain 50 50 msgid "Add to page header" 51 51 msgstr "Lägg till i sidhuvud" 52 52 53 #: dc-google-analytics.php: 15053 #: dc-google-analytics.php:266 54 54 #@ dc_gasw_textdomain 55 55 msgid "Add to page footer" 56 56 msgstr "Lägg till i sidfot" 57 57 58 #: dc-google-analytics.php:198 59 #: dc-google-analytics.php:239 60 #@ dc_gasw_textdomain 61 msgid "Disable Universal Analytics" 62 msgstr "Inaktivera Universal Analytics" 63 64 #: dc-google-analytics.php:240 65 #@ dc_gasw_textdomain 66 msgid "Default setting is for Universal Analytics, check this option if you need to use ga.js" 67 msgstr "Som standard användas Universal Analytics vilket använder de senaste funktionerna för Google Analytics. Markera denna kryssruta om du önskar använda det äldre biblioteket ga.js." 68 69 #: dc-google-analytics.php:248 70 #@ dc_gasw_textdomain 71 msgid "Excluded sites" 72 msgstr "Exkludera webbplatser" 73 74 #: dc-google-analytics.php:249 75 #@ dc_gasw_textdomain 76 msgid "Enter the id for the site you wish to exclude (use a comma separated list for multiple sites)." 77 msgstr "Ange id för den webbplats du önskar exkludera från Analytics (använd kommaseparerad lista om det gäller fler än en webbplats)." 78 -
google-analytics-site-wide/trunk/readme.txt
r1016487 r1016725 1 1 === Google Analytics Site Wide === 2 2 Contributors: dansod 3 Tags: analytics, google analytics, tracking code, site wide, google analytics site wide , universal analytics3 Tags: analytics, google analytics, tracking code, site wide, google analytics site wide 4 4 Requires at least: 3.9 5 5 Tested up to: 4.0 … … 33 33 == Changelog == 34 34 35 = 1.0.1 = 36 * Added option to exclude tracking for one or several sites in the network 37 * Added a possibility to use old ga.js library instead of Universal Analytics 38 35 39 = 1.0 = 36 40 * First release
Note: See TracChangeset
for help on using the changeset viewer.