Containers: create

ต้องมีการให้สิทธิ์

สร้างคอนเทนเนอร์ ลองใช้เลยหรือดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

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

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์เส้นทาง
accountId string รหัสบัญชี GTM

การให้สิทธิ์

คำขอนี้ต้องได้รับสิทธิ์ด้วยขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)

ขอบเขต
https://www.googleapis.com/auth/tagmanager.edit.containers

เนื้อหาของคำขอ

ในเนื้อหาคำขอ ให้ระบุทรัพยากรคอนเทนเนอร์พร้อมด้วยพร็อพเพอร์ตี้ต่อไปนี้

ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย Notes
พร็อพเพอร์ตี้ที่จำเป็น
name string ชื่อที่แสดงของคอนเทนเนอร์ เขียนได้
timeZoneCountryId string รหัสประเทศของคอนเทนเนอร์ เขียนได้
timeZoneId string รหัสเขตเวลาของคอนเทนเนอร์ เขียนได้
usageContext[] list รายการบริบทการใช้งานสำหรับคอนเทนเนอร์ ค่าที่ถูกต้อง ได้แก่ web, android, ios เขียนได้
พร็อพเพอร์ตี้ที่ไม่บังคับ
domainName[] list รายการชื่อโดเมนที่เชื่อมโยงกับคอนเทนเนอร์ (ไม่บังคับ) เขียนได้
enabledBuiltInVariable[] list รายการตัวแปรบิวท์อินที่เปิดใช้ ค่าที่ถูกต้อง ได้แก่ 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 เขียนได้
notes string หมายเหตุคอนเทนเนอร์ เขียนได้

คำตอบ

หากสำเร็จ เมธอดนี้จะแสดงผลทรัพยากรคอนเทนเนอร์ในเนื้อหาการตอบสนอง

ตัวอย่าง

หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)

Java

ใช้ไลบรารีของไคลเอ็นต์ 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

ใช้ไลบรารีของไคลเอ็นต์ 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')

ลองใช้เลย

ใช้ API Explorer ด้านล่างเพื่อเรียกใช้เมธอดนี้กับข้อมูลแบบเรียลไทม์และดูการตอบสนอง