ต้องมีการให้สิทธิ์
อัปเดตมาโคร GTM ลองใช้เลยหรือดูตัวอย่าง
ส่งคำขอ
คำขอ HTTP
PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/macros/macroId
พารามิเตอร์
ชื่อพารามิเตอร์ | ค่า | คำอธิบาย |
---|---|---|
พารามิเตอร์เส้นทาง | ||
accountId |
string |
รหัสบัญชี GTM |
containerId |
string |
รหัสคอนเทนเนอร์ GTM |
macroId |
string |
รหัสมาโคร GTM |
พารามิเตอร์การค้นหาที่ไม่บังคับ | ||
fingerprint |
string |
หากระบุ ลายนิ้วมือนี้ต้องตรงกับลายนิ้วมือของมาโครในพื้นที่เก็บข้อมูล |
การให้สิทธิ์
คำขอนี้ต้องได้รับสิทธิ์ด้วยขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)
ขอบเขต |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
เนื้อหาของคำขอ
ในเนื้อหาคำขอ ให้ระบุทรัพยากรมาโครพร้อมด้วยพร็อพเพอร์ตี้ต่อไปนี้
ชื่อพร็อพเพอร์ตี้ | ค่า | คำอธิบาย | Notes |
---|---|---|---|
พร็อพเพอร์ตี้ที่จำเป็น | |||
parameter[].type |
string |
ประเภทพารามิเตอร์ ค่าที่ถูกต้องคือ:
ค่าที่ยอมรับมีดังนี้
|
เขียนได้ |
type |
string |
ประเภทมาโคร GTM | เขียนได้ |
พร็อพเพอร์ตี้ที่ไม่บังคับ | |||
disablingRuleId[] |
list |
สำหรับคอนเทนเนอร์อุปกรณ์เคลื่อนที่เท่านั้น: รายการรหัสกฎสำหรับการปิดใช้มาโครแบบมีเงื่อนไข มาโครจะเปิดใช้งานหากกฎเปิดใช้งานข้อใดข้อหนึ่งเป็นจริงในขณะที่กฎปิดใช้งานทั้งหมดเป็นเท็จ ถือว่าเป็นชุดที่ไม่มีลำดับ | เขียนได้ |
enablingRuleId[] |
list |
สำหรับคอนเทนเนอร์อุปกรณ์เคลื่อนที่เท่านั้น: รายการรหัสกฎสำหรับเปิดใช้งานมาโครแบบมีเงื่อนไข มาโครจะเปิดใช้งานหากกฎเปิดใช้งานข้อใดข้อหนึ่งเป็นจริงในขณะที่กฎปิดใช้งานทั้งหมดเป็นเท็จ ถือว่าเป็นชุดที่ไม่มีลำดับ | เขียนได้ |
name |
string |
ชื่อที่แสดงของมาโคร | เขียนได้ |
notes |
string |
ผู้ใช้หมายเหตุเกี่ยวกับวิธีใช้มาโครนี้ในคอนเทนเนอร์ | เขียนได้ |
parameter[] |
list |
พารามิเตอร์ของมาโคร | เขียนได้ |
parameter[].key |
string |
คีย์ที่มีชื่อซึ่งระบุพารามิเตอร์โดยไม่ซ้ำกัน ต้องระบุสำหรับพารามิเตอร์ระดับบนสุดและค่าแมป ละเว้นสำหรับค่ารายการ | เขียนได้ |
parameter[].list[] |
list |
พารามิเตอร์ของพารามิเตอร์รายการนี้ (ระบบจะไม่สนใจคีย์) | เขียนได้ |
parameter[].map[] |
list |
พารามิเตอร์ของพารามิเตอร์แมปนี้ (ต้องมีคีย์ คีย์ต้องไม่ซ้ำกัน) | เขียนได้ |
parameter[].value |
string |
ค่าของพารามิเตอร์ (อาจมีการอ้างอิงมาโคร เช่น "") ที่เหมาะสมกับประเภทที่ระบุ | เขียนได้ |
scheduleEndMs |
long |
การประทับเวลาสิ้นสุดเป็นมิลลิวินาทีเพื่อกำหนดเวลาให้มาโคร | เขียนได้ |
scheduleStartMs |
long |
การประทับเวลาเริ่มต้นเป็นมิลลิวินาทีเพื่อกำหนดเวลาให้มาโคร | เขียนได้ |
คำตอบ
หากสำเร็จ วิธีการนี้จะแสดงผลทรัพยากรของมาโครในเนื้อหาการตอบสนอง
ตัวอย่าง
หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)
Java
/* * Note: This code assumes you have an authorized tagmanager service object. */ /* * This request updates an existing macro for the authorized user. */ // Construct the macro object. Macro macro = new Macro(); macro.setName("Updated URL Macro"); macro.setType("u"); // Construct the parameters. Parameter arg0 = new Parameter(); arg0.setType("template"); arg0.setKey("component"); arg0.setValue("URL"); Parameter arg1 = new Parameter(); arg1.setType("template"); arg1.setKey("customUrlSource"); arg1.setValue("{{element}}"); // set the parameters on the macro. macro.setParameter(Arrays.asList(arg0, arg1)); try { Macro response = tagmanager.accounts().containers(). macros().update("123456", "54321", "18", macro).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
# Note: This code assumes you have an authorized tagmanager service object. # This request updates an existing macro for the authorized user. try: response = tagmanager.accounts().containers().macros().update( accountId='123456', containerId='54321', macroId='19', body={ 'name': 'Sample URL Macro', 'type': 'u', 'parameter': [ { 'type': 'template', 'key': 'component', 'value': 'URL' }, { 'type': 'template', 'key': 'customUrlSource', 'value': '{{element}}' } ] } ).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 ด้านล่างเพื่อเรียกใช้เมธอดนี้กับข้อมูลแบบเรียลไทม์และดูการตอบสนอง