Experiments: patch

需要授權

更新現有實驗。這個方法支援修補程式語意。 參閱範例

除了標準參數以外,這個方法也支援參數表格中列出的參數。

要求

HTTP 要求

PATCH https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/experiments/experimentId

參數

參數名稱 說明
路徑參數
accountId string 要更新的實驗帳戶 ID。
experimentId string 要更新的實驗 ID。
profileId string 要更新的實驗資料檢視 (設定檔) ID。
webPropertyId string 要更新的實驗網站資源 ID。

授權

這項要求需要至少下列其中一個範圍的授權 (進一步瞭解驗證和授權)。

範圍
https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.edit

要求主體

在要求內文中,請根據修補語義的規則提供具有以下屬性的 management.experiment 資源相關部分:

資源名稱 說明 附註
必要屬性
id string 實驗 ID。修補與更新的必要項目。不允許建立。
選用屬性
description string 關於這項實驗的附註。 可寫入
editableInGaUi boolean 若為 true,使用者可以透過 Google Analytics (分析) 使用者介面修改實驗。 可寫入
equalWeighting boolean 布林值,可指定是否將流量平均分配到所有變化版本。如果值為 False,內容實驗會採用預設行為,根據變化版本成效動態調整流量。選用 -- 預設為 False。如果實驗狀態為「ENDED」,則無法更改這個欄位。 可寫入
minimumExperimentLengthInDays integer 以 [3, 90] 表示的整數。指定實驗的最短長度。執行中的實驗可以變更。如果實驗狀態為「ENDED」,則無法更改這個欄位。 可寫入
name string 實驗名稱。如果實驗狀態為「ENDED」,則無法更改這個欄位。這是建立實驗時的必填欄位。 可寫入
objectiveMetric string 實驗要最佳化的指標。有效值:「ga:goal(n)Completes」、「ga:adsenseAdsClicks」、「ga:adsenseAdsViewed」、「ga:adsenseRevenue」、「ga:bounces」、「ga:pageviews」、「ga:sessionDuration」、「ga:transactions」、「ga:transactionRevenue」。如果狀態為「RUNNING」,而放送 Framework 為「REDIRECT」或「API」,則此為必填欄位。 可寫入
optimizationType string 是否應最小化或最大化 goalMetric。可能的值:「MAXIMUM」、「MINIMUM」。選用:預設為「MAXIMUM」。如果不使用 goalMetric,就無法指定目標指標。狀態為「RUNNING」或「ENDED」時無法修改。 可寫入
rewriteVariationUrlsAsOriginal boolean 布林值,用於指定是否要重新編寫變化網址以符合原始版本的網址。如果實驗狀態為「ENDED」,則無法更改這個欄位。 可寫入
servingFramework string 用於放送實驗變化版本和評估結果的架構。以下其中之一:
  • 重新導向:Google Analytics (分析) 會將流量重新導向至不同的變化網頁,然後記錄所選變化頁並評估成效。
  • API:Google Analytics (分析) 會選擇並回報變化版本,以放送並評估結果;呼叫端必須負責放送所選變化版本。
  • 外部: 系統會向外部提供變化版本,並將所選變化版本回報給 Google Analytics (分析)。呼叫端負責放送所選變化版本並評估成效。
可寫入
status string 實驗狀態。可能的值:「DRAFT」、「READY_TO_RUN」、「RUNNING」、「ENDED」。實驗可建立為「DRAFT」、「READY_TO_RUN」或「RUNNING」狀態。這是建立實驗時的必填欄位。 可寫入
trafficCoverage double 介於 0 和 1 之間的浮點數。指定參與實驗的流量比例。執行中的實驗可以變更。如果實驗狀態為「ENDED」,則無法更改這個欄位。 可寫入
variations[] list 變化版本的陣列。陣列中的第一個變體為原始版本。實驗進入「執行中」狀態後,變化版本數量不得變動。必須先提供至少兩種變化版本,狀態才能設為「執行中」。 可寫入
variations[].name string 變化版本的名稱。這是建立實驗時的必填欄位。如果實驗狀態為「ENDED」,則無法更改這個欄位。 可寫入
variations[].status string 變化形式的狀態。可能的值:「ACTIVE」、「INACTIVE」。系統不會放送「有效」的變化版本。如果實驗狀態為「ENDED」,則無法更改這個欄位。 可寫入
variations[].url string 變化版本的網址。如果實驗狀態為「執行中」或「ENDED」,即無法變更這個欄位。 可寫入
winnerConfidenceLevel double 介於 0 和 1 之間的浮點數。指定用來選擇勝出組合所需的信賴水準。如果實驗狀態為「ENDED」,則無法更改這個欄位。 可寫入

回應

如果成功,這個方法會在回應主體中傳回 management.experiment 資源

示例

注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面

Java

使用 Java 用戶端程式庫

/*
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Experiments Developer Guide for details.
 */

// This example patches an existing experiment with new variations.
Variations variationA = new Variations();
variationA.setName("Home A");
variationA.setUrl("homeA.html");
Variations variationB = new Variations();
variationB.setName("Home B");
variationB.setUrl("homeB.html");
List<Variations> variations = Arrays.asList(variationA, variationB);

try {
  // First get an existing Experiment.
  Experiment body = analytics.management().experiments().get("123456",
      "UA-123456-1", "7654321", "122333444455555").execute();

  // Set the new variations.
  body.setVariations(variations);

  // Call Patch with the updated experiment.
  analytics.management().experiments().patch("123456", "UA-123456-1",
      "7654321", "12233344455555", 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 Experiments Developer Guide for details.
 */

/**
 * This request patches an existing experiment.
 */

// Construct the first variation.
$variationA = new Google_Service_Analytics_ExperimentVariations();
$variationA->setName('VariationA');
$variationA->setUrl('index.html');

// Construct the second variation.
$variationB = new Google_Service_Analytics_ExperimentVariations();
$variationB->setName('VariationB');
$variationB->setUrl('indexB.html');

try {
  // Get an existing Experiment.
  $experiment = $analytics->management_experiments->get('123456',
      'UA-123456-1', '7654321', '122333444455555');

  // Set the new variations.
  $experiment->setVariations(array($variationA, $variationB));

  // Call the patch method with the updated experiment.
  $analytics->management_experiments->patch('123456', 'UA-123456-1',
      '7654321', '122333444455555', $experiment);
} 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 Experiments Developer Guide for details.

# This request patches an existing experiment with a new name,
# and new variations.
try:
  analytics.management().experiments().patch(
      accountId='123456',
      webPropertyId='UA-123456-1',
      profileId='7654321',
      experimentId='ABCDEFG123456abcdefg',
      body={
          'name': 'Landing Page Test April',
          'variations': [
              {
                  'name': 'First Variation',
                  'url': 'index.html'
              },
              {
                  'name': 'Proposed Change',
                  'url': 'indexB.html'
              }
          ]
      }
  ).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 Experiments Developer Guide for details.
 */

/*
 * This request patches an existing experiment.
 */
function patchExperiment() {
  var request = gapi.client.analytics.management.experiments.patch(
    {
      'accountId': '123456',
      'webPropertyId': 'UA-123456-1',
      'profileId': '7654321',
      'experimentId': '122333444455555',
      'resource': {
        'name': 'Landing Page Test',
        'status': 'DRAFT',
        'variations': [
          {
            'name': 'VariationA',
            'url': 'index.html'
          },
          {
            'name': 'VariationB',
            'url': 'indexB.html'
          }
        ]
      }
    });
  request.execute(function (response) { // Handle the response. });
}