Containers: create

Richiede l'autorizzazione

Crea un container. Prova subito o guarda un esempio.

Richiesta

Richiesta HTTP

POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers

Parametri

Nome del parametro Valore Descrizione
Parametri del percorso
accountId string L'ID account GTM.

Autorizzazione

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

Ambito
https://www.googleapis.com/auth/tagmanager.edit.containers

Corpo della richiesta

Nel corpo della richiesta, fornisci una risorsa Containers con le seguenti proprietà:

Nome proprietà Valore Descrizione Note
Proprietà obbligatorie
name string Nome visualizzato del contenitore. scrivibile
timeZoneCountryId string ID paese contenitore. scrivibile
timeZoneId string ID fuso orario container. scrivibile
usageContext[] list Elenco dei contesti di utilizzo per il contenitore. I valori validi sono: web, android, ios. scrivibile
Proprietà facoltative
domainName[] list Elenco facoltativo di nomi di dominio associati al contenitore. scrivibile
enabledBuiltInVariable[] list Elenco delle variabili integrate attivate. I valori validi sono: pageUrl, pageHostname, pagePath, referrer, event, clickElement, clickClasses, clickId, clickTarget, clickUrl, clickText, formElement, formClasses, formId, formTarget, formUrl, formText, errorMessage, errorUrl, errorLine, newHistoryFragment, oldHistoryFragment, newHistoryState, oldHistoryState, historySource, containerVersion, debugMode, randomNumber, containerId. scrivibile
notes string Note contenitore. scrivibile

Risposta

In caso di esito positivo, questo metodo restituisce una risorsa Containers 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 tagmanager service object.
 */

/*
 * This request creates a new container for the authorized user.
 */

// Construct the container object.
Container container = new Container();
container.setName("Example Container");
container.setTimeZoneCountryId("US");
container.setTimeZoneId("America/Los_Angeles");
container.setUsageContext(Arrays.asList("web", "android", "ios"));

try {
  Container response = tagmanager.accounts().
      containers().create("12345", container).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}


/*
 * The results of the create method are stored in the response object.
 * The following code shows how to access the created Id and Fingerprint.
 */
System.out.println("Container Id = " + response.getContainerId());
System.out.println("Container Fingerprint" + response.getFingerprint());

Python

Utilizza la libreria client Python.

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

# This request creates a new container.
try:
  response = tagmanager.accounts().containers().create(
      accountId='123456',
      body={
          'name': 'Example Container',
          'timeZoneCountryId': 'US',
          'timeZoneId': 'America/Los_Angeles',
          'usageContext': ['web', 'android']
      }
  ).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))

# The results of the create method are stored in the response object.
# The following code shows how to access the created id and fingerprint.
print response.get('containerId')
print response.get('fingerprint')

Prova.

Utilizza Explorer API di seguito per chiamare questo metodo sui dati in tempo reale e visualizzare la risposta.