Task for notes and discussion of 1.x roadmap.

Comments

hass’s picture

+

raspberryman’s picture

I've written a new, smaller class to replace gapi. It uses OAuth, caches results, produces more useful and public objects, and supports users with multiple domains verified with Google.

Check it out: http://drupalcode.org/project/google_analytics_api.git/commitdiff/d50f5e8

raspberryman’s picture

Here is a basic sample report using the new library. This code is just to get the juices flowing :)

    /* Pageviews over the past 2 weeks */
    $params = array(
      'dimensions' => array('date'),
      'metrics' => array('pageviews'),
      'sort_metric' => array('date'),
      'start_date' => strtotime('-16 days')
    );
    
    /* Refresh => TRUE for debugging purposes only */
    $GAFeed = google_analytics_api_report_data($params, array('refresh' => TRUE));

    /* In general, metrics will be $data, and dimensions will be x labels. */
    foreach ($GAFeed->results as $row) {
      $data[] = $row['pageviews'];
      $x_labels[] = date('M d', strtotime($row['date']));
    }
    
    $chart = array(
      '#chart_id' => 'pageviews_2weeks',
      '#title' => chart_title(t('Pageviews over the past two weeks'), '027AC6', 15),
      '#data' => $data,
      '#type' => CHART_TYPE_LINE,
      '#size' => chart_size(800, 300),
      '#adjust_resolution' => TRUE,
      '#data_colors' => array('027AC6'),
      '#chart_fill' => chart_fill('bg', 'EDF5FA'),
      '#line_styles' => array(chart_line_style(3, 10, 0)),
      '#shape_markers' => array(chart_shape_marker(0, -1, 'o', 6, '027AC6')),
      '#grid_lines' => chart_grid_lines(0, 20, 1, 3),
    );
    $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][0][] = chart_mixed_axis_range_label(0, max($data));
    foreach ($x_labels as $label) {
      $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label($label);
    }
    $output = chart_render($chart);
    return $output;
JGonzalez’s picture

How are you implementing this code? Even when trying to implement this, ignoring the chart items and doing a print_r($data) I'm receiving errors, mainly ones like this:
Warning: Invalid argument supplied for foreach() in eval() (line 14 of /srv/www/mysite.com/public_html/includes/common.inc(1694) : eval()'d code).

When taking a step back and printing the results of the GA feed object, I get the following:

       [data] => GDatainvalidParameterValueInvalid value for sort parameter: date
            [protocol] => HTTP/1.0
            [status_message] => Bad Request
            [headers] => Array
                (
                    [Content-Type] => application/vnd.google.gdata.error+xml
                    [Date] => Sun, 17 Apr 2011 21:52:07 GMT
                    [Expires] => Sun, 17 Apr 2011 21:52:07 GMT
                    [Cache-Control] => private, max-age=0
                    [X-Content-Type-Options] => nosniff
                    [X-Frame-Options] => SAMEORIGIN
                    [X-XSS-Protection] => 1; mode=block
                    [Server] => GSE
                )

            [error] => Bad Request
            [code] => 400
        )

Sorry to inundate this thread - I can go ahead and make a new post if you'd like

raspberryman’s picture

No worries - things have changed a bit since that post above. Namely, we use Google's own naming scheme rather than our own. So instead of "date", you'd use "ga:date". We're trying to reduce the abstraction. To learn more about the fields available to you, visit: http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html

Development is reaching our v1.0 objectives, and near release, I'll write some documentation and samples to produce a variety of reports.

JGonzalez’s picture

Yea I was able come up with some nice widgets and reports after I figured out the use of the 'ga:' scheme. Hopefully I'll be able to post some snippets and samples in the future as well.

raspberryman’s picture

Yes, please do! In fact, if you figure out a cool report or funky trick while creating your widgets, please message me or post here, and I'll add your idea to the new documentation. I'm excited to see the smart things people do with this code.

grendzy’s picture

Raspberryman and I discussed the remaining issues today:

grendzy:

  • better handling of the path block when there are 0 visits
  • remove the unused "administer GA reports" permission
  • finish per-path report design

raspberryman:

  • change MENU_DEFAULT_LOCAL_TASK to MENU_NORMAL_ITEM for API settings
  • add a 1 month cache option
  • rename the "reports" folder to the more conventional "google_analytics_reports"
  • Add advanced help
grendzy’s picture

Project: Google Analytics API » Google Analytics Reports
Version: 6.x-1.x-dev »
Plazik’s picture

Version: » 7.x-1.x-dev
Category: Task » Plan
Issue summary: View changes
Status: Active » Closed (won't fix)

7.x-1.x is unsupported. Please upgrade to 7.x-3.x.