Integrate Google Analytics Api to fetch Page views count

09 / Feb / 2016 by Aman Mishra 0 comments

My use case was to show count of Page Views and Unique Page Views using Google analytics. Though there is already enough documentation provided with detailed explanation, it takes time to understand where to get required parameters to call those APIs, due to nested structure of Analytics account.

We can refer here to get detailed idea on Hierarchy of accounts, users, properties, and views for Google Analytics

To fetch Page views and Unique Page views count it’s a Profile Id that we need to know, not a Analytics account Id.

Below are required api url with scenarios and purpose it is for:

Scenario – A single Google Account can have more than Analytics account

Api :
Purpose : To fetch all Analytics accounts associated with a particular Google Account
Reference :

Scenario – A single Analytics account can have more than one Webproperty

Api :
Purpose : To fetch all web properties associated with a specific Analytics account.
Reference :

Scenario – A single Webproperty can have more than one Profiles

Api :
Purpose : To fetch all Profiles associated under a webproperty
Reference :

Once we have desired profile id, we can use below api to fetch Page views and visitors count.

Api :{profileId}&start-date={yyyy-mm- dd}&end-date={yyyy-mm-dd}&metrics=ga:pageviews,ga:uniquePageviews – Reference

Hope it helps 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *