Plugin Directory

Changeset 1016725


Ignore:
Timestamp:
10/30/2014 02:48:25 PM (11 years ago)
Author:
dansod
Message:

Added screenshot and some extra options for setting page

Location:
google-analytics-site-wide/trunk
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • google-analytics-site-wide/trunk/dc-google-analytics.php

    r1016487 r1016725  
    11<?php
    22/*
    3 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
     3  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
    1010*/
    1111
     
    1717 
    1818    private static $instance;
     19    private $excluded_sites = array();
    1920
    2021    /**
     
    4849      add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) );
    4950
    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
    56102    }
    57103
     
    68114    public function render_ga_code() {
    69115        $tracking_code = get_site_option( 'dc-ga-code');
     116
    70117        $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     
    72123      // bail if empty
    73124        if(empty( $tracking_code ))
    74125            return false;
     126
     127      // print old analytics script if universal disabled
     128      if( $disable_universal == 1 ) :
    75129    ?>
    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
    85157        <?php
    86158        }   
    87  
     159
     160
    88161    /**
    89162     * Save network settings
    90163     */
    91164    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 ) {
    95172        update_site_option( $name, $value );
    96173      }
     174
    97175    }
    98176 
     
    116194                        <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 />
    117195                    <?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>
    118200
    119201                <?php else: ?> 
     
    151233            'size' => '40'
    152234        );
     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        );       
    153253
    154254        $settings[] = array(
  • google-analytics-site-wide/trunk/languages/dc_gasw_textdomain-sv_SE.po

    r1016487 r1016725  
    44"Report-Msgid-Bugs-To: \n"
    55"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"
    77"Last-Translator: admin <[email protected]>\n"
    88"Language-Team: \n"
     
    2121"X-Textdomain-Support: yes"
    2222
    23 #: dc-google-analytics.php:123
     23#: dc-google-analytics.php:221
    2424#@ dc_gasw_textdomain
    2525msgid "Google Analytics Tracking Code"
    2626msgstr "Spårningskod"
    2727
    28 #: dc-google-analytics.php:132
     28#: dc-google-analytics.php:230
    2929#@ dc_gasw_textdomain
    3030msgid "Domain"
    3131msgstr "Domän"
    3232
    33 #: dc-google-analytics.php:140
     33#: dc-google-analytics.php:256
    3434#@ dc_gasw_textdomain
    3535msgid "Location"
    3636msgstr "Placering"
    3737
    38 #: dc-google-analytics.php:92
     38#: dc-google-analytics.php:183
    3939#@ dc_gasw_textdomain
    4040msgid "Google Analytics - Site Wide"
    4141msgstr ""
    4242
    43 #: dc-google-analytics.php:133
     43#: dc-google-analytics.php:231
    4444#@ dc_gasw_textdomain
    4545msgid " Enter the domain (domainname.se, exclude http:// and www) that is registred for your tracking code."
    4646msgstr "Ange toppdomän utan http:// eller www  (domannamn.se) som är registrerad för spårningskoden."
    4747
    48 #: dc-google-analytics.php:146
     48#: dc-google-analytics.php:262
    4949#@ dc_gasw_textdomain
    5050msgid "Add to page header"
    5151msgstr "Lägg till i sidhuvud"
    5252
    53 #: dc-google-analytics.php:150
     53#: dc-google-analytics.php:266
    5454#@ dc_gasw_textdomain
    5555msgid "Add to page footer"
    5656msgstr "Lägg till i sidfot"
    5757
     58#: dc-google-analytics.php:198
     59#: dc-google-analytics.php:239
     60#@ dc_gasw_textdomain
     61msgid "Disable Universal Analytics"
     62msgstr "Inaktivera Universal Analytics"
     63
     64#: dc-google-analytics.php:240
     65#@ dc_gasw_textdomain
     66msgid "Default setting is for Universal Analytics, check this option if you need to use ga.js"
     67msgstr "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
     71msgid "Excluded sites"
     72msgstr "Exkludera webbplatser"
     73
     74#: dc-google-analytics.php:249
     75#@ dc_gasw_textdomain
     76msgid "Enter the id for the site you wish to exclude (use a comma separated list for multiple sites)."
     77msgstr "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  
    11=== Google Analytics Site Wide ===
    22Contributors: dansod
    3 Tags: analytics, google analytics, tracking code, site wide, google analytics site wide, universal analytics
     3Tags: analytics, google analytics, tracking code, site wide, google analytics site wide
    44Requires at least: 3.9
    55Tested up to: 4.0
     
    3333== Changelog ==
    3434
     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
    3539= 1.0 =
    3640* First release
Note: See TracChangeset for help on using the changeset viewer.