过滤 Google Analytics API 页面路径以不显示更多子目录

filter Google Analytics API pagepath to not show further subdirectories

我想要列出个人简介主页的前十名,但不包括其他子目录。例如

/cr/johndoe
/cr/janesmith

但不是:

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

我已经从 filters=ga:pagePath==/cr/* 开始,但我不确定如何使用正则表达式来让它不再深入。

你可以使用这个:

^\/cr\/\w+$

DEMO

为了匹配 /cr/something 您可以使用以下过滤器:

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

或Url-编码版本:

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

正则表达式解释:

  • /cr/ - 按字面意思匹配字符序列
  • [^/]* - /
  • 以外的 0 个或多个字符
  • /? - 0 或 1 / 符号
  • $ - 匹配字符串的结尾。

如果 URL 以 /cr 开头,请添加 ^(字符串开头):

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

或Url编码:

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