Custom Metrics: update

Richiede l'autorizzazione

Aggiorna una metrica personalizzata esistente. Prova subito o visualizza un esempio.

Richiesta

Richiesta HTTP

PUT https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customMetrics/customMetricId

Parametri

Nome del parametro Valore Descrizione
Parametri del percorso
accountId string ID account per la metrica personalizzata da aggiornare.
customMetricId string ID metrica personalizzata da aggiornare per la metrica personalizzata.
webPropertyId string ID proprietà web per la metrica personalizzata da aggiornare.
Parametri di query facoltativi

Autorizzazione

Questa richiesta richiede l'autorizzazione con il seguente ambito (scopri di più su autenticazione e autorizzazione).

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

Corpo della richiesta

Nel corpo della richiesta, fornisci una risorsa management.customMetric.

Risposta

Se l'esito è positivo, questo metodo restituisce una risorsa management.customMetric nel corpo della risposta.

Esempi

Nota: gli esempi di codice disponibili per questo metodo non rappresentano tutti i linguaggi di programmazione supportati (consulta la pagina relativa alle librerie client per un elenco dei linguaggi supportati).

Java

Utilizza la libreria client Java.

/*
 * Note: This code assumes you have an authorized Analytics service object.
 */

/*
 * This request updates an existing custom metric.
 */

// Construct the body of the request and set its properties.
CustomMetric body = new CustomMetric();
body.setName("Level Completions");
body.setScope("HIT");
body.setType("INTEGER");
body.setActive(true);

try {
  analytics.management().customMetrics()
      .update("123456", "UA-123456-1", "ga:metric2", body).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

Python

Utilizza la libreria client Python.

# Note: This code assumes you have an authorized Analytics service object.

# This request updates an existing custom metric.
try:
  analytics.management().customMetrics().update(
      accountId='123456',
      webPropertyId='UA-123456-1',
      customMetricId='ga:metric2',
      body={
          'name': 'Level Completions',
          'scope': 'HIT',
          'type': 'INTEGER',
          'active': True
      }
  ).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))

Prova.

Utilizza Explorer API di seguito per chiamare questo metodo sui dati in tempo reale e visualizzare la risposta. In alternativa, prova a utilizzare Explorer in modalità autonoma.