问题
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