OnlineExperimentationClient.CreateOrUpdateMetricAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| CreateOrUpdateMetricAsync(String, RequestContent, RequestConditions, RequestContext) |
[Protocol Method] Creates or updates an experiment metric.
|
| CreateOrUpdateMetricAsync(String, ExperimentMetric, Nullable<ETag>, Nullable<ETag>, CancellationToken) |
Creates or update an experiment metric asynchronously. |
CreateOrUpdateMetricAsync(String, RequestContent, RequestConditions, RequestContext)
[Protocol Method] Creates or updates an experiment metric.
- This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
public virtual System.Threading.Tasks.Task<Azure.Response> CreateOrUpdateMetricAsync(string experimentMetricId, Azure.Core.RequestContent content, Azure.RequestConditions requestConditions = default, Azure.RequestContext context = default);
abstract member CreateOrUpdateMetricAsync : string * Azure.Core.RequestContent * Azure.RequestConditions * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateOrUpdateMetricAsync : string * Azure.Core.RequestContent * Azure.RequestConditions * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateOrUpdateMetricAsync (experimentMetricId As String, content As RequestContent, Optional requestConditions As RequestConditions = Nothing, Optional context As RequestContext = Nothing) As Task(Of Response)
Parameters
- experimentMetricId
- String
Identifier for this experiment metric. Must start with a lowercase letter and contain only lowercase letters, numbers, and underscores.
- content
- RequestContent
The content to send as the body of the request.
- requestConditions
- RequestConditions
The content to send as the request conditions of the request.
- context
- RequestContext
The request context, which can override default behaviors of the client pipeline on a per-call basis.
Returns
The response returned from the service.
Exceptions
experimentMetricId or content is null.
experimentMetricId is an empty string, and was expected to be non-empty.
Service returned a non-success status code.
Examples
This sample shows how to call CreateOrUpdateMetricAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
OnlineExperimentationClient client = new OnlineExperimentationClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
displayName = "Average revenue per purchase [USD]",
description = "The average revenue per purchase transaction in USD. Refund transactions are excluded from this metric. The total revenue might increase while this metric decreases if the number of purchases increases.",
lifecycle = "Active",
categories = new object[]
{
"Monetization"
},
desiredDirection = "Increase",
definition = new
{
type = "Average",
value = new
{
eventName = "Transaction",
eventProperty = "Revenue",
filter = "Revenue > 0",
},
},
});
Response response = await client.CreateOrUpdateMetricAsync("avg_purchase_revenue", content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("lifecycle").ToString());
Console.WriteLine(result.GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("categories")[0].ToString());
Console.WriteLine(result.GetProperty("desiredDirection").ToString());
Console.WriteLine(result.GetProperty("definition").GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("eTag").ToString());
Console.WriteLine(result.GetProperty("lastModifiedAt").ToString());
This sample shows how to call CreateOrUpdateMetricAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
OnlineExperimentationClient client = new OnlineExperimentationClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
displayName = "Number of purchases (credit card)",
description = "The number of purchase transactions made with credit card. Refund transactions are excluded from this metric.",
lifecycle = "Active",
categories = new object[]
{
"Monetization"
},
desiredDirection = "Increase",
definition = new Dictionary<string, object>
{
["type"] = "EventCount",
["event"] = new
{
eventName = "Transaction",
filter = "Revenue > 0 and ['payment.method'] == 'credit_card'",
}
},
});
Response response = await client.CreateOrUpdateMetricAsync("events_purchase_creditcard", content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("lifecycle").ToString());
Console.WriteLine(result.GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("categories")[0].ToString());
Console.WriteLine(result.GetProperty("desiredDirection").ToString());
Console.WriteLine(result.GetProperty("definition").GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("eTag").ToString());
Console.WriteLine(result.GetProperty("lastModifiedAt").ToString());
This sample shows how to call CreateOrUpdateMetricAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
OnlineExperimentationClient client = new OnlineExperimentationClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
displayName = "Refund rate",
description = "The percentage of transactions that are refunds. This metric is calculated as the number of refund transactions divided by the total number of transactions.",
lifecycle = "Active",
categories = new object[]
{
"Monetization"
},
desiredDirection = "Neutral",
definition = new Dictionary<string, object>
{
["type"] = "EventRate",
["event"] = new
{
eventName = "Transaction",
},
["rateCondition"] = "Revenue < 0"
},
});
Response response = await client.CreateOrUpdateMetricAsync("rate_refund", content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("lifecycle").ToString());
Console.WriteLine(result.GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("categories")[0].ToString());
Console.WriteLine(result.GetProperty("desiredDirection").ToString());
Console.WriteLine(result.GetProperty("definition").GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("eTag").ToString());
Console.WriteLine(result.GetProperty("lastModifiedAt").ToString());
This sample shows how to call CreateOrUpdateMetricAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
OnlineExperimentationClient client = new OnlineExperimentationClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
displayName = "95th percentile of page load time [ms]",
description = "The 95th percentile of the page load time for all pages. Measured in milliseconds. Review page-specific metric results to identify pages that need optimization.",
lifecycle = "Active",
categories = new object[]
{
"Performance",
"Important"
},
desiredDirection = "Decrease",
definition = new
{
type = "Percentile",
value = new
{
eventName = "PageLoad",
eventProperty = "LoadTime_ms",
},
percentile = 95,
},
});
Response response = await client.CreateOrUpdateMetricAsync("p95_page_load_time", content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("lifecycle").ToString());
Console.WriteLine(result.GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("categories")[0].ToString());
Console.WriteLine(result.GetProperty("desiredDirection").ToString());
Console.WriteLine(result.GetProperty("definition").GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("eTag").ToString());
Console.WriteLine(result.GetProperty("lastModifiedAt").ToString());
This sample shows how to call CreateOrUpdateMetricAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
OnlineExperimentationClient client = new OnlineExperimentationClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
displayName = "Total revenue [USD]",
description = "The total revenue in USD. Refund transactions contribute negatively to this metric.",
lifecycle = "Active",
categories = new object[]
{
"Monetization",
"Important"
},
desiredDirection = "Increase",
definition = new
{
type = "Sum",
value = new
{
eventName = "Transaction",
eventProperty = "Revenue",
},
},
});
Response response = await client.CreateOrUpdateMetricAsync("sum_revenue", content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("lifecycle").ToString());
Console.WriteLine(result.GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("categories")[0].ToString());
Console.WriteLine(result.GetProperty("desiredDirection").ToString());
Console.WriteLine(result.GetProperty("definition").GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("eTag").ToString());
Console.WriteLine(result.GetProperty("lastModifiedAt").ToString());
This sample shows how to call CreateOrUpdateMetricAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
OnlineExperimentationClient client = new OnlineExperimentationClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
displayName = "Users with purchase",
description = "The number of users who have made at least one purchase transaction. Refund transactions are excluded from this metric. As the analysis period grows, this metric begins to saturate as users making multiple purchases no longer contribute.",
lifecycle = "Active",
categories = new object[]
{
"Monetization"
},
desiredDirection = "Increase",
definition = new Dictionary<string, object>
{
["type"] = "UserCount",
["event"] = new
{
eventName = "Transaction",
filter = "Revenue > 0",
}
},
});
Response response = await client.CreateOrUpdateMetricAsync("users_purchase", content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("lifecycle").ToString());
Console.WriteLine(result.GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("categories")[0].ToString());
Console.WriteLine(result.GetProperty("desiredDirection").ToString());
Console.WriteLine(result.GetProperty("definition").GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("eTag").ToString());
Console.WriteLine(result.GetProperty("lastModifiedAt").ToString());
This sample shows how to call CreateOrUpdateMetricAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
OnlineExperimentationClient client = new OnlineExperimentationClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
displayName = "Subscription ad conversion rate",
description = "The percentage of users who saw an advertisement for a subscription promotion and then later successfully subscribed. This metric is calculated as the number of users who successfully subscribed after seeing the advert divided by the total number of users who saw the advert. Users who saw multiple adverts or subscribed multiple times are counted only once. Users who saw the advert before the analysis period starts are excluded from this metric.",
lifecycle = "Active",
categories = new object[]
{
"Monetization"
},
desiredDirection = "Increase",
definition = new
{
type = "UserRate",
startEvent = new
{
eventName = "AdView",
filter = "Source == 'subscription_promo'",
},
endEvent = new
{
eventName = "Subscribe",
filter = "Status == 'Success'",
},
},
});
Response response = await client.CreateOrUpdateMetricAsync("rate_subscription_ad", content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("lifecycle").ToString());
Console.WriteLine(result.GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("categories")[0].ToString());
Console.WriteLine(result.GetProperty("desiredDirection").ToString());
Console.WriteLine(result.GetProperty("definition").GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("eTag").ToString());
Console.WriteLine(result.GetProperty("lastModifiedAt").ToString());
Applies to
CreateOrUpdateMetricAsync(String, ExperimentMetric, Nullable<ETag>, Nullable<ETag>, CancellationToken)
Creates or update an experiment metric asynchronously.
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.OnlineExperimentation.ExperimentMetric>> CreateOrUpdateMetricAsync(string experimentMetricId, Azure.Analytics.OnlineExperimentation.ExperimentMetric metric, Azure.ETag? ifMatch = default, Azure.ETag? ifNoneMatch = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateOrUpdateMetricAsync : string * Azure.Analytics.OnlineExperimentation.ExperimentMetric * Nullable<Azure.ETag> * Nullable<Azure.ETag> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.OnlineExperimentation.ExperimentMetric>>
override this.CreateOrUpdateMetricAsync : string * Azure.Analytics.OnlineExperimentation.ExperimentMetric * Nullable<Azure.ETag> * Nullable<Azure.ETag> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.OnlineExperimentation.ExperimentMetric>>
Public Overridable Function CreateOrUpdateMetricAsync (experimentMetricId As String, metric As ExperimentMetric, Optional ifMatch As Nullable(Of ETag) = Nothing, Optional ifNoneMatch As Nullable(Of ETag) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of ExperimentMetric))
Parameters
- experimentMetricId
- String
Identifier for this experiment metric. Must start with a lowercase letter and contain only lowercase letters, numbers, and underscores.
- metric
- ExperimentMetric
A ExperimentMetric object that describes the metric.
- cancellationToken
- CancellationToken
The token to check for cancellation.
Returns
An awaitable task.
Exceptions
Thrown when experimentMetricId or metric parameter is null.
Thrown when experimentMetricId is empty.