You are here

function _google_analytics_counter_path_filter in Google Analytics Counter 7

Same name and namespace in other branches
  1. 6.2 google_analytics_counter.module \_google_analytics_counter_path_filter()
  2. 6 google_analytics_counter.module \_google_analytics_counter_path_filter()
1 call to _google_analytics_counter_path_filter()
_google_analytics_counter_path_report in ./google_analytics_counter.module

File

./google_analytics_counter.module, line 519

Code

function _google_analytics_counter_path_filter($node_path = NULL) {
  $aliases = _google_analytics_counter_path_aliases($node_path);

  // Regular expressions may have max 128 characters -- see http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDataFeed.html#filters
  $filters = array();
  foreach ($aliases as $alias) {
    $filters[] = "ga:pagePath=~^/" . $alias . "([?#].*)?\$";
  }

  // The limit 128 characters applies only to regexp and 20110917 Vacilando tested that two long regexps will work fine even though together they exceed 128 characters.
  // Nevertheless, to play safe (what if the data feed URI is longer than some other limit with e.g. long pathauto aliases?) we do NOT implode with comma here but fetch results for each filter separately!

  /* $filters = implode(",",$filters); */

  /*
   // Okay, this is ridiculous.  Google Analytics regex filters
   // have a limit of 32 characters.  Therefore we can't simply
   // create one filter per pagePath.  Instead we are going too
   // do a "contains substring" match on the path, and then take
   // as many of the ending characters paired with ([?#].*)?$. If
   // this will all fit in one regex under 32 characters then so
   // be it.  Return a string if they all do, or an array if not.
   // 32 - 12 = 20 characters maximum for alias
   $under_filters = array();
   $over_filters = array();
   foreach ($aliases as $alias) {
   if (strlen($alias) <= 20) {
   $under_filters[] = 'pagePath=~^/' . $alias . '([?#].*)?$';
   } else {
   $over_filters[] = array(
   'pagePath=@ /' . $alias,
   // 32 - 10 = 22 characters
   'pagePath=~ ' . substr($alias, -22) . '([?#].*)?$'
   );
   }
   }

   // Add pipes and put together under and over filters.
   $filters = array();
   if ($under_filters) {
   $filters[] = implode(' || ', $under_filters);
   }
   foreach ($over_filters as $filter) {
   $filters[] = implode(' && ', $filter);
   }
  */
  return $filters;
}