需要授权
创建一个新的非抽样报告。 查看示例。
请求
HTTP 请求
POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/unsampledReports
参数
参数名称 | 值 | 说明 |
---|---|---|
路径参数 | ||
accountId |
string |
要为其创建非抽样报告的帐号 ID。 |
profileId |
string |
要为其创建非抽样报告的数据视图(配置文件)ID。 |
webPropertyId |
string |
要为其创建非抽样报告的网络媒体资源 ID。 |
授权
此请求至少需要获得以下任一范围的授权(详细了解身份验证和授权)。
范围 |
---|
https://www.googleapis.com/auth/analytics |
https://www.googleapis.com/auth/analytics.edit |
请求正文
在请求正文中提供一个具有以下属性的 management.unsampledReport 资源:
属性名称 | 值 | 说明 | 备注 |
---|---|---|---|
必需属性 | |||
end-date |
string |
非抽样报告的结束日期。 | 可写入 |
metrics |
string |
用于非抽样报告的指标。 | 可写入 |
start-date |
string |
非抽样报告的开始日期。 | 可写入 |
title |
string |
非抽样报告的标题。 | 可写入 |
可选属性 | |||
dimensions |
string |
用于非抽样报告的维度。 | 可写入 |
filters |
string |
用于非抽样报告的过滤器。 | 可写入 |
segment |
string |
用于非抽样报告的细分。 | 可写入 |
响应
如果成功,此方法将在响应正文中返回一个 management.unsampledReport 资源。
示例
备注:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 Java 客户端库。
/* * Note: This code assumes you have an authorized Analytics service object. * See the Unsampled Reports Developer Guide for details. */ /* * This example creates a new unsampled report. */ UnsampledReport body = new UnsampledReport(); body.setTitle("A test report"); body.setStartDate("2013-01-01"); body.setEndDate("2013-03-31"); body.setMetrics("ga:pageviews,ga:bounces"); body.setDimensions("ga:browser"); body.setFilters("ga:bounces>=100"); body.setSegment("gaid:-1"); try { analytics.management().unsampledReports().insert("123456", "UA-123456-1", "7654321", body ).execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); }
PHP
使用 PHP 客户端库。
/** * Note: This code assumes you have an authorized Analytics service object. * See the Unsampled Reports Developer Guide for details. */ /** * This request creates a new Unsampled Report. */ // Construct an unsampled report object. $unsampledReport = new Google_Service_Analytics_UnsampledReport(); $unsampledReport->setTitle('A test report'); $unsampledReport['start-date'] = '2013-01-01'; $unsampledReport['end-date'] = '2013-03-31'; $unsampledReport->setMetrics('ga:pageviews,ga:bounces'); $unsampledReport->setDimensions('ga:browser'); $unsampledReport->setFilters('ga:bounces>=100'); $unsampledReport->setSegment('gaid:-1'); try { $analytics->management_unsampledReports->insert('123456', 'UA-123456-1', '7654321', $unsampledReport); } catch (apiServiceException $e) { print 'There was an Analytics API service error ' . $e->getCode() . ':' . $e->getMessage(); } catch (apiException $e) { print 'There was a general API error ' . $e->getCode() . ':' . $e->getMessage(); }
Python
使用 Python 客户端库。
# Note: This code assumes you have an authorized Analytics service object. # See the Unsampled Reports Developer Guide for details. # This request creates an new unsampled report. try: reports = analytics.management().unsampledReports().insert( accountId='123456', webPropertyId='UA-123456-1', profileId='7654321', body={ 'title': 'A test Report', 'start-date': '2013-01-01', 'end-date': '2013-01-31', 'metrics': 'ga:pageviews,ga:bounces', 'dimensions': 'ga:browser', 'filters': 'ga:bounces>=100', 'segment': 'gaid::-1' } ).execute() except TypeError, error: # Handle errors in constructing a query. print 'There was an error in constructing your query : %s' % error except HttpError, error: # Handle API errors. print ('There was an API error : %s : %s' % (error.resp.status, error.resp.reason))
JavaScript
使用 JavaScript 客户端库。
/* * Note: This code assumes you have an authorized Analytics client object. * See the Unsampled Reports Developer Guide for details. */ /* * This request creates an new unsampled report. */ function insertView() { var request = gapi.client.analytics.management.unsampledReports.insert( { 'accountId': '123456', 'webPropertyId': 'UA-123456-1', 'profileId': '7654321', 'resource': { 'title': 'A test Report', 'start-date': '2013-01-01', 'end-date': '2013-01-31', 'metrics': 'ga:pageviews,ga:bounces', 'dimensions': 'ga:browser', 'filters': 'ga:bounces>=100', 'segment': 'gaid::-1' } }); request.execute(function (response) { /* Handle the response. */ }); }