Primary and secondary dimension query

565 views
Skip to first unread message

Rob Denton

unread,
Jun 30, 2014, 9:10:45 PM6/30/14
to google-analytics...@googlegroups.com
Hi all, code at bottom.

I am trying to return data with pageTitle as the primary dimension. Not sure if that actually makes since or not...

Long story short, posts on my website may have multiple URLs. But each post has the same title. So I want to use pageTitle as a unique id to query on that may return multiple pagePaths. By doing this I hope to add pageviews on multiple pagePaths to one total pageview count by pageTitle.

This theory works if I query *only* the pageTitle. But if I query both the pageTitle and pagePath (no matter the order) it returns pageviews based on pagePath.

Short of making two queries and merging data, is there any way to query based on pageTitle and also get the pagePath? Is there a work around to return the absolute page URL as as to avoid pagePath altogether?

Thanks, Rob

def get_results(service):
  return service.data().ga().get(
      ids=get_secret("tableID"),
      start_date=yesterday,
      end_date=yesterday,
      metrics='ga:pageviews',
      dimensions='ga:pageTitle,ga:pagePath',
      sort='-ga:pageviews',
      max_results='5' ).execute()

Aaron Toledo

unread,
Jun 30, 2014, 9:37:34 PM6/30/14
to google-analytics...@googlegroups.com
Hi Rob - You should be able to get the data your'e looking for with 1 query. Try sorting by your dimensions as well.....sort='ga:pageTitle,ga:pagePath,-ga:pageviews'

Rob Denton

unread,
Jul 1, 2014, 12:13:19 PM7/1/14
to google-analytics...@googlegroups.com
Hi Aaron,

Thanks for your response. When I sort='ga:pageTitle,ga:pagePath,-ga:page views’ the data is alphabetized by pageTitle and I’m trying to find the most visited pages. 

So then I tried sort=‘-ga:pagviews,ga:pageTitle’ and sort=‘ga:page views,ga:pageTitle,ga:pagePath’ and they still return the count by pagePath as the primary dimension.

I suppose I could get the whole table and do Python sorting but that feels like a bit overkill since Google offers the max_results and sorting...

Rob Denton

Digital Developer-Producer





On Jun 30, 2014, at 6:37 PM, Aaron Toledo <aaron...@gmail.com> wrote:

Hi Rob - You should be able to get the data your'e looking for with 1 query. Try sorting by your dimensions as well.....sort='ga:pageTitle,ga:pagePath,-ga:pageviews'

--
You received this message because you are subscribed to a topic in the Google Groups "Google Analytics Reporting API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-analytics-data-export-api/_JaEwBYQ0vY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-analytics-data-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

chris@shufflepoint

unread,
Jul 3, 2014, 9:52:10 AM7/3/14
to google-analytics...@googlegroups.com
You'll have to do two queries if you need to get metrics which can't be aggregated by client-side summation. But if you just need pageviews, the write one query and then do your aggregation client-side.

Rob Denton

unread,
Jul 3, 2014, 11:59:35 AM7/3/14
to google-analytics...@googlegroups.com
Ok, thanks Chris

Micky Hulse

unread,
Jul 16, 2014, 7:35:46 PM7/16/14
to google-analytics...@googlegroups.com
Hi Chris,


On Thursday, July 3, 2014 6:52:10 AM UTC-7, chris@shufflepoint wrote:
> You'll have to do two queries if you need to get metrics which can't be aggregated by client-side summation.
> But if you just need pageviews, the write one query and then do your aggregation client-side.

I'm having a hard time following your suggestion. If it's not too much trouble, could you post example code?

Micky Hulse

unread,
Jul 16, 2014, 7:37:32 PM7/16/14
to google-analytics...@googlegroups.com
On Monday, June 30, 2014 6:10:45 PM UTC-7, Rob Denton wrote:
This theory works if I query *only* the pageTitle. But if I query both the pageTitle and pagePath (no matter the order) it returns pageviews based on pagePath.

 Can anyone confirm if this is the expected behavior of GA, or is this a bug? If a bug, is there a place to report API bugs?

chris@shufflepoint

unread,
Jul 17, 2014, 9:52:02 AM7/17/14
to google-analytics...@googlegroups.com
It will return pageviews based upon the distinct pageTitle/pagePath pairs. Order of dimensions doesn't matter.

chris@shufflepoint

unread,
Jul 17, 2014, 9:59:42 AM7/17/14
to google-analytics...@googlegroups.com
Very coarse pseudocode:

get pageviews by pageTitle
for each pageTitle
    get pageviews by pagePath
    merge those results in with first results

As an aside (and potential GA API feature request) the Sitecatalyst API has the above semantics - you specify an order and count for each dimension.

Micky Hulse

unread,
Jul 17, 2014, 12:29:26 PM7/17/14
to google-analytics...@googlegroups.com
Thanks for replies and pseudocode Chris, I really appreciate it. :)
Reply all
Reply to author
Forward
0 new messages