Ian
Ian

Reputation: 519

filter Google Analytics API pagepath to not show further subdirectories

I'm looking to do a top ten list of the main pages of a bio but not the additional subdirectories. E.g.

/cr/johndoe
/cr/janesmith

but NOT:

/cr/johndoe/news
/cr/janesmith/dvds
/cr/santaclaus/galleries/1
etc.

I've started with filters=ga:pagePath==/cr/* but I'm not sure how to do the regex to get it to not go any deeper.

Upvotes: 1

Views: 1701

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627110

In order to match the /cr/something you can use the following filters:

filters=ga:pagePath=~/cr/[^/]*/?$

Or Url-encoded version:

filters=ga:pagePath%3D~%2Fcr%2F%5B%5E%2F%5D*%2F%3F%24

REGEX EXPLANATION:

  • /cr/ - matches the sequence of the characters literally
  • [^/]* - 0 or more characters other than /
  • /? - 0 or 1 / symbol
  • $ - matches the end of string.

If the URL starts with /cr, add ^ (start of string):

filters=ga:pagePath=~^/cr/[^/]*/?$

or Url-encoded:

filters=ga:pagePath%3D~%5E%2Fcr%2F%5B%5E%2F%5D*%2F%3F%24

Upvotes: 1

Pruthvi Raj
Pruthvi Raj

Reputation: 3036

You can use this:

^\/cr\/\w+$

DEMO

Upvotes: 1

Related Questions