DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • What Is React? A Complete Guide
  • Writing a Vector Database in a Week in Rust
  • Introduction To Git
  • Authorization: Get It Done Right, Get It Done Early

Trending

  • What Is React? A Complete Guide
  • Writing a Vector Database in a Week in Rust
  • Introduction To Git
  • Authorization: Get It Done Right, Get It Done Early
  1. DZone
  2. Data Engineering
  3. Data
  4. Retrieving Data from Google Analytics API using PHP

Retrieving Data from Google Analytics API using PHP

Lorna Mitchell user avatar by
Lorna Mitchell
·
Dec. 09, 10 · News
Like (0)
Save
Tweet
Share
7.69K Views

Join the DZone community and get the full member experience.

Join For Free
Recently I started playing with the google analytics API, looking at ways to bring analytics onto dashboards and generate simple reports from the data in there. Very shortly after I started to look at the API, I had working data retrieval, so I thought I'd share my experiences (and code!).
I am using OAuth for authentication, and I blogged about using Google and OAuth previously so feel free to pop over there to find out more about that. I used the pecl_oauth extension to make all the requests to analytics, but even for another technology choice, the concepts apply so keep reading :)

Analytics Parameters


The data format for analytics is fairly comprehensive and easy to understand - see their data feed reference document for a clear outline of the parameters that can be passed and what format they can take. I am using the ids parameter (which is the tableId I showed retrieval of in the earlier blog post), the date parameters, metrics, dimensions and sort - so my code looks something like this, with the parameters set in $query_data.
        $oauth = new OAuth($oauth_consumer_key, $oauth_consumer_secret);
$oauth->setToken($token, $token_secret);

$oauth->fetch('https://www.google.com/analytics/feeds/data', $query_data);
$result = $oauth->getLastResponse();

Combining Parameters


The biggest problem I'm encountering with the analytics is understanding how to combine the dimension and metrics parameters to get useful data. It is pretty easy to report on visitors by day/week/month, over a given date range, but getting more meaningful and useful statistics is still a work in progress! There is some documentation, which is exhaustive, but doesn't link the available data to the sorts of questions users actually want to ask. If anyone has any suggestions on good combinations to use, I'd absolutely love to hear them - leave me a comment and I'll post again if/when have some better data patterns!
API Data (computing) Analytics PHP Google (verb)

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • What Is React? A Complete Guide
  • Writing a Vector Database in a Week in Rust
  • Introduction To Git
  • Authorization: Get It Done Right, Get It Done Early

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: