Google Analytics Core API Breaks with ga:pagePath

I’m trying to work with Google Analytics Core API.

I am using their sample page, and if I just do this, it works:


return $analytics->data_ga->get(
       'ga:' . $profileId,
       '2008-01-01',
       'today',
       'ga:pageviews');

This, when applied to another function, gets all the pageviews for my entire site/property all-time.

But, I want pageviews for a specific pagePath, so I attempt to just add the dimension ga:pagePath, and the API stops functioning or times out. I try to add the full set of parameters…

function getResults($analytics, $profileId) {
    $optParams = array(
        'dimensions' => 'ga:pagePath',
        'filters' => 'ga:pagePath==/live-by-night/trailer',
        'max-results' => '1');

   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '2008-01-01',
       'today',
       'ga:pageviews',
       $optParams);
}

This breaks the response, and instead I get:

Uncaught exception ‘Google_Service_Exception’ with message
‘{“error”:{“errors”:[{“domain”:“global”,“reason”:“backendError”,“message”:“There
was a temporary error. Please try again
later.”}],“code”:503,“message”:“There was a temporary error. Please try
again later.”}}’

Not sure if it’s temporary, as I get temporary banned for the bad request happening too often.

Can’t figure out what I’m doing wrong.

All feedback appreciated.

Cheers!
Ryan

Does this page on Stackoverflow help at all? - http://stackoverflow.com/questions/16728093/google-analytics-api-query-a-specific-url

The samples there seem to have some additional parameters over yours, and some changes. I’ve never tried it myself and can’t test it.

Thanks for that link!

Let me see. In principle it should be the same thing, but let me see if doing exactly like this changes things.

Dang it. But that for some reason does not work. Here is what works, but only gets the Profile ID total visits:

return $analytics->data_ga->get(
       'ga:' . $profileId,
       '2008-01-01',
       'today',
       'ga:visits');

This works. Takes a few seconds, but returns a result.

Then I get confident and do this:

return $analytics->data_ga->get(
       'ga:' . $profileId,
       '2008-01-01',
       'today',
       'ga:visits',
        array(
        'filters' => 'ga:pagePath=@/sully-2016',
        'dimensions' => 'ga:pagePath',
        'metrics' => 'ga:pageviews',
        'sort' => '-ga:pageviews',
        'max-results' => '25'));
}

Which gives:

Fatal error: Uncaught exception ‘Google_Service_Exception’ with
message
‘{“error”:{“errors”:[{“domain”:“global”,“reason”:“backendError”,“message”:“There
was a temporary error. Please try again
later.”}],“code”:503,“message”:“There was a temporary error. Please try
again later.”}}’

Scratching my head

Actually,

If I remove the metrics and sort function it starts working. But I’ve discovered another issue.

I just want the total pageviews recorded by Analytics for a URL, so declare the date the site went live. Google hates this and the result takes forever to get, if it doesn’t error out.

Was trying to find just to ask for all-time total pageviews.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.