Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3362450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:16:32+00:00 2026-05-18T03:16:32+00:00

I’m using GAPI to try and create simple reports from our Google Analytics data.

  • 0

I’m using GAPI to try and create simple reports from our Google Analytics data.
My internal customer would like to see an overview with 2 fields per page: pageviews and unique visitors.
I have the pageviews part working, but I cannot get the unique visitors part to work.
This is my current code. The filter would be a parameter they can change, but is hardcoded for now:

require 'gapi.class.php';

$ga = new gapi(ga_email,ga_password);

$filter = 'pagepath =~ ^/home$';
$ga->requestReportData(ga_profile_id,
                        array('pagepath'),
                        array('pageviews'),
                       'pageviews',
                       $filter,
                       '2010-10-01',
                       '2010-10-31');

and then some code to show the results which is not really relevant here.
As said, that works, but if I add ‘visitors’ to the metric like this:

$ga->requestReportData(ga_profile_id,
                       array('pagepath'),
                       array('pageviews','visitors'),
                       '-pageviews',
                       $filter,
                      '2010-10-01',
                      '2010-10-31');

Then I get this error:

PHP Fatal error:  Uncaught exception 'Exception' with message 'GAPI: Failed to request report data. Error: "Illegal combination of dimensions and metrics"' in gapi.class.php:218

Stack trace:
#0example.filter.php(24): gapi->requestReportData('30296235', Array, Array, '-pageviews', 'pagepath =~ ^/h...', '2010-10-01', '2010-10-31')
#1 {main}
thrown in gapi.class.php on line 218
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:16:33+00:00Added an answer on May 18, 2026 at 3:16 am

    The Google Analytics API restricts what combinations it can show you. Specifically, visitors (not to be confused with visits) is heavily restricted as to what metrics it can be used with. visitors and hour are the two most heavily restricted metrics and dimensions you can query in Google Analytics. So, the above combination you tried is invalid, and Google refuses to compute it. Just switch it to visits, and it’ll work.

    Notice on this valid combinations page, almost all of the metrics restrict visitors.

    The reason for this is likely that visitors is much more computationally expensive, occasionally impossible to compute, and, to be honest, not particularly useful. visitor is aggregate of visits, but constrained to a particular cookie set, whereas a visit is just one particular session for a visitor. It’s also less useful, since visitors does not map 1:1 to people. For example, I access StackOverflow from Safari, Chrome, and Firefox on my home and work computers, as well as from my iPhone. SO sees me as 7 visitors! It’s not a useful way of tracking users. Visit, by being more limited in what it offers, provides a better view.

    Also, since being a visitor spans multiple sessions, you can’t quite have a pagePath for them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.