2010-11-22 79 views
27

我的网站有可通过如下所示的网址访问的用户个人资料:www.domain.com/profile/123/...。我想向用户显示其个人资料的页面查看统计信息,但需要能够使用通配符。Google AnalyticsAPI:按URI过滤?

例如,此工作原理:

filters=ga:pagePath==/profile/123/ 

的问题是,有遵循/profile/123/潜在的其他URI段。我想做这样的事情(不起作用):

filters=ga:pagePath==/profile/123/* 

建议?

回答

32

使用Dimension Filters中的'包含正则表达式匹配'操作符(〜)。

filters=ga:pagePath=~/profile/123/* 
+0

你的链接不好...我们该怎么办〜/ * /视图/ *? – VinnyG 2012-04-25 16:56:39

+3

@yahelc,#〜是正确的,但*并不意味着你在正则表达式中的想法。实际上,在这种情况下,filters = ga:pagePath =〜/ profile/123 /就足够了。 – s6mike 2012-10-11 05:55:04

+0

我在我的查询中保留了原来的双精度'==',并且对它为什么不工作感到困惑......实质上:'filters = ga:pagePath ==〜/ profile/123/*'> ___ < – 2014-08-20 15:49:06

0

为我工作。

  
    require('gapi.class.php'); 
    $ga = new gapi('[email protected]','google_analytics_password'); 
    $filter = 'ga:pagePath==/home.php'; 

    //first parameter is your Google Analytics profile id 

    /* How to find Google Analytics Profile ID 
    http://stackoverflow.com/questions/4119610/get-google-analytics-id-from-the-code-embed/4120625#4120625 
    */ 
    $ga->requestReportData(0000000,array('pagePath'),array('pageViews','UniquePageviews'), '-pageViews', $filter); 

    foreach($ga->getResults() as $result) 
    { 
     echo $result->getPageviews(); 
     echo $result->getUniquePageviews(); 
     echo $result->getPagePath(); 
    } 
    ?> 
+0

GAPI类(谷歌分析PHP接口) http://code.google.com/p/gapi-google-analytics-php-interface/ – Tag 2011-03-16 13:48:27

+0

如何查找Google Analytics配置文件ID http://stackoverflow.com/questions/4119610 /让 - 谷歌 - 分析-ID-来自该代码嵌入/ 4120625#4120625 – Tag 2011-03-16 14:01:47

4

这将工作:

filters=ga:pagePath=~/profile/123/ 

要做到/*/view/*(按@ VinnyG的评论),这应该工作:

filters=ga:pagePath=~/[^/]+/view/ 

我假设你想匹配一个(并且只有一个)/view/之前的目录。