Containers: create

Wymaga autoryzacji

Tworzy kontener. Wypróbuj lub zobacz przykład.

Prośba

Żądanie HTTP

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

Parametry

Nazwa parametru Wartość Opis
Parametry ścieżki
accountId string Identyfikator konta Menedżera tagów Google.

Upoważnienie

To żądanie wymaga autoryzacji z tym zakresem (więcej informacji o uwierzytelnianiu i autoryzacji).

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

Treść żądania

W treści żądania podaj zasób kontenerów z tymi właściwościami:

nazwa usługi, Wartość Opis Uwagi
Właściwości wymagane
name string Wyświetlana nazwa kontenera. z możliwością zapisu
timeZoneCountryId string Identyfikator kraju kontenera. z możliwością zapisu
timeZoneId string Identyfikator strefy czasowej kontenera. z możliwością zapisu
usageContext[] list Lista kontekstów użycia kontenera. Prawidłowe wartości to: web, android, ios. z możliwością zapisu
Właściwości opcjonalne
domainName[] list Opcjonalna lista nazw domen powiązanych z kontenerem. z możliwością zapisu
enabledBuiltInVariable[] list Lista włączonych zmiennych wbudowanych. Prawidłowe wartości to: 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. z możliwością zapisu
notes string Notatki do kontenera. z możliwością zapisu

Odpowiedź

Jeśli operacja się uda, metoda zwróci zasób kontenerów w treści odpowiedzi.

Przykłady

Uwaga: dostępne dla tej metody przykłady kodu nie odzwierciedlają wszystkich obsługiwanych języków programowania. Listę obsługiwanych języków znajdziesz na stronie z bibliotekami klienta.

Java

Korzysta z biblioteki klienta 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

Używa biblioteki klienta dla języka 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')

Wypróbuj

Użyj Eksploratora interfejsów API poniżej, aby wywołać tę metodę na aktywnych danych i zobaczyć odpowiedź.