diff --git a/googleanalytics.admin.inc b/googleanalytics.admin.inc
index a726186..68e0ed5 100644
--- a/googleanalytics.admin.inc
+++ b/googleanalytics.admin.inc
@@ -24,6 +24,23 @@ function googleanalytics_admin_settings_form($form_state) {
     '#description' => t('This ID is unique to each site you want to track separately, and is in the form of UA-xxxxxxx-yy. To get a Web Property ID, <a href="@analytics">register your site with Google Analytics</a>, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. <a href="@webpropertyid">Find more information in the documentation</a>.', array('@analytics' => 'http://www.google.com/analytics/', '@webpropertyid' => 'http://code.google.com/apis/analytics/docs/concepts/gaConceptsAccounts.html#webProperty')),
   );
 
+//add option to select between server or client side tracking method
+  $form['account']['googleanalytics_use_phpga'] = array(
+    '#type' => 'radios',
+    '#title' => t('Select tracking method'),
+    '#options' => array(
+      0 => t('Client side cookies') . '<div class="description">' . t('The standard approach is to use cookies') . '</div>',
+      1 => t('Server side submission') . '<div class="description">' . t('Use this approach if you do not want to send tracking cookies to your users.  Tracking data is sent via the server on page load.  Not all Analytics data is supported - this is an experimental addition at the moment!') . '</div>',
+    ),
+    '#default_value' => variable_get('googleanalytics_use_phpga', 0),
+  );
+
+// test if /sites/all/libraries/php-ga exists...
+  if(_googleanalytics_phpga_get_path()==NULL) {
+    $form['account']['googleanalytics_use_phpga']['#disabled']= TRUE;
+    $form['account']['googleanalytics_use_phpga']['#description']= t('You need to install php-ga to enable this option, default Client side cookies will be used.  To install php-ga, download the library to sites/all/libraries/php-ga.  <a href="@phpga">You can find php-ga here</a>', array('@phpga' => 'http://code.google.com/p/php-ga/'));
+  }
+
   // Visibility settings.
   $form['tracking_title'] = array(
     '#type' => 'item',
diff --git a/googleanalytics.install b/googleanalytics.install
index b696081..6e7659b 100644
--- a/googleanalytics.install
+++ b/googleanalytics.install
@@ -46,6 +46,7 @@ function googleanalytics_uninstall() {
   variable_del('googleanalytics_translation_set');
   variable_del('googleanalytics_visibility_pages');
   variable_del('googleanalytics_visibility_roles');
+  variable_del('googleanalytics_use_phpga');
 
   // Remove backup variables if exits. Remove this code in D8.
   variable_del('googleanalytics_codesnippet_after_backup_6300');
diff --git a/googleanalytics.module b/googleanalytics.module
index 77ef862..0b00500 100644
--- a/googleanalytics.module
+++ b/googleanalytics.module
@@ -14,6 +14,9 @@ define('GOOGLEANALYTICS_TRACKFILES_EXTENSIONS', '7z|aac|arc|arj|asf|asx|avi|bin|
 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
 define('GOOGLEANALYTICS_PAGES', "admin\nadmin/*\nbatch\nnode/add*\nnode/*/*\nuser/*/*");
 
+// Path to php-ga
+define('GOOGLEANALYTICS_PHPGA_PATH', 'sites/all/libraries/php-ga');
+
 /**
  * Implements hook_help().
  */
@@ -77,214 +80,251 @@ function googleanalytics_menu() {
  * Implements hook_page_alter() to insert JavaScript to the appropriate scope/region of the page.
  */
 function googleanalytics_page_alter(&$page) {
-  global $user;
-
-  $id = variable_get('googleanalytics_account', '');
-
-  // Get page status code for visibility filtering.
-  $status = drupal_get_http_header('Status');
-  $trackable_status_codes = array(
-    '403 Forbidden',
-    '404 Not Found',
-  );
-
-  // 1. Check if the GA account number has a value.
-  // 2. Track page views based on visibility value.
-  // 3. Check if we should track the currently active user's role.
-  // 4. Ignore pages visibility filter for 404 or 403 status codes.
-  if (!empty($id) && (_googleanalytics_visibility_pages() || in_array($status, $trackable_status_codes)) && _googleanalytics_visibility_user($user)) {
-
-    // We allow different scopes. Default to 'header' but allow user to override if they really need to.
-    $scope = variable_get('googleanalytics_js_scope', 'header');
-
-    if (variable_get('googleanalytics_trackadsense', FALSE)) {
-      // Custom tracking. Prepend before all other JavaScript.
-      drupal_add_js('window.google_analytics_uacct = ' . drupal_json_encode($id) . ';', array('type' => 'inline', 'group' => JS_LIBRARY-1));
-    }
-
-    // Add link tracking.
-    $link_settings = array();
-    if ($track_outbound = variable_get('googleanalytics_trackoutbound', 1)) {
-      $link_settings['trackOutbound'] = $track_outbound;
-    }
-    if ($track_mailto = variable_get('googleanalytics_trackmailto', 1)) {
-      $link_settings['trackMailto'] = $track_mailto;
-    }
-    if (($track_download = variable_get('googleanalytics_trackfiles', 1)) && ($trackfiles_extensions = variable_get('googleanalytics_trackfiles_extensions', GOOGLEANALYTICS_TRACKFILES_EXTENSIONS))) {
-      $link_settings['trackDownload'] = $track_download;
-      $link_settings['trackDownloadExtensions'] = $trackfiles_extensions;
-    }
-    if ($track_domain_mode = variable_get('googleanalytics_domain_mode', 0)) {
-      $link_settings['trackDomainMode'] = $track_domain_mode;
-    }
-    if ($track_cross_domains = variable_get('googleanalytics_cross_domains', '')) {
-      $domains = preg_split('/(\r\n?|\n)/', $track_cross_domains);
-      $link_settings['trackCrossDomains'] = implode('|', $domains);
-    }
-
-    if (!empty($link_settings)) {
-      drupal_add_js(array('googleanalytics' => $link_settings), 'setting');
-      drupal_add_js(drupal_get_path('module', 'googleanalytics') . '/googleanalytics.js');
-    }
-
-    // Add User profile segmentation values.
-    $profile_fields = variable_get('googleanalytics_segmentation', array());
-    if (!empty($profile_fields)) {
-      // Invoke all modules having a hook_user_load() implemented.
-      // If the invoked modules extend the $user object, the additional
-      // data can be tracked.
-      module_invoke_all('user_load', array($user->uid => $user));
-
-      $fields = array();
-      foreach ($profile_fields as $field => $title) {
-        $fields[$field] = is_array($user->$field) ? implode(',', $user->$field) : $user->$field;
+  if (variable_get('googleanalytics_use_phpga',0)==0) {
+    global $user;
+  
+    $id = variable_get('googleanalytics_account', '');
+  
+    // Get page status code for visibility filtering.
+    $status = drupal_get_http_header('Status');
+    $trackable_status_codes = array(
+      '403 Forbidden',
+      '404 Not Found',
+    );
+  
+    // 1. Check if the GA account number has a value.
+    // 2. Track page views based on visibility value.
+    // 3. Check if we should track the currently active user's role.
+    // 4. Ignore pages visibility filter for 404 or 403 status codes.
+    if (!empty($id) && (_googleanalytics_visibility_pages() || in_array($status, $trackable_status_codes)) && _googleanalytics_visibility_user($user)) {
+  
+      // We allow different scopes. Default to 'header' but allow user to override if they really need to.
+      $scope = variable_get('googleanalytics_js_scope', 'header');
+  
+      if (variable_get('googleanalytics_trackadsense', FALSE)) {
+        // Custom tracking. Prepend before all other JavaScript.
+        drupal_add_js('window.google_analytics_uacct = ' . drupal_json_encode($id) . ';', array('type' => 'inline', 'group' => JS_LIBRARY-1));
       }
-
-      // Only show segmentation variable if there are specified fields.
-      $segmentation = '';
-      if (count($fields) > 0) {
-        $segmentation = '_gaq.push(["_setVar", ' . drupal_json_encode(implode(':', $fields)) . ']);';
+  
+      // Add link tracking.
+      $link_settings = array();
+      if ($track_outbound = variable_get('googleanalytics_trackoutbound', 1)) {
+        $link_settings['trackOutbound'] = $track_outbound;
       }
-    }
-
-    // Site search tracking support.
-    $url_custom = '';
-    if (module_exists('search') && variable_get('googleanalytics_site_search', FALSE) && arg(0) == 'search' && $keys = googleanalytics_search_get_keys()) {
-      $url_custom = '(window.googleanalytics_search_results) ? ' . drupal_json_encode(url('search/' . arg(1), array('query' => array('search' => $keys)))) . ' : ' . drupal_json_encode(url('search/' . arg(1), array('query' => array('search' => 'no-results:' . $keys, 'cat' => 'no-results'))));
-    }
-
-    // If this node is a translation of another node, pass the original
-    // node instead.
-    if (module_exists('translation') && variable_get('googleanalytics_translation_set', 0)) {
-      // Check we have a node object, it supports translation, and its
-      // translated node ID (tnid) doesn't match its own node ID.
-      $node = menu_get_object();
-      if ($node && translation_supported_type($node->type) && !empty($node->tnid) && ($node->tnid != $node->nid)) {
-        $source_node = node_load($node->tnid);
-        $languages = language_list();
-        $url_custom = drupal_json_encode(url('node/' . $source_node->nid, array('language' => $languages[$source_node->language])));
+      if ($track_mailto = variable_get('googleanalytics_trackmailto', 1)) {
+        $link_settings['trackMailto'] = $track_mailto;
       }
-    }
-
-    // Track access denied (403) and file not found (404) pages.
-    if ($status == '403 Forbidden') {
-      // See http://www.google.com/support/analytics/bin/answer.py?answer=86927
-      $url_custom = '"/403.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer';
-    }
-    elseif ($status == '404 Not Found') {
-      $url_custom = '"/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer';
-    }
-
-    // Add any custom code snippets if specified.
-    $codesnippet_before = variable_get('googleanalytics_codesnippet_before', '');
-    $codesnippet_after = variable_get('googleanalytics_codesnippet_after', '');
-
-    // Add custom variables.
-    $googleanalytics_custom_vars = variable_get('googleanalytics_custom_var', array());
-    $custom_var = '';
-    for ($i = 1; $i < 6; $i++) {
-      $custom_var_name = !empty($googleanalytics_custom_vars['slots'][$i]['name']) ? $googleanalytics_custom_vars['slots'][$i]['name'] : '';
-      if (!empty($custom_var_name)) {
-        $custom_var_value = !empty($googleanalytics_custom_vars['slots'][$i]['value']) ? $googleanalytics_custom_vars['slots'][$i]['value'] : '';
-        $custom_var_scope = !empty($googleanalytics_custom_vars['slots'][$i]['scope']) ? $googleanalytics_custom_vars['slots'][$i]['scope'] : 3;
-
-        $types = array();
-        $node = menu_get_object();
-        if (is_object($node)) {
-          $types += array('node' => $node);
+      if (($track_download = variable_get('googleanalytics_trackfiles', 1)) && ($trackfiles_extensions = variable_get('googleanalytics_trackfiles_extensions', GOOGLEANALYTICS_TRACKFILES_EXTENSIONS))) {
+        $link_settings['trackDownload'] = $track_download;
+        $link_settings['trackDownloadExtensions'] = $trackfiles_extensions;
+      }
+      if ($track_domain_mode = variable_get('googleanalytics_domain_mode', 0)) {
+        $link_settings['trackDomainMode'] = $track_domain_mode;
+      }
+      if ($track_cross_domains = variable_get('googleanalytics_cross_domains', '')) {
+        $domains = preg_split('/(\r\n?|\n)/', $track_cross_domains);
+        $link_settings['trackCrossDomains'] = implode('|', $domains);
+      }
+  
+      if (!empty($link_settings)) {
+        drupal_add_js(array('googleanalytics' => $link_settings), 'setting');
+        drupal_add_js(drupal_get_path('module', 'googleanalytics') . '/googleanalytics.js');
+      }
+  
+      // Add User profile segmentation values.
+      $profile_fields = variable_get('googleanalytics_segmentation', array());
+      if (!empty($profile_fields)) {
+        // Invoke all modules having a hook_user_load() implemented.
+        // If the invoked modules extend the $user object, the additional
+        // data can be tracked.
+        module_invoke_all('user_load', array($user->uid => $user));
+  
+        $fields = array();
+        foreach ($profile_fields as $field => $title) {
+          $fields[$field] = is_array($user->$field) ? implode(',', $user->$field) : $user->$field;
         }
-        $custom_var_value = token_replace($custom_var_value, $types, array('clear' => TRUE));
-
-        // Suppress empty custom variables.
-        if (!is_numeric($custom_var_value) && empty($custom_var_value)) {
-          continue;
+  
+        // Only show segmentation variable if there are specified fields.
+        $segmentation = '';
+        if (count($fields) > 0) {
+          $segmentation = '_gaq.push(["_setVar", ' . drupal_json_encode(implode(':', $fields)) . ']);';
         }
-
-        // The length of the string used for the 'name' and the length of the
-        // string used for the 'value' must not exceed 64 bytes after url encoding.
-        $name_length = drupal_strlen(rawurlencode($custom_var_name));
-        $tmp_value = rawurlencode($custom_var_value);
-        $value_length = drupal_strlen($tmp_value);
-        if ($name_length + $value_length > 64) {
-          // Trim value and remove fragments of url encoding.
-          $tmp_value = rtrim(substr($tmp_value, 0, 63 - $name_length), '%0..9A..F');
-          $custom_var_value = urldecode($tmp_value);
+      }
+  
+      // Site search tracking support.
+      $url_custom = '';
+      if (module_exists('search') && variable_get('googleanalytics_site_search', FALSE) && arg(0) == 'search' && $keys = googleanalytics_search_get_keys()) {
+        $url_custom = '(window.googleanalytics_search_results) ? ' . drupal_json_encode(url('search/' . arg(1), array('query' => array('search' => $keys)))) . ' : ' . drupal_json_encode(url('search/' . arg(1), array('query' => array('search' => 'no-results:' . $keys, 'cat' => 'no-results'))));
+      }
+  
+      // If this node is a translation of another node, pass the original
+      // node instead.
+      if (module_exists('translation') && variable_get('googleanalytics_translation_set', 0)) {
+        // Check we have a node object, it supports translation, and its
+        // translated node ID (tnid) doesn't match its own node ID.
+        $node = menu_get_object();
+        if ($node && translation_supported_type($node->type) && !empty($node->tnid) && ($node->tnid != $node->nid)) {
+          $source_node = node_load($node->tnid);
+          $languages = language_list();
+          $url_custom = drupal_json_encode(url('node/' . $source_node->nid, array('language' => $languages[$source_node->language])));
         }
-
-        $custom_var_name = drupal_json_encode($custom_var_name);
-        $custom_var_value = drupal_json_encode($custom_var_value);
-        $custom_var .= "_gaq.push(['_setCustomVar', $i, $custom_var_name, $custom_var_value, $custom_var_scope]);";
       }
+  
+      // Track access denied (403) and file not found (404) pages.
+      if ($status == '403 Forbidden') {
+        // See http://www.google.com/support/analytics/bin/answer.py?answer=86927
+        $url_custom = '"/403.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer';
+      }
+      elseif ($status == '404 Not Found') {
+        $url_custom = '"/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer';
+      }
+  
+      // Add any custom code snippets if specified.
+      $codesnippet_before = variable_get('googleanalytics_codesnippet_before', '');
+      $codesnippet_after = variable_get('googleanalytics_codesnippet_after', '');
+  
+      // Add custom variables.
+      $googleanalytics_custom_vars = variable_get('googleanalytics_custom_var', array());
+      $custom_var = '';
+      for ($i = 1; $i < 6; $i++) {
+        $custom_var_name = !empty($googleanalytics_custom_vars['slots'][$i]['name']) ? $googleanalytics_custom_vars['slots'][$i]['name'] : '';
+        if (!empty($custom_var_name)) {
+          $custom_var_value = !empty($googleanalytics_custom_vars['slots'][$i]['value']) ? $googleanalytics_custom_vars['slots'][$i]['value'] : '';
+          $custom_var_scope = !empty($googleanalytics_custom_vars['slots'][$i]['scope']) ? $googleanalytics_custom_vars['slots'][$i]['scope'] : 3;
+  
+          $types = array();
+          $node = menu_get_object();
+          if (is_object($node)) {
+            $types += array('node' => $node);
+          }
+          $custom_var_value = token_replace($custom_var_value, $types, array('clear' => TRUE));
+  
+          // Suppress empty custom variables.
+          if (!is_numeric($custom_var_value) && empty($custom_var_value)) {
+            continue;
+          }
+  
+          // The length of the string used for the 'name' and the length of the
+          // string used for the 'value' must not exceed 64 bytes after url encoding.
+          $name_length = drupal_strlen(rawurlencode($custom_var_name));
+          $tmp_value = rawurlencode($custom_var_value);
+          $value_length = drupal_strlen($tmp_value);
+          if ($name_length + $value_length > 64) {
+            // Trim value and remove fragments of url encoding.
+            $tmp_value = rtrim(substr($tmp_value, 0, 63 - $name_length), '%0..9A..F');
+            $custom_var_value = urldecode($tmp_value);
+          }
+  
+          $custom_var_name = drupal_json_encode($custom_var_name);
+          $custom_var_value = drupal_json_encode($custom_var_value);
+          $custom_var .= "_gaq.push(['_setCustomVar', $i, $custom_var_name, $custom_var_value, $custom_var_scope]);";
+        }
+      }
+  
+      // Build tracker code.
+      $script = 'var _gaq = _gaq || [];';
+      $script .= '_gaq.push(["_setAccount", ' . drupal_json_encode($id) . ']);';
+      if (variable_get('googleanalytics_tracker_anonymizeip', 0)) {
+        // FIXME: The Google API is currently broken and "_gat._anonymizeIp" is only
+        // a workaround until "_anonymizeIp" has been implemented/fixed.
+        $script .= '_gaq.push(["_gat._anonymizeIp"]);';
+      }
+  
+      // Domain tracking type.
+      global $cookie_domain;
+      $domain_mode = variable_get('googleanalytics_domain_mode', 0);
+  
+      // Per RFC 2109, cookie domains must contain at least one dot other than the
+      // first. For hosts such as 'localhost' or IP Addresses we don't set a cookie domain.
+      if ($domain_mode == 1 && count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
+        $script .= '_gaq.push(["_setDomainName", ' . drupal_json_encode($cookie_domain) . ']);';
+      }
+      elseif ($domain_mode == 2) {
+        $script .= '_gaq.push(["_setDomainName", "none"]);';
+        $script .= '_gaq.push(["_setAllowLinker", true]);';
+      }
+  
+      if (!empty($segmentation)) {
+        $script .= $segmentation;
+      }
+      if (!empty($custom_var)) {
+        $script .= $custom_var;
+      }
+      if (!empty($codesnippet_before)) {
+        $script .= $codesnippet_before;
+      }
+      if (empty($url_custom)) {
+        $script .= '_gaq.push(["_trackPageview"]);';
+      }
+      else {
+        $script .= '_gaq.push(["_trackPageview", ' . $url_custom . ']);';
+      }
+      if (!empty($codesnippet_after)) {
+        $script .= $codesnippet_after;
+      }
+  
+      $script .= '(function() {';
+      $script .= 'var ga = document.createElement("script");';
+      $script .= 'ga.type = "text/javascript";';
+      $script .= 'ga.async = true;';
+  
+      // Should a local cached copy of ga.js be used?
+      if (variable_get('googleanalytics_cache', 0) && $url = _googleanalytics_cache('http://www.google-analytics.com/ga.js')) {
+        // A dummy query-string is added to filenames, to gain control over
+        // browser-caching. The string changes on every update or full cache
+        // flush, forcing browsers to load a new copy of the files, as the
+        // URL changed.
+        $query_string = '?' . variable_get('css_js_query_string', '0');
+  
+        $script .= 'ga.src = "' . $url . $query_string . '";';
+      }
+      else {
+        $script .= 'ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";';
+      }
+      $script .= 'var s = document.getElementsByTagName("script")[0];';
+      $script .= 's.parentNode.insertBefore(ga, s);';
+      $script .= '})();';
+  
+      drupal_add_js($script, array('scope' => $scope, 'type' => 'inline'));
     }
+  }
+}
 
-    // Build tracker code.
-    $script = 'var _gaq = _gaq || [];';
-    $script .= '_gaq.push(["_setAccount", ' . drupal_json_encode($id) . ']);';
-    if (variable_get('googleanalytics_tracker_anonymizeip', 0)) {
-      // FIXME: The Google API is currently broken and "_gat._anonymizeIp" is only
-      // a workaround until "_anonymizeIp" has been implemented/fixed.
-      $script .= '_gaq.push(["_gat._anonymizeIp"]);';
-    }
-
-    // Domain tracking type.
-    global $cookie_domain;
-    $domain_mode = variable_get('googleanalytics_domain_mode', 0);
+/**
+ * Implements hook_page_build() to submit server side analytics
+ */
+function googleanalytics_page_build(&$page) {
+  if (variable_get('googleanalytics_use_phpga',0)==1) {
+  // use server side cookie method (php-ga)
+    $id = variable_get('googleanalytics_account', '');
+    require_once(_googleanalytics_phpga_get_path() . '/src/autoload.php');
+    //use UnitedPrototype\GoogleAnalytics;  //causes 500 Internal Server error, so need to use full namespace references eg UnitedPrototype\GoogleAnalytics\Tracker instead of GoogleAnalytics\Tracker
 
-    // Per RFC 2109, cookie domains must contain at least one dot other than the
-    // first. For hosts such as 'localhost' or IP Addresses we don't set a cookie domain.
-    if ($domain_mode == 1 && count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
-      $script .= '_gaq.push(["_setDomainName", ' . drupal_json_encode($cookie_domain) . ']);';
-    }
-    elseif ($domain_mode == 2) {
-      $script .= '_gaq.push(["_setDomainName", "none"]);';
-      $script .= '_gaq.push(["_setAllowLinker", true]);';
-    }
+    // Initilize GA Tracker
+    $tracker = new UnitedPrototype\GoogleAnalytics\Tracker($id, $_SERVER['HTTP_HOST']);  //need to look this up in the GA settings?
 
-    if (!empty($segmentation)) {
-      $script .= $segmentation;
-    }
-    if (!empty($custom_var)) {
-      $script .= $custom_var;
-    }
-    if (!empty($codesnippet_before)) {
-      $script .= $codesnippet_before;
-    }
-    if (empty($url_custom)) {
-      $script .= '_gaq.push(["_trackPageview"]);';
-    }
-    else {
-      $script .= '_gaq.push(["_trackPageview", ' . $url_custom . ']);';
-    }
-    if (!empty($codesnippet_after)) {
-      $script .= $codesnippet_after;
-    }
+    // Assemble Visitor information
+    $visitor = new UnitedPrototype\GoogleAnalytics\Visitor();
+    $visitor->setIpAddress($_SERVER['REMOTE_ADDR']);
+    $visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']);
+    $visitor->setScreenResolution('1024x768');
 
-    $script .= '(function() {';
-    $script .= 'var ga = document.createElement("script");';
-    $script .= 'ga.type = "text/javascript";';
-    $script .= 'ga.async = true;';
+    // Assemble Session information
+    $ga_session = new UnitedPrototype\GoogleAnalytics\Session();
 
-    // Should a local cached copy of ga.js be used?
-    if (variable_get('googleanalytics_cache', 0) && $url = _googleanalytics_cache('http://www.google-analytics.com/ga.js')) {
-      // A dummy query-string is added to filenames, to gain control over
-      // browser-caching. The string changes on every update or full cache
-      // flush, forcing browsers to load a new copy of the files, as the
-      // URL changed.
-      $query_string = '?' . variable_get('css_js_query_string', '0');
+    // Assemble Page information
+    $pageinfo = new UnitedPrototype\GoogleAnalytics\Page("/" . current_path());
+    $pageinfo->setTitle(drupal_get_title());
 
-      $script .= 'ga.src = "' . $url . $query_string . '";';
-    }
-    else {
-      $script .= 'ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";';
-    }
-    $script .= 'var s = document.getElementsByTagName("script")[0];';
-    $script .= 's.parentNode.insertBefore(ga, s);';
-    $script .= '})();';
+    // Track page view
+    $tracker->trackPageview($pageinfo, $ga_session, $visitor);
 
-    drupal_add_js($script, array('scope' => $scope, 'type' => 'inline'));
+//    drupal_set_message("Analytics submitted for:" . drupal_get_title() . " - " . current_path());
   }
 }
 
+
+
 /**
  * Implements hook_form_FORM_ID_alter().
  *
@@ -579,3 +619,23 @@ function _googleanalytics_visibility_header($account) {
 
   return TRUE;
 }
+
+/**
+ * Helper function to return the path to php-ga
+ *
+ */
+function _googleanalytics_phpga_get_path() {
+  static $library_path = NULL;
+
+  // First check the default location.
+  if (is_file(GOOGLEANALYTICS_PHPGA_PATH . '/src/autoload.php')) {
+    $library_path = GOOGLEANALYTICS_PHPGA_PATH;
+  }
+  // Ask the libraries module as a fallback.
+  elseif ($library_path == NULL && module_exists('libraries')) {
+    if ($path = libraries_get_path('php-ga')) {
+      $library_path = $path;
+    }
+  }
+  return $library_path;
+}
