Containers: update

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

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

ส่งคำขอ

คำขอ HTTP

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

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์เส้นทาง
accountId string รหัสบัญชี GTM
containerId string รหัสคอนเทนเนอร์ GTM
พารามิเตอร์การค้นหาที่ไม่บังคับ
fingerprint string หากระบุ ลายนิ้วมือนี้ต้องตรงกับลายนิ้วมือของคอนเทนเนอร์ในพื้นที่เก็บข้อมูล

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

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

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

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

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

ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย Notes
พร็อพเพอร์ตี้ที่จำเป็น
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 เขียนได้
name string ชื่อที่แสดงของคอนเทนเนอร์ เขียนได้
notes string หมายเหตุคอนเทนเนอร์ เขียนได้
timeZoneCountryId string รหัสประเทศของคอนเทนเนอร์ เขียนได้
timeZoneId string รหัสเขตเวลาของคอนเทนเนอร์ เขียนได้

คำตอบ

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

ตัวอย่าง

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

Java

ใช้ไลบรารีของไคลเอ็นต์ Java

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

/*
 * This request updates an existing container for the authorized user.
 */

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

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

/*
 * The results of the update method are stored in the response object.
 * The following code shows how to access the updated name and fingerprint.
 */
System.out.println("Updated Name = " + response.getName());
System.out.println("Updated Fingerprint = " + response.getFingerprint());

Python

ใช้ไลบรารีของไคลเอ็นต์ Python

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

# This request updates an existing container.
try:
  response = tagmanager.accounts().containers().update(
      accountId='123456',
      containerId='54321',
      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 update method are stored in the response object.
# The following code shows how to access the updated name and fingerprint.
print 'Updated Name = %s' % response.get('name')
print 'Updated Fingerprint = %s' % response.get('fingerprint')

ลองใช้เลย

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