使用GAPI返回包含视图百分比的页面列表 - php

有人知道我如何使用GAPI从我的Google Analytics(分析)帐户返回以下信息吗?

参考方案

您需要使用pagePath维度和pageviews指标。尝试如下操作:

<?php
require 'gapi.class.php';

$gaEmail = '[email protected]';
$gaPassword = 'your password';
$profileId = 'your profile id';

$dimensions = array('pagePath');
$metrics = array('pageviews');
$sortMetric=null;
$filter=null;
$startDate='2011-02-01';
$endDate='2011-02-28';
$startIndex=1;
$maxResults=10000;

$ga = new gapi($gaEmail, $gaPassword);

$ga->requestReportData($profileId, $dimensions, $metrics, $sortMetric, $filter, $startDate, $endDate, $startIndex, $maxResults);

$totalPageviews = $ga->getPageviews();

foreach ($ga->getResults() as $result) {
    $pageviews = $result->getPageviews();
    $percentPageviews = round(($result->getPageviews()/$totalPageviews)*100,2);
    print "$result:$pageviews:$percentPageviews\n";
}

?>

Analytics API:自动身份验证 - php

我正在尝试使用Google Analytics(分析)Reporting API构建仪表板,以便为我公司的客户创建报告。问题是我需要使用cronjob创建报告,但这需要身份验证。我尝试了以下方法:1.使用API for web applications:我设法完成了这项工作,但是OAuth2流程通过将我重定向到Google登录页面,迫使我向Google进行身…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

PHP-将日期插入日期时间字段 - php

我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数