You are here

function google_analytics_counter_gac_get_count in Google Analytics Counter 6

Same name and namespace in other branches
  1. 6.2 google_analytics_counter.module \google_analytics_counter_gac_get_count()
  2. 7 google_analytics_counter.module \google_analytics_counter_gac_get_count()
1 string reference to 'google_analytics_counter_gac_get_count'
google_analytics_counter_menu in ./google_analytics_counter.module
Menu for this module

File

./google_analytics_counter.module, line 107

Code

function google_analytics_counter_gac_get_count() {
  $path = google_analytics_counter_get_searched_path();

  // This gives the AJAX call URI, e.g. /google_analytics_counter/gac_get_count/node/264455. We need to get the calling page's URI.
  $path = explode("gac_get_count", $path);
  $path = $path[1];

  // We have something like /node/264455. Remove the leading slash.
  $path = trim(substr($path, 1));
  $sumarray = google_analytics_counter_get_sum_per_path($path);

  // Return Data
  $json = array();
  if (!empty($sumarray)) {
    $json['#google-analytics-counter-' . md5($path)] = google_analytics_counter_construct_content($sumarray) . ' (AJAX)';

    //$json['#google-analytics-counter'] = google_analytics_counter_construct_content($sumarray);
  }
  else {
    $json['#google-analytics-counter-' . md5($path)] = NULL;

    //$json['#google-analytics-counter'] = NULL;
  }

  // Send JSON Back
  drupal_json($json);
  exit;

  #return mt_rand(0,1000000);
}