需要授權
建立新的未取樣報表。 參閱範例。
要求
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
/* * 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. */ }); }