Take our developer survey. We want your feedback so we can learn how to improve Google Analytics, and make it an even better tool for you.

Experiments: patch

Requires authorization

Update an existing experiment. This method supports patch semantics. See an example.

In addition to the standard parameters, this method supports the parameters listed in the parameters table.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
accountId string Account ID of the experiment to update.
experimentId string Experiment ID of the experiment to update.
profileId string View (Profile) ID of the experiment to update.
webPropertyId string Web property ID of the experiment to update.

Authorization

This request requires authorization with at least one of the following scopes (read more about authentication and authorization).

Scope
https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.edit

Request body

In the request body, supply the relevant portions of a management.experiment resource, according to the rules of patch semantics, with the following properties:

Property name Value Description Notes
Required Properties
id string Experiment ID. Required for patch and update. Disallowed for create.
Optional Properties
description string Notes about this experiment. writable
editableInGaUi boolean If true, the end user will be able to edit the experiment via the Google Analytics user interface. writable
equalWeighting boolean Boolean specifying whether to distribute traffic evenly across all variations. If the value is False, content experiments follows the default behavior of adjusting traffic dynamically based on variation performance. Optional -- defaults to False. This field may not be changed for an experiment whose status is ENDED. writable
minimumExperimentLengthInDays integer An integer number in [3, 90]. Specifies the minimum length of the experiment. Can be changed for a running experiment. This field may not be changed for an experiment whose status is ENDED. writable
name string Experiment name. This field may not be changed for an experiment whose status is ENDED. This field is required when creating an experiment. writable
objectiveMetric string The metric that the experiment is optimizing. Valid values: "ga:goal(n)Completions", "ga:adsenseAdsClicks", "ga:adsenseAdsViewed", "ga:adsenseRevenue", "ga:bounces", "ga:pageviews", "ga:sessionDuration", "ga:transactions", "ga:transactionRevenue". This field is required if status is "RUNNING" and servingFramework is one of "REDIRECT" or "API". writable
optimizationType string Whether the objectiveMetric should be minimized or maximized. Possible values: "MAXIMUM", "MINIMUM". Optional--defaults to "MAXIMUM". Cannot be specified without objectiveMetric. Cannot be modified when status is "RUNNING" or "ENDED". writable
rewriteVariationUrlsAsOriginal boolean Boolean specifying whether variations URLS are rewritten to match those of the original. This field may not be changed for an experiment whose status is ENDED. writable
servingFramework string The framework used to serve the experiment variations and evaluate the results. One of:
  • REDIRECT: Google Analytics redirects traffic to different variation pages, reports the chosen variation and evaluates the results.
  • API: Google Analytics chooses and reports the variation to serve and evaluates the results; the caller is responsible for serving the selected variation.
  • EXTERNAL: The variations will be served externally and the chosen variation reported to Google Analytics. The caller is responsible for serving the selected variation and evaluating the results.
writable
status string Experiment status. Possible values: "DRAFT", "READY_TO_RUN", "RUNNING", "ENDED". Experiments can be created in the "DRAFT", "READY_TO_RUN" or "RUNNING" state. This field is required when creating an experiment. writable
trafficCoverage double A floating-point number between 0 and 1. Specifies the fraction of the traffic that participates in the experiment. Can be changed for a running experiment. This field may not be changed for an experiment whose status is ENDED. writable
variations[] list Array of variations. The first variation in the array is the original. The number of variations may not change once an experiment is in the RUNNING state. At least two variations are required before status can be set to RUNNING. writable
variations[].name string The name of the variation. This field is required when creating an experiment. This field may not be changed for an experiment whose status is ENDED. writable
variations[].status string Status of the variation. Possible values: "ACTIVE", "INACTIVE". INACTIVE variations are not served. This field may not be changed for an experiment whose status is ENDED. writable
variations[].url string The URL of the variation. This field may not be changed for an experiment whose status is RUNNING or ENDED. writable
winnerConfidenceLevel double A floating-point number between 0 and 1. Specifies the necessary confidence level to choose a winner. This field may not be changed for an experiment whose status is ENDED. writable

Response

If successful, this method returns a management.experiment resource in the response body.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library.

/*
 * 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

Uses the PHP client library.

/**
 * 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

Uses the Python client library.

# 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

Uses the JavaScript client library.

/*
 * 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. });
}