如何分组google sourceMedium并统计相同的推介

时间:2017-01-23 04:58:38

标签: php google-analytics google-analytics-api

我使用Gapi.class.php从谷歌分析中获取数据。

这是我的PHP代码

 $ga->requestReportData(xxxxx,array('sourceMedium','month','year'),array('sessions'), $sort_metric=array('month'), $filter=null, $start_date=$fromDate, $end_date=$toDate, $start_index=1, $max_results=10000);

我喜欢这个



[dimensions:gapiReportEntry:private] => Array
                (
                    [sourceMedium] => l.facebook.com / referral
                    [month] => 06
                    [year] => 2016
                )
   [dimensions:gapiReportEntry:private] => Array
                (
                    [sourceMedium] => mail.google.com / referral
                    [month] => 06
                    [year] => 2016
                )
     [dimensions:gapiReportEntry:private] => Array
                (
                    [sourceMedium] => mbasic.facebook.com / referral
                    [month] => 06
                    [year] => 2016
                )




我想知道如何将它们分组并计算,

Example 
        source   Count
         fb    =  100
        google =  50

更新

enter image description here

1 个答案:

答案 0 :(得分:1)

只需从查询中删除与日期相关的维度,例如monthyear,即可获得汇总数字。

所以你的查询看起来应该是这样的,以获得预期的输出。

$ga->requestReportData(xxxxx,array('sourceMedium','pagePath'), array('pageviews'), $sort_metric=array('pageviews'), $filter=null, $start_date=$fromDate, $end_date=$toDate, $start_index=1, $max_results=10000);

请查看以下链接以供参考。

Google Analytics Dimension and Metrics

Creating Reports

Advanced Use Cases of Creating Reports