wp-google-analytics.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. Copyright 2006 Aaron D. Campbell (email : wp_plugins@xavisys.com)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. /**
  17. * Jetpack_Google_Analytics is the class that handles ALL of the plugin functionality.
  18. * It helps us avoid name collisions
  19. * http://codex.wordpress.org/Writing_a_Plugin#Avoiding_Function_Name_Collisions
  20. */
  21. if ( ! defined( 'ABSPATH' ) ) {
  22. exit;
  23. }
  24. require_once( plugin_basename( 'classes/wp-google-analytics-utils.php' ) );
  25. require_once( plugin_basename( 'classes/wp-google-analytics-options.php' ) );
  26. require_once( plugin_basename( 'classes/wp-google-analytics-legacy.php' ) );
  27. require_once( plugin_basename( 'classes/wp-google-analytics-universal.php' ) );
  28. class Jetpack_Google_Analytics {
  29. /**
  30. * @var Jetpack_Google_Analytics - Static property to hold our singleton instance
  31. */
  32. static $instance = false;
  33. /**
  34. * @var Static property to hold concrete analytics impl that does the work (universal or legacy)
  35. */
  36. static $analytics = false;
  37. /**
  38. * This is our constructor, which is private to force the use of get_instance()
  39. *
  40. * @return void
  41. */
  42. private function __construct() {
  43. if ( Jetpack_Google_Analytics_Options::enhanced_ecommerce_tracking_is_enabled() ) {
  44. $analytics = new Jetpack_Google_Analytics_Universal();
  45. } else {
  46. $analytics = new Jetpack_Google_Analytics_Legacy();
  47. }
  48. }
  49. /**
  50. * Function to instantiate our class and make it a singleton
  51. */
  52. public static function get_instance() {
  53. if ( ! self::$instance ) {
  54. self::$instance = new self;
  55. }
  56. return self::$instance;
  57. }
  58. }
  59. global $jetpack_google_analytics;
  60. $jetpack_google_analytics = Jetpack_Google_Analytics::get_instance();