需要授权
请求
HTTP 请求
PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules/ruleId
参数
参数名称 | 值 | 说明 |
---|---|---|
路径参数 | ||
accountId |
string |
GTM 帐号 ID。 |
containerId |
string |
GTM 容器 ID。 |
ruleId |
string |
GTM 规则 ID。 |
可选的查询参数 | ||
fingerprint |
string |
此指纹(如果提供)必须与所存储规则的指纹匹配。 |
授权
此请求需要获得下列范围的授权(详细了解身份验证和授权)。
范围 |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
请求正文
在请求正文中,提供具有以下属性的 Rules 资源:
属性名称 | 值 | 说明 | 备注 |
---|---|---|---|
必需属性 | |||
condition[].parameter[] |
list |
命名参数(即键值对)的列表,具体取决于条件的类型。注意:
|
可写 |
condition[].parameter[].type |
string |
参数类型。有效值:
可接受的值:
|
可写 |
condition[].type |
string |
此条件的运算符类型。
可接受的值:
|
可写 |
可选属性 | |||
condition[] |
list |
构成此规则的条件的列表(这些条件之间存在隐式 AND 关系)。 | 可写 |
condition[].parameter[].key |
string |
唯一标识参数的命名键。对于顶级参数及映射值,该键属于必需项。但对于列表值,会忽略该键。 | 可写 |
condition[].parameter[].list[] |
list |
该列表参数的参数(键将被忽略)。 | 可写 |
condition[].parameter[].map[] |
list |
该映射参数的参数(必须提供键;且键必须具有唯一性)。 | 可写 |
condition[].parameter[].value |
string |
适用于指定类型的参数的值,可以包含宏引用,例如“”。 | 可写 |
name |
string |
规则显示名。 | 可写 |
notes |
string |
有关如何在容器中应用此规则的用户注释。 | 可写 |
响应
如果成功,此方法将在响应正文中返回 Rules 资源。
示例
注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 Java 客户端库。
/* * Note: This code assumes you have an authorized tagmanager service object. */ /* * This request updates an existing rule for the authorized user. */ // Construct the condition parameters. Parameter arg0 = new Parameter(); arg0.setType("template"); arg0.setKey("arg0"); arg0.setValue("{{url}}"); Parameter arg1 = new Parameter(); arg1.setType("template"); arg1.setKey("arg1"); arg1.setValue(".*hellowworld.html"); // Construct the condition object Condition condition = new Condition(); condition.setType("endsWith"); condition.setParameter(Arrays.asList(arg0, arg1)); // Construct the rule object. Rule rule = new Rule(); rule.setName("Updated Rule"); rule.setCondition(Arrays.asList(condition)); try { Rule response = tagmanager.accounts().containers(). rules().update("123456", "54321", "2", rule).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 rule for the authorized user. try: response = tagmanager.accounts().containers().rules().update( accountId='123456', containerId='54321', ruleId='2', body={ 'name': 'Updated Ends with Rule', 'condition': [ { 'type': 'endsWith', 'parameter': [ { 'type': 'template', 'key': 'arg0', 'value': '{{url}}' }, { 'type': 'template', 'key': 'arg1', 'value': '.*hellowworld.html' } ] } ] } ).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 对实时数据调用此方法并查看响应。