通过API提取Google Analytics多渠道路径数据 [英] Pulling Google Analytics Multi Channel Funnel data via API

查看:96
本文介绍了通过API提取Google Analytics多渠道路径数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Google AnalyticsAPI获取多渠道渠道报告,并收到以下错误消息:

无效值'mcf:source 。值必须匹配以下正则表达式:'(ga:。+)?'



这是我使用的代码, &安培;指标来自ga:...家族,但出于某种原因,它不会让我得到mcf:报告。

  $ analytics =新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()));

尝试{
$ 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 +)([AZ])/ U','\\ \\2',str_replace('ga:','',$ header-> name)));
printf('%s',$ headerName);
print',';
}

打印\\\
;

foreach($ results->行为$ row){
foreach($ row as $ cell){
printf('%s',$ cell);
print',';
}
打印\\\
;



$ div $解析方案

我想说的是因为您正在使用 $ analytics-> data_ga-> get()而不是 $ analytics- > data_mcf-> get()(多渠道数据有它自己的API)。


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";
    }
} 

解决方案

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).

这篇关于通过API提取Google Analytics多渠道路径数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆