Plugin Directory

Changeset 863963


Ignore:
Timestamp:
02/24/2014 10:23:24 AM (12 years ago)
Author:
audriusd
Message:

Google Universal Analytics v2.0

Location:
google-universal-analytics
Files:
53 added
4 edited

Legend:

Unmodified
Added
Removed
  • google-universal-analytics/trunk/googleanalytics.php

    r836381 r863963  
    44Plugin URI: http://wordpress.org/extend/plugins/google-universal-analytics/
    55Description: Adds <a href="http://www.google.com/analytics/">Google Analytics</a> tracking code on all pages.
    6 Version: 1.3
     6Version: 2.0
    77Author: Audrius Dobilinskas
    88Author URI: http://onlineads.lt/
     
    1818      define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins');
    1919
    20 function activate_google_universal_analytics() {
    21   add_option('web_property_id', 'Paste your Google Universal Analytics tracking code here...');
     20function deactive_google_universal_analytics() {
     21  delete_option('web_property_id');
     22  delete_option('in_footer');
     23  delete_option('plugin_switch');
     24  delete_option('track_links');
     25  //classic_options
     26  delete_option('classic_property_id');
     27  delete_option('classic_in_footer');
     28  delete_option('classic_plugin_switch');
    2229}
    2330
    24 function deactive_google_universal_analytics() {
    25   delete_option('web_property_id');
    26 }
    27 
    28 function admin_init_google_universal_analytics() {
    29   register_setting('google_universal_analytics', 'web_property_id');
    30 }
    3131
    3232function admin_menu_google_universal_analytics() {
    33   add_options_page('Google Universal Analytics', 'Google Universal Analytics', 'manage_options', 'google_universal_analytics', 'options_page_google_universal_analytics');
     33
     34 
     35 global  $settings_page, $settings_page1, $instructions_page;
     36 
     37  $settings_page    =   add_menu_page( 'Google Universal Analytics', 'Google Universal Analytics', 'manage_options', 'google_universal_analytics', 'options_page_google_universal_analytics' );
     38  add_submenu_page('google_universal_analytics','','','manage_options','google_universal_analytics','options_page_google_universal_analytics');
     39 $settings_page1    =    add_submenu_page( 'google_universal_analytics', 'Settings', 'Settings', 'manage_options', 'google_universal_analytics', 'options_page_google_universal_analytics' );
     40 $instructions_page =    add_submenu_page( 'google_universal_analytics', 'Classic Analytics', 'Classic Analytics', 'manage_options', 'classic_analytics', 'classic_analytics_page_google_universal_analytics' );
     41 
    3442}
    3543
     
    3745  include(WP_PLUGIN_DIR.'/google-universal-analytics/options.php'); 
    3846}
     47function classic_analytics_page_google_universal_analytics() {
     48  include(WP_PLUGIN_DIR.'/google-universal-analytics/classic/classic-analytics.php'); 
     49}
    3950
    4051function google_universal_analytics() {
    41   $web_property_id = get_option( 'web_property_id' );
    42 
    43   // Is the option just the UA id?
    44   $web_property_id_p1 = strtoupper( trim( $web_property_id ) );
    45   $web_property_id_p2 = '';
    46   if ( strpos( $web_property_id_p1, 'UA-' ) === 0 ) {
    47 
    48     // Does the option have a second parameter? (Comma separator)
    49     $web_property_id_p2_pos = strpos( $web_property_id, ',');
    50     if ( $web_property_id_p2_pos !== false ) {
    51 
    52       // Isolate the first parameter.
    53       $web_property_id_p1_pos = strpos( $web_property_id_p1, ',');
    54       if ( $web_property_id_p1_pos !== false ) {
    55         $web_property_id_p1 = substr( $web_property_id, 0, $web_property_id_p1_pos );
    56         if ( $web_property_id_p1 !== false ) {
    57           $web_property_id_p1 = strtoupper( trim( $web_property_id_p1 ) );
    58         } else {
    59           $web_property_id_p1 = '';
    60         }
    61       }
    62 
    63       // Isolate the second parameter.
    64       $web_property_id_p2_pos += 1;
    65       $web_property_id_p2 = substr( $web_property_id, $web_property_id_p2_pos );
    66       if ( $web_property_id_p2 !== false ) {
    67         $web_property_id_p2 = strtolower( trim( $web_property_id_p2 ) );
    68       } else {
    69         $web_property_id_p2 = '';
    70       }
    71     }
    72 
    73     // Build up a whitespace trimmed javascript that is the GA tracking script.
    74     // Include the option. One or two values.
    75     $web_property_id_js = '<script>';
    76     $web_property_id_js .= '(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){';
    77     $web_property_id_js .= '(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),';
    78     $web_property_id_js .= 'm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)';
    79     $web_property_id_js .= '})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');';
    80     $web_property_id_js .= 'ga(\'create\',\'' . $web_property_id_p1 . '\'';
    81     if ( strlen( $web_property_id_p2 ) > 1 ) {
    82       $web_property_id_js .= ',\'' . $web_property_id_p2 . '\'';
    83     }
    84     $web_property_id_js .= ');ga(\'send\',\'pageview\');';
    85     $web_property_id_js .= '</script>';
    86 
    87     $web_property_id = $web_property_id_js;
    88   }
    89   if ( strpos( $web_property_id, 'UA-' ) !== false ) {
    90     echo $web_property_id;
    91   }
     52  require 'tracking-code.php';
    9253}
    9354
    94 register_activation_hook(__FILE__, 'activate_google_universal_analytics');
     55function google_classic_analytics() {
     56  $classic_property_id  =   get_option('classic_property_id');
     57  $classic_analytics_code   =   "<script type='text/javascript'>
     58
     59  var _gaq = _gaq || [];
     60  _gaq.push(['_setAccount', '$classic_property_id']);
     61  _gaq.push(['_trackPageview']);
     62
     63  (function() {
     64    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
     65    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
     66    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     67  })();
     68
     69</script>";
     70echo $classic_analytics_code;
     71}
     72function google_universal_analytics_scripts($hook){
     73        global  $settings_page, $settings_page1, $instructions_page;
     74       
     75        if($hook != $settings_page && $hook != $settings_page1 && $hook != $instructions_page )
     76        return;
     77       
     78       
     79        //register styles
     80        wp_register_style( 'bootstrap-css', plugins_url( 'google-universal-analytics/bootstrap/css/bootstrap.min.css' , dirname(__FILE__) ) );
     81        wp_register_style( 'bootstrap-switch-css', plugins_url( 'google-universal-analytics/bootstrap/css/bootstrap-switch.min.css' , dirname(__FILE__) ) );
     82        wp_register_style( 'main-css', plugins_url( 'google-universal-analytics/assets/main.css' , dirname(__FILE__) ) );
     83       
     84        //register scripts
     85        wp_register_script( 'google-js', '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js', array(), '', true );
     86        wp_register_script( 'bootstrap-js', plugins_url( 'google-universal-analytics/bootstrap/js/bootstrap.min.js' , dirname(__FILE__) ), array('google-js'), '', true );
     87        wp_register_script( 'bootstrap-switch-js', plugins_url( 'google-universal-analytics/bootstrap/js/bootstrap-switch.min.js' , dirname(__FILE__) ) , array('bootstrap-js'),'',true );
     88        wp_register_script( 'main-js', plugins_url( 'google-universal-analytics/assets/main.js' , dirname(__FILE__) ) , array('google-js'),'',true );
     89       
     90       
     91        //enqueue styles
     92        wp_enqueue_style( 'bootstrap-css' );
     93        wp_enqueue_style( 'bootstrap-switch-css' );
     94        wp_enqueue_style( 'main-css' );
     95       
     96        //enqueue scripts
     97        wp_enqueue_script( 'google-js' );
     98        wp_enqueue_script( 'bootstrap-js' );
     99        wp_enqueue_script( 'bootstrap-switch-js' );
     100        wp_enqueue_script( 'main-js' );
     101}
     102
     103
    95104register_deactivation_hook(__FILE__, 'deactive_google_universal_analytics');
    96105
    97106if (is_admin()) {
    98   add_action('admin_init', 'admin_init_google_universal_analytics');
     107  add_action('admin_enqueue_scripts', 'google_universal_analytics_scripts');       
    99108  add_action('admin_menu', 'admin_menu_google_universal_analytics');
    100109}
    101110
    102 if (!is_admin()) {
    103   add_action('wp_head', 'google_universal_analytics');
     111if (!is_admin() && get_option('plugin_switch')=='on') {
     112    if(get_option('in_footer')=='on'){
     113        add_action('wp_footer', 'google_universal_analytics');
     114    }else{
     115        add_action('wp_head', 'google_universal_analytics');
     116    }
    104117}
    105118
     119if (!is_admin() && get_option('classic_plugin_switch')=='on') {
     120    if(get_option('classic_in_footer')=='on'){
     121        add_action('wp_footer', 'google_classic_analytics');
     122    }else{
     123        add_action('wp_head', 'google_classic_analytics');
     124    }
     125}
     126
     127
     128function save_google_universal_analytics_settings() {
     129    // The $_REQUEST contains all the data sent via ajax
     130    if ( isset($_REQUEST) ) {
     131        $property_id = $_REQUEST['property_id'];
     132        $in_footer = $_REQUEST['in_footer'];
     133        $plugin_switch = $_REQUEST['plugin_switch'];
     134        $track_links = $_REQUEST['track_links'];
     135       
     136       
     137        update_option('web_property_id', $property_id);
     138        update_option('in_footer', $in_footer);
     139        update_option('plugin_switch', $plugin_switch);
     140        update_option('track_links', $track_links);
     141    }
     142    // Always die in functions echoing ajax content
     143   die();
     144}
     145
     146function save_google_classic_analytics_settings() {
     147    // The $_REQUEST contains all the data sent via ajax
     148    if ( isset($_REQUEST) ) {
     149        $classic_property_id = $_REQUEST['classic_property_id'];
     150        $classic_in_footer = $_REQUEST['classic_in_footer'];
     151        $classic_plugin_switch = $_REQUEST['classic_plugin_switch'];
     152       
     153       
     154        update_option('classic_property_id', $classic_property_id);
     155        update_option('classic_in_footer', $classic_in_footer);
     156        update_option('classic_plugin_switch', $classic_plugin_switch);
     157    }
     158    // Always die in functions echoing ajax content
     159   die();
     160}
     161
     162add_action( 'wp_ajax_save_google_universal_analytics_settings', 'save_google_universal_analytics_settings' );
     163add_action( 'wp_ajax_save_google_classic_analytics_settings', 'save_google_classic_analytics_settings' );
     164
     165
     166
    106167?>
  • google-universal-analytics/trunk/options.php

    r836381 r863963  
    11<div class="wrap">
    2 
    3 <h2>Google Universal Analytics</h2>
    4 
    5 <form method="post" action="options.php">
    6 <?php wp_nonce_field('update-options'); ?>
    7 <?php settings_fields('google_universal_analytics'); ?>
    8 
    9 <style type="text/css">
    10 .tooltip {
    11   border-bottom: 1px dotted #000000;
    12   color: #000000; outline: none;
    13   cursor: help; text-decoration: none;
    14   position: relative;
    15 }
    16 .tooltip span {
    17   margin-left: -999em;
    18   position: absolute;
    19 }
    20 .tooltip:hover span {
    21   font-family: Calibri, Tahoma, Geneva, sans-serif;
    22   position: absolute;
    23   left: 1em;
    24   top: 2em;
    25   z-index: 99;
    26   margin-left: 0;
    27   width: 450px;
    28 }
    29 .tooltip:hover img {
    30   border: 0;
    31   margin: -10px 0 0 -55px;
    32   float: left;
    33   position: absolute;
    34 }
    35 .tooltip:hover em {
    36   font-family: Candara, Tahoma, Geneva, sans-serif;
    37   font-size: 1.2em;
    38   font-weight: bold;
    39   display: block;
    40   padding: 0.2em 0 0.6em 0;
    41 }
    42 .classic { padding: 0.8em 1em; }
    43 .custom { padding: 0.5em 0.8em 0.8em 2em; }
    44 * html a:hover { background: transparent; }
    45 </style>
    46 
    47 <p><b>Option 1:</b> Insert your Google Universal Analytics javascript code below
    48 <a class="tooltip" href="#">(Code Example)<span class="classic">
    49     &lt;script&gt;</br>
    50   (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){</br>
    51   (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),</br>
    52   m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)</br>
    53   })(window,document,'script','//www.google-analytics.com/analytics.js','ga');</br>
     2  <h2>Google Universal Analytics</h2>
     3 
     4  <br />
     5  <div class="col-lg-6 row">
     6      <form class="form-horizontal" role="form" id="google-universal-options">
     7       
     8        <div class="form-group">
     9          <label for="web_property_id" class="col-sm-3 control-label">Status</label>
     10          <div class="col-sm-9">
     11            <input id="plugin_switch" type="checkbox" name="plugin_switch" <?php if(get_option('plugin_switch')=='on'): ?> checked="checked" <?php endif; ?>>
     12           
     13          </div>
     14        </div>
     15        <div class="form-group">
     16          <label for="web_property_id" class="col-sm-3 control-label">Tracking ID</label>
     17          <div class="col-sm-9">
     18            <input type="text" class="form-control" name="web_property_id" id="web_property_id" placeholder="Tracking code example: UA-­23710711-­7" value="<?php echo get_option('web_property_id'); ?>">
     19            <span class="error hide"><strong>Error! </strong> match your code with this forma: UA-41115660-1</span>
     20          </div>
     21        </div>
     22        <div class="form-group">
     23          <label for="web_property_id" class="col-sm-3 control-label"></label>
     24          <div class="col-sm-9">
     25                <i>Advanced settings:</i>
     26          </div>
     27        </div>
     28       
     29        <div class="form-group">
     30          <div class="col-sm-offset-3 col-sm-9">
     31            <div class="checkbox">
     32              <label>
     33                <input type="checkbox" name="in_footer" id="in_footer" <?php if(get_option('in_footer')=='on'): ?> checked="checked" <?php endif; ?>>
     34                Place code in footer </label>
     35            </div>
     36          </div>
     37        </div>
     38        <div class="form-group">
     39          <div class="col-sm-offset-3 col-sm-9">
     40            <div class="checkbox">
     41              <label>
     42                <input type="checkbox" name="track_links" id="track_links" <?php if(get_option('track_links')=='on'): ?> checked="checked" <?php endif; ?>>
     43                Track events (Downloads, Mailto & Outbound URLs) </label>
     44            </div>
     45          </div>
     46        </div>
     47       
     48        <div class="form-group">
     49          <div class="col-sm-offset-3 col-sm-9">
     50            <input type="hidden" id="ajax_url" name="ajax_url" value="<?php echo admin_url('admin-ajax.php'); ?>" />
     51            <button type="button" class="btn btn-primary" id="save-gua-settings">Save Changes</button><span class="alert alert-success hide"><strong>Options Saved</strong></span>
     52          </div>
     53        </div>
     54      </form>
     55  </div>
     56  <div class="clearfix"></div>
     57  <div class="row col-lg-6">Have a question? Drop us a question at <a href="http://onlineads.lt/?utm_source=WordPress&utm_medium=Google%20Universal%20Analytics%202.0&utm_content=Google%20Universal%20Analytics&utm_campaign=WordPress%20plugins" title="Google Universal Analytics">OnlineAds.lt</a> </div>
     58</div>
    5459</br>
    55   ga('create', 'UA-23710779-8', 'onlineads.lt');</br>
    56   ga('send', 'pageview');</br>
    57 </br>
    58   &lt;/script&gt;
    59 </span></a>:</p>
    60 <p><b>Option 2:</b> Insert just the web property id. Example: UA-23710779-8</p>
    61 <p><b>Option 3:</b> Insert the web property id, a comma and then the domain name. Example: UA-23710779-8,onlineads.lt</p>
    62 <textarea name="web_property_id" id="web_property_id" rows="10"  cols="65" >
    63 <?php echo get_option('web_property_id'); ?> </textarea>
    64 
    65 <input type="hidden" name="action" value="update" />
    66 
    67 <p class="submit">
    68 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
    69 </p>
    70 
    71 </form>
    72 Have a question? Drop us a question at <a href="http://onlineads.lt/?utm_source=WordPress&utm_medium=Google%20Universal%20Analytics%201.3&utm_campaign=WordPress%20plugins" title="Google Universal Analytics">OnlineAds.lt</a>
    73 </div>
    74 
    75 </br>
  • google-universal-analytics/trunk/readme.txt

    r836878 r863963  
    22Contributors: audriusd
    33Donate link: http://onlineads.lt/
    4 Tags: javascript, tracking, google, analytics, universal, statistics, google analytics, universal analytics, google universal analytics
    5 Requires at least: 2.7
    6 Tested up to: 3.8
    7 Stable tag: 1.3
     4Tags: javascript, tracking, google, analytics, universal, statistics, google analytics, universal analytics, google universal analytics, classic
     5Requires at least: 3.0
     6Tested up to: 3.8.1
     7Stable tag: 2.0
    88License: GPLv2 or later
    99
    10 Adds the latest Google Universal Analytics JavaScript tracking code to your WordPress website.
     10Adds the latest Google Universal Analytics JavaScript tracking code to your WordPress website. Event tracking is now available.
    1111
    1212== Description ==
     
    2020* Multi-platform tracking;
    2121* Simplified configuration controls;
     22* It is the new analytics standard set by Google;
    2223* ...and more.
    2324
     
    28291. Upload `google-universal-analytics` directory to the `/wp-content/plugins/` directory or use plugin search - Admin > Plugins > Add new > Search for 'Google Universal Analytics'.
    29302. Activate the plugin through the 'Plugins' menu in WordPress
    30 3. Paste tracking code from Google Analytics to the settings (Admin > Settings > Google Universal Analytics)
     313. Paste tracking code from Google Analytics to the settings (Admin > Google Universal Analytics (below Settings button)
    3132
    3233== Frequently Asked Questions ==
    3334
    34 = How to install Google Analytics for my WordPress blog? =
     35= Can I use both - Google Universal Analytics and Classic Google Analytics? =
    3536
    36 Follow the link for step-by-step guide:
    37 [http://onlineads.lt/how-to-install-google-universal-analytics-for-your-wordpress-blog/](http://onlineads.lt/how-to-install-google-universal-analytics-for-your-wordpress-blog/)
     37Yes. Simply enable both in the Settings page. It is totally fine to have both of them running at the same time.
    3838
    39 = How can I update and modify the tracking code? =
     39= I cannot see tracker's activation button in the Settings page? =
    4040
    41 The same way you entered it the first time: Admin > Settings > Google Universal Analytics
     41Make sure you have the latest WordPress version running and have a modern web browser. If these are not a case, try cleaning browser's cache and cookies.
     42
     43= How can I update and modify the tracking ID? =
     44
     45The same way you entered it the first time: Admin > Google Universal Analytics (below Settings button)
    4246
    4347= How can I get support? =
     
    4650Also, do not hesitate to contact us if you have any questions regarding [Google Analytics](http://onlineads.lt/contact-us/).
    4751
     52= Feature that I need is not available with this plugin. How can I recommend a new feature? =
     53
     54[Submit your idea at our website](http://onlineads.lt/contact-us/).
     55
    4856== Screenshots ==
    4957
     581. Google Universal Analytics plugin interface with additional options.
    50591. Google Analytics and Google Universal Analytics compared.
    5160
    5261== Changelog ==
    5362
     63= 2.0 =
     64* Completelly updated the whole plugin.
     65* Events tracking is now available.
     66* Tracking code can now be removed without deactivating the plugin (ON/OFF button).
     67* Supports both Google Universal Analytics (analytics.js) and older Google Analytics (ga.js) versions.
     68
    5469= 1.3 =
    55 * More options in the plugin settings (admin section).
    56 * Big thanks to estepix for code suggestion!
     70* More options in the plugin settings (admin section).
    5771
    5872= 1.2 =
     
    6882== Upgrade Notice ==
    6983
     84= 2.0 =
     85* Important upgrade. More options added. More powerful than ever before!
     86
    7087= 1.3 =
    7188* Important: Bug fixed, more options available.
Note: See TracChangeset for help on using the changeset viewer.