Containers: create

Requiere autorización

Crea un contenedor. Pruébalo ahora y ve un ejemplo.

Solicitud

Solicitud HTTP

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

Parámetros

Nombre del parámetro Valor Descripción
Parámetros de ruta de acceso
accountId string El ID de la cuenta de GTM.

Autorización

Esta solicitud requiere autorización con el siguiente alcance (obtén más información sobre la autenticación y la autorización).

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

Cuerpo de la solicitud

En el cuerpo de la solicitud, proporciona un recurso de contenedores con las siguientes propiedades:

Nombre de la propiedad Valor Descripción Notas
Propiedades obligatorias
name string Nombre visible del contenedor. admite escritura
timeZoneCountryId string ID del país del contenedor. admite escritura
timeZoneId string ID de zona horaria del contenedor. admite escritura
usageContext[] list Lista de contextos de uso para el contenedor. Entre los valores válidos, se incluyen web, android, ios. admite escritura
Propiedades opcionales
domainName[] list Lista opcional de nombres de dominio asociados con el contenedor. admite escritura
enabledBuiltInVariable[] list Lista de variables integradas habilitadas. Entre los valores válidos, se incluyen 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. admite escritura
notes string Notas del contenedor. admite escritura

Respuesta

Si se ejecuta de forma correcta, este método muestra un recurso de contenedores en el cuerpo de la respuesta.

Ejemplos

Nota: Los ejemplos de código disponibles para este método no representan todos los lenguajes de programación admitidos (consulta la página de bibliotecas cliente para consultar una lista de lenguajes admitidos).

Java

Usa la biblioteca cliente de 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

Usa la biblioteca cliente de 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')

Pruébala

Usa el Explorador de APIs que aparece a continuación para llamar a este método con datos en tiempo real y ver la respuesta.