LCHCAPITALHUMAIN / gapi-google-analytics-php-interface

Automatically exported from code.google.com/p/gapi-google-analytics-php-interface
0 stars 0 forks source link

API version 2 - goal names #27

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The API has been updated to version two.  (Changelog:
http://code.google.com/apis/analytics/docs/gdata/changelog.html)

I have been working to incorporate some of these changes and wanted to
share them here to save extra work for anyone else.  My immediate need was
for accessing the goal names, so I have added the following code to the
accountObjectMapper function:

      $properties['goals'] = array();
      foreach ($entry->children('http://schemas.google.com/ga/2009')->goal
as $goal)
      {
        if ($goal->attributes()->active=='true')
        {
          $properties['goals'][intval($goal->attributes()->number)] =
strval($goal->attributes()->name);
        }
      }

Obviously, this is for my specific use-case, but this could be quickly
modified to load in all of the goal data.

To access the new features, I also had to add "GData-Version: 2" to the
headers in the HTTP request.

Original issue reported on code.google.com by jasonw...@gmail.com on 16 Dec 2009 at 1:09

GoogleCodeExporter commented 9 years ago
I've been attempting similar things, though it's the dynamic filtering that I 
wanted 
to use instead of the goals.

So here's my hack to get things working - debugging welcome! (though it seems 
to work 
in the simple cases I've used it for so far, mostly traffic source segmentation 
etc.)

Suggest this and the addition above be combined, QA'd and added to next release 
of 
GAPI?

Note: should probably add v2 to the HTTP header, not a param as I've done. 
Note: used the processFilter function to duplicate functionality. Will this 
cause any 
issues?

######################################

Modify the requestReportData function to show as follows:

public function requestReportData($report_id, $dimensions, $metrics, 
$sort_metric=null, $filter=null, $start_date=null, $end_date=null, 
$start_index=1, 
$max_results=100, $segments=null) 
  {
    $parameters = array('ids'=>'ga:' . $report_id);

    /* segmentation params
     * adam marshall dec 2009
     * specifiy either :        
     * $segments Integer  id of segment to use
     * $segments String   dynamic segment e.g. 'medium==referral'  [ use the same 
form as filters, see example.filter.php ]
     * **********************************/

    if ($segments !== null) 
    {
            if (!is_int($segments))
             {
              $parameters['segment'] = 'dynamic::'.$this-
>processFilter($segments);
             }
            else
             {
              $parameters['segment'] = 'gaid::'.$segments;
             }
             $parameters['v'] =2;
    }        

    /* end segmentation params */

and then the function continues from the "if ($dimensions !== null)" line 
onwards...

Original comment by logan...@googlemail.com on 22 Dec 2009 at 4:18

GoogleCodeExporter commented 9 years ago
logantod. You, sir, win, and I shall be replacing my slightly different 
variation of segment implementation with 
your cleaner one. Thank you.

Original comment by wraithof...@gmail.com on 25 Jan 2010 at 1:55

GoogleCodeExporter commented 9 years ago
Jason, your fix worked like a charm! It's made my flexible "show the clients 
their GA
data in our extranet" project much schnazzier!

Original comment by g...@bacs.org on 22 Feb 2010 at 9:36