Changeset 1517588
- Timestamp:
- 10/18/2016 10:36:02 PM (9 years ago)
- Location:
- easy-google-analytics-tracking/trunk
- Files:
-
- 3 edited
-
css/admin.css (modified) (4 diffs)
-
easy-google-analytics-tracking.php (modified) (6 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easy-google-analytics-tracking/trunk/css/admin.css
r1438050 r1517588 1 1 #main-content 2 2 { 3 max-width: 600px;3 max-width:400px; 4 4 } 5 5 6 . tracking-id6 .google-ids 7 7 { 8 8 display:block; … … 10 10 } 11 11 12 .tracking-id > span, 13 .site-verfication > span 12 .title 14 13 { 15 14 font-weight:bold; 16 15 font-size:14px; 17 display:block; 18 margin:1em 0; 16 margin:1em 0 1em 0; 19 17 } 20 18 21 .tracking-id > input, 22 .site-verfication > input 19 .text-field-titles 23 20 { 24 width:300px;21 display:block; 25 22 } 26 23 27 .enable-tracking-id 24 .google-ids > input 25 { 26 width:100%; 27 } 28 29 .checkbox-options 28 30 { 29 31 display:block; … … 31 33 } 32 34 33 .enable-tracking-id > span 35 .checkbox-options > input[type=checkbox] 36 { 37 float:right; 38 } 39 40 .checkbox-options > span 34 41 { 35 42 margin:1em 5px 1em 0; … … 37 44 } 38 45 46 .radio-button-options 47 { 48 margin:1em 0; 49 } 50 51 .script-placement-foot, 52 .script-placement-head 53 { 54 margin:0 5px 0 0; 55 } 56 39 57 p.submit 40 58 { 41 margin: 10px 0;42 padding -top:0;59 margin:20px 0; 60 padding:0; 43 61 } 62 63 @media(min-width:400px) 64 { 65 .checkbox-options > input[type=checkbox] 66 { 67 float:none; 68 } 69 70 .radio-button-options 71 { 72 float:none; 73 } 74 } -
easy-google-analytics-tracking/trunk/easy-google-analytics-tracking.php
r1438055 r1517588 3 3 /* 4 4 Plugin Name: Easy Google Analytics Tracking 5 Plugin URI: http:// selfdesigns.co.uk5 Plugin URI: http://www.selfdesigns.co.uk 6 6 Description: Add google analytics script without theme modification 7 7 License: GPL 8 Version: 1. 1.08 Version: 1.2.0 9 9 Author: Lewis Self 10 Author URI: http:// selfdesigns.co.uk10 Author URI: http://www.selfdesigns.co.uk 11 11 */ 12 12 … … 16 16 } 17 17 18 if((get_option('google_analytics_enabled')) && (get_option('google_analytics_tracking_id'))) 18 $google_analytics_enabled = get_option('google_analytics_enabled'); 19 $google_analytics_tracking_id = get_option('google_analytics_tracking_id'); 20 $google_analytics_placement = get_option('google_analytics_placement'); 21 $google_site_verification_enabled = get_option('google_site_verification_enabled'); 22 $google_site_verification_id = get_option('google_site_verification_id'); 23 24 if($google_analytics_enabled) 19 25 { 26 if($google_analytics_tracking_id) 27 { 28 function egat_add_google_analytics_script() // Add Google Analytics code to theme file 29 { 30 ?> 20 31 21 function egat_add_google_analytics_script() // Add Google Analytics code to theme file 32 <script> 33 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 34 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 35 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 36 })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 37 38 ga('create', '<?php echo esc_attr($google_analytics_tracking_id); ?>', 'auto'); 39 ga('send', 'pageview'); 40 </script> 41 42 <?php 43 } 44 45 if($google_analytics_placement == '2') 46 { 47 add_action('wp_footer', 'egat_add_google_analytics_script'); 48 } 49 50 if($google_analytics_placement == '1') 51 { 52 add_action('wp_head', 'egat_add_google_analytics_script'); 53 } 54 } 55 } 56 57 function egat_add_google_site_verification() 58 { 59 if($google_site_verification_enabled) 22 60 { 61 if($google_site_verification_id) 62 { 63 ?> 23 64 24 ?>65 <meta name="google-site-verification" content="<?php echo esc_attr($google_site_verification_id); ?>" /> 25 66 26 <script>27 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){28 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),29 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)30 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');67 <?php 68 } 69 } 70 } 71 add_action('wp_head', 'egat_add_google_site_verification'); 31 72 32 ga('create', '<?php echo esc_attr(get_option('google_analytics_tracking_id')) ?>', 'auto');33 ga('send', 'pageview');34 </script>35 36 <?php37 38 }39 add_action('wp_footer', 'egat_add_google_analytics_script');40 41 }42 43 73 if(is_admin()) 44 74 { 45 46 75 function egat_add_setting_link($links) // Creates settings link for plugin page 47 76 { … … 51 80 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'egat_add_setting_link'); 52 81 53 function egat_enqueue_css() 82 function egat_register_my_cool_plugin_settings() // Register plugin settings 83 { 84 register_setting('google-analytics-script-settings', 'google_analytics_tracking_id'); 85 register_setting('google-analytics-script-settings', 'google_analytics_enabled'); 86 register_setting('google-analytics-script-settings', 'google_analytics_placement'); 87 register_setting('google-analytics-script-settings', 'google_site_verification_enabled'); 88 register_setting('google-analytics-script-settings', 'google_site_verification_id'); 89 } 90 add_action('admin_init', 'egat_register_my_cool_plugin_settings'); 91 92 function egat_google_analytics_script_menu() // Creates settings page 93 { 94 add_options_page('Google Analytics', 'Google Analytics', 'administrator', 'easy-google-analytics-tracking', 'egat_settings_page'); 95 } 96 add_action('admin_menu', 'egat_google_analytics_script_menu'); 97 98 function egat_enqueue_css() // Pulls in admin CSS if on settings page 54 99 { 55 100 if($_GET['page'] == 'easy-google-analytics-tracking') … … 59 104 } 60 105 add_action('admin_print_styles', 'egat_enqueue_css'); 61 62 function egat_google_analytics_script_menu() // Creates settings page63 {64 add_options_page('Google Analytics', 'Google Analytics ID', 'administrator', 'easy-google-analytics-tracking', 'egat_settings_page');65 }66 add_action('admin_menu', 'egat_google_analytics_script_menu');67 106 68 function egat_register_my_cool_plugin_settings() // Register plugin settings69 {70 register_setting('google-analytics-script-settings', 'google_analytics_tracking_id');71 register_setting('google-analytics-script-settings', 'google_analytics_enabled');72 }73 add_action('admin_init', 'egat_register_my_cool_plugin_settings');74 75 107 function egat_settings_page() // Output Settings page 76 108 { … … 83 115 <?php do_settings_sections('google-analytics-script-settings'); ?> 84 116 <div> 85 <p>You can find the google tracking Id in your google analytics admin. Property > Tracking Info > Tracking Code.</p> 86 <p>Once you generate the Google Analytics Code, you can find the Google Tracking Id under the ga function with the first paramiter as "create" For example, ga('create', <b>'YOUR TRACKING CODE'</b>, 'auto').</p> 117 <p>Use your tracking Id and site verification code to enable google analytics to track traffic on your site.</p> 87 118 </div> 88 <label class=" tracking-id">89 <span >Google Analytics Tracking ID:</span>90 <input name="google_analytics_tracking_id" value="<?php echo esc_attr( get_option('google_analytics_tracking_id')); ?>" />119 <label class="google-ids"> 120 <span class="title text-field-titles">Google Analytics Tracking ID:</span> 121 <input name="google_analytics_tracking_id" value="<?php echo esc_attr($google_analytics_tracking_id); ?>" /> 91 122 </label> 92 <label class=" enable-tracking-id">93 <span >Enable Google Analytics:</span>94 <input type="checkbox" name="google_analytics_enabled" value="1" <?php checked(1, get_option('google_analytics_enabled'), true); ?>/>123 <label class="google-ids"> 124 <span class="title text-field-titles">Google Site Verification Code:</span> 125 <input name="google_site_verification_id" value="<?php echo esc_attr($google_site_verification_id); ?>" /> 95 126 </label> 127 <label class="checkbox-options"> 128 <span class="title">Enable Google Analytics:</span> 129 <input type="checkbox" name="google_analytics_enabled" value="1" <?php checked(1, $google_analytics_enabled, true); ?> /> 130 </label> 131 <label class="checkbox-options"> 132 <span class="title">Enable Google Site Verification:</span> 133 <input type="checkbox" name="google_site_verification_enabled" value="1" <?php checked(1, $google_analytics_enabled, true); ?> /> 134 </label> 135 <div class="script-placement"> 136 <span class="title">JavaScript placement:</span> 137 <div class="radio-button-options"> 138 <label class="script-placement-head"> 139 <input type="radio" name="google_analytics_placement" value="1" <?php checked(1, get_option('google_analytics_placement'), true); ?> /> 140 <b>Header</b> 141 </label> 142 <label class="script-placement-foot"> 143 <input type="radio" name="google_analytics_placement" value="2" <?php checked(2, get_option('google_analytics_placement'), true); ?> /> 144 <b>Footer</b> 145 </label> 146 </div> 147 </div> 96 148 <?php submit_button(); ?> 97 149 </form> … … 101 153 } 102 154 103 function egat_uninstall() // Cleans up database and WordPress files on uninstall 104 { 105 delete_option('google_analytics_tracking_id'); 106 delete_option('google_analytics_enabled'); 107 } 108 register_uninstall_hook(__FILE__, 'egat_uninstall'); 155 function egat_uninstall() // Cleans up database and WordPress files on uninstall 156 { 157 delete_option('google_analytics_tracking_id'); 158 delete_option('google_analytics_enabled'); 159 delete_option('google_analytics_placement'); 160 delete_option('google_site_verification_enabled'); 161 delete_option('google_site_verification_id'); 162 } 163 register_uninstall_hook(__FILE__, 'egat_uninstall'); 109 164 } 110 165 -
easy-google-analytics-tracking/trunk/readme.txt
r1438055 r1517588 2 2 3 3 Contributors: Lewis Self 4 Donate Link: http:// selfdesigns.co.uk4 Donate Link: http://www.selfdesigns.co.uk 5 5 Tags: Google, Analytics, website data, tracking, simple 6 6 Requires at least: 4.0 … … 8 8 Stable tag: Trunk 9 9 License: GPLv2 10 Version: 1. 1.010 Version: 1.2.0 11 11 12 12 == Description == … … 45 45 * Changed admin settings from inline style to external Style Sheet: 16/06/2016 46 46 * Responsive admin settings: 16/06/2016 47 48 = 1.2.0 49 * Functionality to add tracking code to top or bottom of website source code: 18/10/2016 50 * Google site verification added: 18/10/2016 51 * Option to choose where google analytics code is outputted on website
Note: See TracChangeset
for help on using the changeset viewer.