如何分组 google sourceMedium 并计算相同的推荐

How to group google sourceMedium and count same referral

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

这是我的 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

请。

已更新

只需从查询中删除与日期相关的维度,即 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