Richiede l'autorizzazione
Aggiorna una regola GTM. Prova subito o guarda un esempio.
Richiesta
Richiesta HTTP
PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules/ruleId
Parametri
Nome del parametro | Valore | Descrizione |
---|---|---|
Parametri del percorso | ||
accountId |
string |
L'ID account GTM. |
containerId |
string |
L'ID contenitore GTM. |
ruleId |
string |
L'ID regola GTM. |
Parametri di query facoltativi | ||
fingerprint |
string |
Se fornita, questa impronta deve corrispondere all'impronta della regola nello spazio di archiviazione. |
Autorizzazione
Questa richiesta richiede l'autorizzazione con il seguente ambito (scopri di più su autenticazione e autorizzazione).
Ambito |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
Corpo della richiesta
Nel corpo della richiesta, fornisci una risorsa Regole con le seguenti proprietà:
Nome proprietà | Valore | Descrizione | Note |
---|---|---|---|
Proprietà obbligatorie | |||
condition[].parameter[] |
list |
Un elenco di parametri denominati (chiave/valore), a seconda del tipo di condizione. Note:
|
scrivibile |
condition[].parameter[].type |
string |
Il tipo di parametro. I valori validi sono:
I valori accettati sono:
|
scrivibile |
condition[].type |
string |
Il tipo di operatore per questa condizione.
I valori accettati sono:
|
scrivibile |
Proprietà facoltative | |||
condition[] |
list |
L'elenco di condizioni che costituiscono questa regola (implicita AND tra le condizioni). | scrivibile |
condition[].parameter[].key |
string |
La chiave denominata che identifica in modo univoco un parametro. Obbligatorio per i parametri di primo livello e per i valori della mappa. Ignorato per i valori dell'elenco. | scrivibile |
condition[].parameter[].list[] |
list |
Parametri di questo parametro elenco (le chiavi verranno ignorate). | scrivibile |
condition[].parameter[].map[] |
list |
I parametri di questo parametro mappa (devono essere dotati di chiavi; le chiavi devono essere univoche). | scrivibile |
condition[].parameter[].value |
string |
Il valore di un parametro (può contenere riferimenti a macro come "") a seconda del tipo specificato. | scrivibile |
name |
string |
Nome visualizzato della regola. | scrivibile |
notes |
string |
Note dell'utente su come applicare questa regola nel contenitore. | scrivibile |
Risposta
In caso di esito positivo, questo metodo restituisce una risorsa Regole nel corpo della risposta.
Esempi
Nota: gli esempi di codice disponibili per questo metodo non rappresentano tutti i linguaggi di programmazione supportati (consulta la pagina relativa alle librerie client per un elenco dei linguaggi supportati).
Java
Utilizza la libreria client 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
Utilizza la libreria client 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')
Prova.
Utilizza Explorer API di seguito per chiamare questo metodo sui dati in tempo reale e visualizzare la risposta.