Requires authorization
Update an existing experiment. See an example.
In addition to the standard parameters, this method supports the parameters listed in the parameters table.
Request
HTTP request
PUT 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 a management.experiment resource with the following properties:
Property name | Value | Description | Notes |
---|---|---|---|
Required Properties | |||
id |
string |
Experiment ID. Required for patch and update. Disallowed for create. | |
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 |
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 |
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 |
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 |
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:
|
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[].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 updates an existing experiment with new variations. Variations variationA = new Variations(); variationA.setName("Home Alpha"); variationA.setUrl("homeA.html"); Variations variationB = new Variations(); variationB.setName("Home Beta"); 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 Update with the updated experiment. analytics.management().experiments().update("123456", "UA-123456-1", "7654321", "122333444455555", 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 updates 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 update method with the updated experiment. $analytics->management_experiments->update('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 updates an existing experiment with a new name, # and new variations. try: analytics.management().experiments().update( accountId='123456', webPropertyId='UA-123456-1', profileId='7654321', experimentId='ABCDEFG123456abcdefg', body={ 'name': 'Updated Test Title', 'status': 'DRAFT', 'variations': [ { 'name': 'Checkout Page', 'url': 'checkout.html' }, { 'name': 'Proposed Checkout Page', 'url': 'newCheckout.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 updates an existing experiment. */ function updateExperiment() { var request = gapi.client.analytics.management.experiments.update( { '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. }); }