Is there any way to get the subpages with the largest number of views using Google Analytics's API?
-
18-03-2021 - |
Question
I'd like to see the pages with the largest number of post views that start with the "posts" slug: http://www.example.com/my-page/ should be ignored when counting, but http://www.example.com/posts/my-page/ should be included.
I'm not sure how to query the api to achieve this result.
Solution
Add a filter to the api query:
filters=ga:pagePath=~(/posts/)
You can test it out using the Data Feed Query Explorer using the following values in these fields:
dimensions: ga:pagePath
metrics: ga:pageviews
filters: ga:pagePath=~(/posts/)
See also filter operators in the filters section for more information and to note that the forward slash /
is not a reserved character so it can be used in your filter for matching. The backslash \
is reserved.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow