the only reason that i'm using GAR atm is to sync my core stats with google's stats so that i can run Boost without firing up a Drupal bootstrap with the Boost AJAX stats block.

i'm looking into using http://drupal.org/project/google_analytics_counter but it seems to rely on a function called google_analytics_reports_path_report removed that i found in a git repository for this project, but isn't in the alpha1 version of GAR.

it means i'm getting fatal errors when i try to enable GAC, so i'm considering dropping the function as-is back into my local copy of GAR just to get things working, but i am curious as to why it was removed in the first place.

this is the code that i found, i have no idea if it is even the "right" version for what GAC expects but it's what i'm going to trial:

 /*
 * Function to collect together data for different aliases.
 */
 function google_analytics_reports_path_report($request, $path = NULL, $group_by = 'date') {
 $data = array();

 foreach (_google_analytics_reports_path_filter($path) as $filter) {
 $request['filter'] = $filter;
 $GAFeed = google_analytics_api_report_data($request);
 if (!empty($GAFeed->results)) {
 $data = array_merge($data, $GAFeed->results);
 }
 else {
 return FALSE;
 }
 }

 // Add up all the statistics for different paths.
 $rows = array();
 foreach ($data as $item) {
 $dimensions = $item->getDimensions();
 if (is_array($group_by)) {
 $group_name = '';
 foreach ($group_by as $group_by_item) {
 $group_name .= $dimensions[$group_by_item];
 }
 }
 else {
 $group_name = $dimensions[$group_by];
 }
 if (isset($rows[$group_name])) {
 foreach ($item->getMetrics() as $key => $value) {
 $rows[$group_name][$key] += $value;
 }
 }
 else {
 $rows[$group_name] = $item->getMetrics();
 }
 }
 return $rows;
 }

Comments

grendzy’s picture

Status: Active » Fixed

I've posted some details about the refractor at http://drupal.org/node/1144994#comment-4431586
In short, google_analytics_api is a pre-release module. Once we reach 1.0 (very soon) we'll be more cautious about API changes. Please do fetch data from google_analytics_api_report_data() - most other functions should be considered private and may change again in the future.

On a side note, the google_analytics_reports module now includes a small page statistics block. Here is a screenshot:
http://drupal.org/files/issues/GA1_0.png

thedavidmeister’s picture

i saw the statistics block, and i'm displaying it to admin users, but i specifically need to import GA stats into core stats as afaik there's no real views integration provided by GAR and i sort a lot of my Views by pageviews, but i'm also running Boost which mangles my stats.

running the Boost AJAX stats block was a fair performance hit, so i'd rather sync my stats on cron runs.

dstol’s picture

@thedavidmeister, it seems as though you have a similar use case to me. See my comments in http://drupal.org/node/760592#comment-4375758 and my module http://drupal.org/project/ga_importer

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

thedavidmeister’s picture

@dstol, i checked out ga_importer but it works by batch processing stats for nodes on chron runs, whereas GAC imports stats on pageviews, with a minimum time between recounts.

i have around 10-20k nodes, updating about 2-300 of those each day through feeds and manually, some of which are viewed thousands of times, some maybe 10 times, so there's no way that ga_importer won't go stale on me thanks to google's limit on API calls.

GAC however takes a more scalable approach, but the API changes from GAR seems to have caused it some troubles :(

bmango’s picture

@thedavidmeister Did you manage to get the GAC block to work using the function google_analytics_reports_path_report?

thedavidmeister’s picture

unfortunately i had to switch priorities to something that didn't require rewriting a whole contrib module just to tweak my stats display. My use case isn't that urgent..

i'm not that familiar with the GA API anyway, so it would probably take me a little while to get my head around that before i could really fix anything.

i'll let you know if i come back to this before anyone else gets the chance to look into it.

bmango’s picture

Thanks, I'm trying to find a way to display some custom stats, and was looking for a solution where I wouldn't have to to delve into the GA API. It seems like Google Analytics Importer may be an easier approach.

thedavidmeister’s picture

as i mentioned above, GAI may be an easier approach, but it hits the Google server with requests for every node in your site on cron runs (last time i checked), whereas GAC only uses the Google API when you view a page, using a "freshness" timer that can be set by admin to stop many requests in a short period for popular nodes.

Google caps your requests at something like 10k a day, so if you have 10's of thousands of nodes, some of which are much less popular than others, GAI is less scalable than GAC and is pretty much guaranteed to show stale data on medium-large sites.

unfortunately, the site where i thought i needed GAC changed its caching setup, and is now generating more favourable stats from the core stat counter than what is reported by Google Analytics, so i doubt that i'll have any time "on the clock" to investigate the issues with GAC :P

incidently, this is not really the issue queue to be discussing problems with GAC, or comparing GAC and GAI.

comment #1 posted by Grendzy pretty much answers everything asked in my OP; the function was removed because the developers of GAR considered it private, and they've decided that it isn't their problem if we were relying on it for something - at least until a stable version 1.0 of the API is released.