Requiere autorización
Actualiza una regla de GTM. Pruébalo ahora y ve un ejemplo.
Solicitud
Solicitud HTTP
PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules/ruleId
Parámetros
Nombre del parámetro | Valor | Descripción |
---|---|---|
Parámetros de ruta de acceso | ||
accountId |
string |
El ID de la cuenta de GTM. |
containerId |
string |
El ID del contenedor de GTM. |
ruleId |
string |
El ID de regla de GTM. |
Parámetros de consulta opcionales | ||
fingerprint |
string |
Cuando se proporciona, esta huella digital debe coincidir con la de la regla en el almacenamiento. |
Autorización
Esta solicitud requiere autorización con el siguiente alcance (obtén más información sobre la autenticación y la autorización).
Permiso |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
Cuerpo de la solicitud
En el cuerpo de la solicitud, proporciona un recurso de reglas con las siguientes propiedades:
Nombre de la propiedad | Valor | Descripción | Notas |
---|---|---|---|
Propiedades obligatorias | |||
condition[].parameter[] |
list |
Una lista de parámetros con nombre (clave-valor), según el tipo de condición. Notas:
|
admite escritura |
condition[].parameter[].type |
string |
Es el tipo de parámetro. Los valores válidos son los siguientes:
Los valores aceptables son los siguientes:
|
admite escritura |
condition[].type |
string |
Es el tipo de operador para esta condición.
Los valores aceptables son los siguientes:
|
admite escritura |
Propiedades opcionales | |||
condition[] |
list |
Es la lista de condiciones que conforman esta regla (implícito AND entre ellas). | admite escritura |
condition[].parameter[].key |
string |
La clave con nombre que identifica un parámetro de forma única. Obligatorio para los parámetros de nivel superior, así como para los valores de mapa. Se ignora para los valores de lista. | admite escritura |
condition[].parameter[].list[] |
list |
Los parámetros de este parámetro de lista (se ignorarán las claves). | admite escritura |
condition[].parameter[].map[] |
list |
Los parámetros de este parámetro de mapa (deben tener claves; las claves deben ser únicas). | admite escritura |
condition[].parameter[].value |
string |
El valor de un parámetro (puede contener referencias de macro como "") según corresponda para el tipo especificado. | admite escritura |
name |
string |
Nombre visible de la regla. | admite escritura |
notes |
string |
Notas del usuario sobre cómo aplicar esta regla en el contenedor. | admite escritura |
Respuesta
Si se aplica correctamente, este método muestra un recurso de reglas en el cuerpo de la respuesta.
Ejemplos
Nota: Los ejemplos de código disponibles para este método no representan todos los lenguajes de programación admitidos (consulta la página de bibliotecas cliente para consultar una lista de lenguajes admitidos).
Java
Usa la biblioteca cliente de 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
Usa la biblioteca cliente de 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')
Pruébala
Usa el Explorador de APIs que aparece a continuación para llamar a este método con datos en tiempo real y ver la respuesta.