SEOGuy
SEOGuy

Reputation: 81

Google Analytics API - Query specific URL stats

We're building an inhouse application, and I've been tasked with researching the Google Analytics API to see what limitations there are.

Currently, it would serve us perfectly but the one task it doesn't seem to allow would be to query specific URLs.

For example, currently in GA you can go to Behaviour > Site Content > All Pages, and run a search for a specific URL.

We would like to use this functionality in our inhouse app; primarily for sales representatives who are sitting in front of a client can pull up specific analytical stats for a URL such as pageviews, time on page etc.

Does anyone have any experience with the Google Analytics API? And for those that do, is this possible?

Upvotes: 2

Views: 2117

Answers (2)

Patrick.SE
Patrick.SE

Reputation: 4564

The google analytics API uses three concepts: dimensions, metrics and filters.

The dimension that is of interest to you is: ga:pagePath, which falls under the Page Tracking family. This in turn tells you which metrics you can use with this dimension.

Let's use ga:pageViews as the metric. All that is left now is to append a filter on the dimension:

&filters=ga:pagePath==2017 (raw string)
&filters=ga%3ApagePath%3D%3D2017 (encoded string)

For example,

https://www.googleapis.com/analytics/v3/data/ga?ids=XXX&start-date=30daysAgo&end-date=yesterday&metrics=ga%3Apageviews&dimensions=ga%3ApagePath&filters=ga%3ApagePath%3D%3D2017

Would effectively return the number of page views filtered against the selected page path dimension.

The query explorer is an effective tool to test out your requests manually. At this point, you can add any other dimension of interest, which will be filtered by the ga:pagePath.

Upvotes: 1

Philip Walton
Philip Walton

Reputation: 30441

You can do that with the Google Analytics Core Reporting API by specifying the filter query parameter.

The documentation has many examples of how to use filters and what the syntax looks like:
https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters

Upvotes: 0

Related Questions