Cần có sự cho phép
Tạo vùng chứa. Thử ngay hoặc xem ví dụ.
Yêu cầu
Yêu cầu HTTP
POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers
Các tham số
Tên thông số | Giá trị | Nội dung mô tả |
---|---|---|
Tham số đường dẫn | ||
accountId |
string |
Mã tài khoản GTM. |
Ủy quyền
Yêu cầu này cần được uỷ quyền với phạm vi sau (đọc thêm về quy trình xác thực và uỷ quyền).
Phạm vi |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
Nội dung yêu cầu
Trong nội dung yêu cầu, hãy cung cấp tài nguyên Vùng chứa có các thuộc tính sau:
Tên tài sản | Giá trị | Nội dung mô tả | Ghi chú |
---|---|---|---|
Thuộc tính bắt buộc | |||
name |
string |
Tên hiển thị vùng chứa. | có thể ghi |
timeZoneCountryId |
string |
Mã quốc gia của vùng chứa. | có thể ghi |
timeZoneId |
string |
Mã múi giờ của vùng chứa. | có thể ghi |
usageContext[] |
list |
Danh sách ngữ cảnh sử dụng cho vùng chứa. Các giá trị hợp lệ bao gồm: web, android, ios . |
có thể ghi |
Thuộc tính không bắt buộc | |||
domainName[] |
list |
Danh sách tên miền không bắt buộc liên kết với Vùng chứa. | có thể ghi |
enabledBuiltInVariable[] |
list |
Danh sách các biến tích hợp đã bật. Các giá trị hợp lệ bao gồm: 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 . |
có thể ghi |
notes |
string |
Ghi chú vùng chứa. | có thể ghi |
Phản hồi
Nếu thành công, phương thức này sẽ trả về một tài nguyên Vùng chứa trong nội dung phản hồi.
Ví dụ
Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).
Java
Sử dụng thư viện ứng dụng 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
Dùng thư viện ứng dụng 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')
Hãy dùng thử!
Hãy sử dụng APIs Explorer bên dưới để gọi phương thức này trên dữ liệu trực tiếp và xem phản hồi.