需要授权
请求
HTTP 请求
PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/tags/tagId
参数
参数名称 | 值 | 说明 |
---|---|---|
路径参数 | ||
accountId |
string |
GTM 帐号 ID。 |
containerId |
string |
GTM 容器 ID。 |
tagId |
string |
GTM 代码 ID。 |
可选查询参数 | ||
fingerprint |
string |
此指纹(如果提供)必须与所存储代码的指纹匹配。 |
授权
此请求需要获得下列范围的授权(详细了解身份验证和授权)。
范围 |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
请求正文
在请求正文中,提供具有以下属性的 Tags 资源:
属性名称 | 值 | 说明 | 备注 |
---|---|---|---|
必需属性 | |||
name |
string |
代码显示名。 | 可写入 |
parameter[].type |
string |
参数类型。有效值包括:
可接受的值包括:
|
可写入 |
priority.type |
string |
参数类型。有效值包括:
可接受的值包括:
|
可写入 |
可选属性 | |||
blockingRuleId[] |
list |
屏蔽规则 ID。如果列出的任何规则的计算结果为 true,将不触发代码。 | 可写入 |
blockingTriggerId[] |
list |
屏蔽型触发器 ID。如果列出的任何触发器的计算结果为 true,将不触发代码。 | 可写入 |
firingRuleId[] |
list |
触发规则 ID。如果列出的任何规则为 true 且代码的所有 blockingRuleIds (如果指定)为 false,则将触发代码。 |
可写入 |
firingTriggerId[] |
list |
触发型触发器 ID。如果列出的任何触发器为 true 且代码的所有 blockingTriggerIds (如果指定)为 false,则将触发代码。 |
可写入 |
liveOnly |
boolean |
如果设置为 true,则此代码仅在实际环境中触发(例如,不在预览或调试模式下触发)。 | 可写入 |
notes |
string |
有关如何在容器中应用此代码的用户注释。 | 可写入 |
parameter[] |
list |
代码的参数。 | 可写入 |
parameter[].key |
string |
唯一标识参数的命名键。对于顶级参数及映射值,该键属于必需项。但对于列表值,会忽略该键。 | 可写入 |
parameter[].list[] |
list |
该列表参数的参数(键将被忽略)。 | 可写入 |
parameter[].map[] |
list |
该映射参数的参数(必须提供键;且键必须具有唯一性)。 | 可写入 |
parameter[].value |
string |
适用于指定类型的参数的值(可以包含变量引用,例如“{{myVariable}}”)。 | 可写入 |
paused |
boolean |
如果代码已暂停,则为 true。 | 可写入 |
priority |
nested object |
用户指定的代码优先级数值。代码按优先级顺序异步触发。代码的优先级数值越大,触发顺序越靠前。代码的优先级可以是正值,也可以是负值。默认值为 0。 | 可写入 |
priority.key |
string |
唯一标识参数的命名键。对于顶级参数及映射值,该键属于必需项。但对于列表值,会忽略该键。 | 可写入 |
priority.list[] |
list |
该列表参数的参数(键将被忽略)。 | 可写入 |
priority.map[] |
list |
该映射参数的参数(必须提供键;且键必须具有唯一性)。 | 可写入 |
priority.value |
string |
适用于指定类型的参数的值(可以包含变量引用,例如“{{myVariable}}”)。 | 可写入 |
scheduleEndMs |
long |
用于安排代码的结束时间戳(以毫秒为单位)。 | 可写入 |
scheduleStartMs |
long |
用于安排代码的开始时间戳(以毫秒为单位)。 | 可写入 |
type |
string |
GTM 代码类型。 | 可写入 |
响应
如果成功,此方法将在响应正文中返回 Tags 资源。
示例
备注:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 Java 客户端库。
/* * Note: This code assumes you have an authorized tagmanager service object. */ /* * This request updates an existing tag for the authorized user. */ // Construct the parameters. Parameter arg0 = new Parameter(); arg0.setType("template"); arg0.setKey("trackingId"); arg0.setValue("UA-123456-1"); Parameter arg1 = new Parameter(); arg1.setType("template"); arg1.setKey("type"); arg1.setValue("TRACK_TRANSACTION"); // Construct the tag object. Tag tag = new Tag(); tag.setName("Sample Universal Analytics"); tag.setType("ua"); tag.setLiveOnly(false); tag.setParameter(Arrays.asList(arg0, arg1)); try { Tag response = tagmanager.accounts(). containers().tags().update("123456", "54321", "1", tag).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 new container tag. try: response = tagmanager.accounts().containers().tags().update( accountId='123456', containerId='54321', tagId='1', body={ 'name': 'Universal Analytics Tag', 'type': 'ua', 'liveOnly': False, 'parameter': [ { 'type': 'template', 'key': 'trackingId', 'value': 'UA-123456-1' }, { 'type': 'template', 'key': 'type', 'value': 'TRACK_TRANSACTION' } ] } ).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 针对实际数据调用此方法,并查看响应。