简体   繁体   English

将Google AnalyticsAPI与PHP结合使用

[英]Using Google Analytics API with PHP

I am using the Google Analytics PHP class to get data from Google Analytics. 我正在使用Google Analytics PHP类从Google Analytics获取数据。 http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation

I would like to get a report of "Bounce Rate" For "Top Contnet". 我想得到一份关于“Top Contnet”的“跳出率”报告。

The thing is I am not familiar with the terminology. 问题是我对术语不熟悉。

When I am trying to get a "content" report or "topcontent" or "top_content" it says that there in no such metric. 当我试图获得“内容”报告或“topcontent”或“top_content”时,它表示没有这样的指标。 I simply don't know the right expressions. 我根本就不知道正确的表达方式。

Does anyone know where can I find a list of all expressions? 有谁知道在哪里可以找到所有表达式的列表? metrics & dimensions? 指标和维度?

Thanks. 谢谢。

Top content isn't a metric, it's just a list of the pages on your site with the highest number of page views. 热门内容不是指标,它只是您网站上页面浏览次数最多的网页列表。

The metric you're looking for is 'entranceBounceRate' and the dimension is 'pagePath'. 您要查找的指标是'entranceBounceRate',维度是'pagePath'。 You want to get the bounce rate for the top X most visited pages on your site, so you'll want to limit your results and sort the results by '-pageviews' (pageviews descending). 您希望获得网站上访问量最大的X页面的跳出率,因此您需要限制结果并按“-pageviews”(网页浏览量下降)对结果进行排序。

If you want to get the bounce rate for the top 10 most viewed pages on your site, your query should look like this: 如果您想获得网站上查看次数最多的10个网页的跳出率,您的查询应如下所示:

$ga = new gapi('email@yourdomain.com','password');
$ga->requestReportData(145141242,array('pagePath'),array('entranceBounceRate','pageviews'),array('-visits'),null,null,null,10);

The Google Analytics Export API has a data feed query explorer that should help you out considerably when using GAPI: http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html Google Analytics导出API具有数据Feed查询资源管理器,可在使用GAPI时大大帮助您: http//code.google.com/apis/analytics/docs/gdata/gdataExplorer.html

Also, here's a list of all available dimensions and metrics you can pull from the API: http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html 此外,以下是您可以从API中提取的所有可用维度和指标的列表: http//code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html

Definitely read over the GAPI documentation: http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation 绝对阅读GAPI文档: http//code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation

If you would like to get the global Bounce Rate for the last 30days (by default), here is how. 如果您想获得过去30天的全球跳出率(默认情况下),请按以下步骤操作。 Very simple once you know it. 一旦你知道它就很简单。

//Check Bounce Rate for the last 30 days
$ga = new gapi(ga_email, ga_password);
$ga->requestReportData(145141242, NULL ,array('bounces', 'visits'));
$data = round(($ga->getBounces() / $ga->getVisits()) * 100) . "%";

Note that the GAPI has a bug, they mention the dimension parameter is optional (2nd parameter) but it's not. 请注意,GAPI有一个bug,他们提到维度参数是可选的(第二个参数),但事实并非如此。 You have to open the gapi.class.php file and patch line 128 with this: 您必须使用以下命令打开gapi.class.php文件和补丁行128:

  //Patch bug to make 2nd parameter optional
  if( !empty($dimensions) ) {
      $parameters['dimensions'] = 'ga:'.$dimensions;
  } else {
      $parameters['dimensions'] = '';
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM