PHP上的Google Analytics(分析)API - php

但是我仍然遇到这个问题:

致命错误:/ home / sample / www / test / google-api-php-client-master / src / Google / Service / Resource中未捕获的异常“ Google_Exception”,消息“(获取)缺少必需的参数:'ids”。 php:163堆栈跟踪:#0 /home/sample/www/test/google-api-php-client-master/src/Google/Service/Analytics.php(2107):Google_Service_Resource-> call('get',Array ,'Google_Service _...')#1 /home/sample/www/test/google-api-php-client-master/practicein.php(57):Google_Service_Analytics_DataRealtime_Resource-> get('ga:****** **','ga:pageviews','2015-03-07','2015-04-04')#2 /home/sample/www/test/index.php(34):require_once('/ home / lanforest ...')#3 {main}在第163行的/home/sample/www/test/google-api-php-client-master/src/Google/Service/Resource.php中抛出

我认为这里的代码是错误的。

$results = $analytics->data_realtime->get(
    $analytics_view_id,
    'ga:pageviews',//**I did correct this.**
    '2015-03-07',
    '2015-04-04'
);

//**I think these goes wrong**
$totals = $results->getTotalsForAllResults();
$array = array("activeUsers" => $totals["rt:activeUsers"]);

我只想查看页面浏览量。我可以编码什么?

我认为我获得了活跃的用户价值。但是,它仍然是警告。
这是什么错误?

Warning: Cannot modify header information - headers already sent by (output started at /home/sample/www/test/index.php:16) in /home/sample/www/test/google-api-php-client-master/practicein.php on line 76

Warning: Cannot modify header information - headers already sent by (output started at /home/sample/www/test/index.php:16) in /home/sample/www/test/google-api-php-client-master/practicein.php on line 77

{"activeUsers":"0"}//this is the result.

参考方案

从您的starcktrace我看到:

#1 .../practicein.php(66): Google_Service_Analytics_DataRealtime_Resource->get('ga:*******', '2015-03-07', '2015-04-04', 'ga:pageviews'

您用错误的参数调用get方法:第一个是您的用户名,第二个必须是指标,然后您可以传递opt参数。

检查get中的src/Google/Service/Analytics.php方法文档:

/**
 * Returns real time data for a view (profile). (realtime.get)
 *
 * @param string $ids Unique table ID for retrieving real time data. Table ID is
 * of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
 * @param string $metrics A comma-separated list of real time metrics. E.g.,
 * 'rt:activeUsers'. At least one metric must be specified.
 * @param array $optParams Optional parameters.
 *
 * @opt_param int max-results The maximum number of entries to include in this
 * feed.
 * @opt_param string sort A comma-separated list of dimensions or metrics that
 * determine the sort order for real time data.
 * @opt_param string dimensions A comma-separated list of real time dimensions.
 * E.g., 'rt:medium,rt:city'.
 * @opt_param string filters A comma-separated list of dimension or metric
 * filters to be applied to real time data.
 * @return Google_Service_Analytics_RealtimeData
 */
 public function get($ids, $metrics, $optParams = array())

Google Analytics(分析)报告中的分页 - php

在这里,我正在获取下一个和上一个URL,但是当尝试使用该URL访问下一页时,由于网址= https://www.googleapis.com/analytics/v3/data/ga?ids=ga:85914642&dimensions=ga:pagePath,ga:date&metrics=ga:pageviews,ga:uniquePag…

Google Analytics PHP API:找不到目标 - php

在我公司,我们决定使用Google Analytics(分析)来获取有关访问者,进入渠道等的一些有趣指标...当访问者提交联系表单时,我创建了一个“触发”的目标,一切工作正常,我什至创建了一个细分来预览使用该表单的人与其他人之间的区别。使用PHP API,我有自己的仪表板表,其中逐个列出了每个会话的一些详细信息,其中包括:每个访问的URL约会时间如果来自Ad…

使用php将交易推送到Google Analytics(分析) - php

我需要将离线交易推送到Google Analytics(分析)。我正在考虑创建一个php脚本来查询电子商务数据库,以查看从后端创建的最近一小时内进行的交易。确定了这些交易(以及订单项/ SKU)。如何使用PHP将数据推送到Google Analytics(分析)? 参考方案 您需要通过measurement protocol。没有客户端库可以帮助您在PHP中…

Google Analytics(分析),维度和指标-如何? - php

我终于弄清楚了我如何连接到Google Analytics(分析),现在可以访问数据了。我正在使用google-api-php-client。我可以通过 return $analytics->data_ga->get( 'ga:' . $profileId, '7daysAgo', 'today&…

Google Analytics API-不完整的报告批次 - php

因此,我们有一个有效的API,可以在特定日期范围内获取报告。最近,我们尝试获取行数达到40,000个结果的报告。我们从API得到响应,并且能够提取前1000行。现在的问题是分页。查询设置为每批检索1,000行,因此总共40批(基于40,000行)。根据analytics api pagination,从api响应中检索nextPageToken并将其设置为下…