Pulling Google Analytics Multi Channel Funnel data via API

只谈情不闲聊 提交于 2019-12-20 03:26:17

问题


I am trying to pull the multi-channel funnel reports from the Google Analytics API and am getting the following error:

Invalid value 'mcf:source'. Values must match the following regular expression: '(ga:.+)?'

Here is the code I am using, it works fine when the dimensions & metrics are from the ga:... family, but for some reason it won't let me pull mcf: reports.

$analytics = new Google_Service_Analytics($client);
$analytics_id   = 'ga:XXXXXXXX';
$lastWeek       = date('Y-m-d', strtotime('-26 day', time()));
$today          = date('Y-m-d', strtotime('-26 day', time()));

try {
    $optParams = array();
    $optParams['dimensions'] = "mcf:source";
    #$optParams['sort'] = "";
    $optParams['max-results'] = "10000";
    $metrics = 'mcf:totalConversions';
    $results = $analytics->data_ga->get($analytics_id,
                       $lastWeek,
                       $today,$metrics,$optParams);

    $rows = $results->getRows();
    foreach ($results->columnHeaders as $header) {
        $headerName = ucwords(preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', str_replace('ga:', '', $header->name)));
        printf('%s', $headerName);
        print ',';
    }

    print "\n";

    foreach ($results->rows as $row) {
        foreach ($row as $cell) {
            printf('%s', $cell);
            print ',';
        }
        print "\n";
    }
} 

回答1:


From the top of my head I'd say it's because your are using $analytics->data_ga->get() instead of $analytics->data_mcf->get() (Multichannel data has it's own API).



来源:https://stackoverflow.com/questions/31597137/pulling-google-analytics-multi-channel-funnel-data-via-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!