Plugin Directory

Changeset 1517588


Ignore:
Timestamp:
10/18/2016 10:36:02 PM (9 years ago)
Author:
lewisself
Message:

Added Google Site Verification and option of google analytics javascript placement.

Location:
easy-google-analytics-tracking/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • easy-google-analytics-tracking/trunk/css/admin.css

    r1438050 r1517588  
    11#main-content
    22{
    3   max-width:600px;
     3  max-width:400px;
    44}
    55
    6 .tracking-id
     6.google-ids
    77{
    88  display:block;
     
    1010}
    1111
    12 .tracking-id > span,
    13 .site-verfication > span
     12.title
    1413{
    1514  font-weight:bold;
    1615  font-size:14px;
    17   display:block;
    18   margin:1em 0;
     16  margin:1em 0 1em 0;
    1917}
    2018
    21 .tracking-id > input,
    22 .site-verfication > input
     19.text-field-titles
    2320{
    24   width:300px;
     21  display:block;
    2522}
    2623
    27 .enable-tracking-id
     24.google-ids > input
     25{
     26  width:100%;
     27}
     28
     29.checkbox-options
    2830{
    2931  display:block;
     
    3133}
    3234
    33 .enable-tracking-id > span
     35.checkbox-options > input[type=checkbox]
     36{
     37  float:right;
     38}
     39
     40.checkbox-options > span
    3441{
    3542  margin:1em 5px 1em 0;
     
    3744}
    3845
     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
    3957p.submit
    4058{
    41   margin:10px 0;
    42   padding-top:0;
     59  margin:20px 0;
     60  padding:0;
    4361}
     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  
    33  /*
    44    Plugin Name: Easy Google Analytics Tracking
    5     Plugin URI:  http://selfdesigns.co.uk
     5    Plugin URI:  http://www.selfdesigns.co.uk
    66    Description: Add google analytics script without theme modification
    77    License:     GPL
    8     Version:     1.1.0
     8    Version:     1.2.0
    99    Author:      Lewis Self
    10     Author URI:  http://selfdesigns.co.uk
     10    Author URI:  http://www.selfdesigns.co.uk
    1111  */
    1212
     
    1616  }
    1717
    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)
    1925  {
     26    if($google_analytics_tracking_id)
     27    {
     28      function egat_add_google_analytics_script() // Add Google Analytics code to theme file
     29      {
     30        ?>
    2031
    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)
    2260    {
     61      if($google_site_verification_id)
     62      {
     63        ?>
    2364
    24       ?>
     65          <meta name="google-site-verification" content="<?php echo esc_attr($google_site_verification_id); ?>" />
    2566
    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');
    3172
    32         ga('create', '<?php echo esc_attr(get_option('google_analytics_tracking_id')) ?>', 'auto');
    33         ga('send', 'pageview');
    34       </script>
    35 
    36     <?php
    37 
    38     }
    39     add_action('wp_footer', 'egat_add_google_analytics_script');
    40    
    41   }
    42    
    4373  if(is_admin())
    4474  {
    45    
    4675    function egat_add_setting_link($links) // Creates settings link for plugin page
    4776    {
     
    5180    add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'egat_add_setting_link');
    5281   
    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
    5499    {
    55100      if($_GET['page'] == 'easy-google-analytics-tracking')
     
    59104    }
    60105    add_action('admin_print_styles', 'egat_enqueue_css');
    61        
    62     function egat_google_analytics_script_menu() // Creates settings page
    63     {
    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');
    67106
    68     function egat_register_my_cool_plugin_settings() // Register plugin settings
    69     {
    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            
    75107    function egat_settings_page() // Output Settings page
    76108    {
     
    83115          <?php do_settings_sections('google-analytics-script-settings'); ?>
    84116          <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>
    87118          </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); ?>" />
    91122          </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); ?>" />
    95126          </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>
    96148          <?php submit_button(); ?>
    97149        </form>
     
    101153    }
    102154   
    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');
    109164  }
    110165
  • easy-google-analytics-tracking/trunk/readme.txt

    r1438055 r1517588  
    22
    33Contributors: Lewis Self
    4 Donate Link: http://selfdesigns.co.uk
     4Donate Link: http://www.selfdesigns.co.uk
    55Tags: Google, Analytics, website data, tracking, simple
    66Requires at least: 4.0
     
    88Stable tag: Trunk
    99License: GPLv2
    10 Version: 1.1.0
     10Version: 1.2.0
    1111
    1212== Description ==
     
    4545* Changed admin settings from inline style to external Style Sheet: 16/06/2016
    4646* 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.