Rules: list

Requer autorização

Lista todos os Rules do GTM de um contêiner. Faça um teste agora ou veja um exemplo.

Solicitação

Solicitação HTTP

GET https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/rules

Parâmetros

Nome do parâmetro Valor Descrição
Parâmetros de caminho
accountId string Código do Account do GTM.
containerId string Código do contêiner do GTM.

Autorização

Esta solicitação requer autorização com pelo menos um dos seguintes escopos (leia mais sobre autenticação e autorização).

Escopo
https://www.googleapis.com/auth/tagmanager.readonly
https://www.googleapis.com/auth/tagmanager.edit.containers

Corpo da solicitação

Não forneça um corpo de solicitação com este método.

Resposta

Se for bem-sucedido, esse método retornará um corpo de resposta com esta estrutura:

{
  "rules": [
    accounts.containers.rules Resource
  ]
}
Nome da propriedade Valor Descrição Observações
rules[] list Todos os Rules do GTM de um Container do GTM.

Exemplos

Observação: os exemplos de código disponíveis para esse método não representam todas as linguagens de programação compatíveis. Consulte a página de bibliotecas cliente para ver uma lista de linguagens compatíveis.

Java

Usa a biblioteca cliente de Java.

/*
 * Note: This code assumes you have an authorized tagmanager service object.
 */

/*
 * This request lists all rules for the authorized user.
 */
try {
  ListRulesResponse rules = tagmanager.accounts().containers().rules().
      list("123456", "54321").execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}


/*
 * The results of the list method are stored in the rules object.
 * The following code shows how to iterate through them.
 */
for (Rule rule : rules.getRules()) {
  System.out.println("Account Id = " + rule.getAccountId());
  System.out.println("Container Id = " + rule.getContainerId());
  System.out.println("Rule Id = " + rule.getRuleId());
  System.out.println("Rule Name = " + rule.getName());
  System.out.println("Rule Notes = " + rule.getNotes());

  // Get the conditions.
  if (rule.getCondition() != null) {
    for (Condition condition : rule.getCondition()) {
      System.out.println("Condition Type = " + condition.getType());
      if (condition.getParameter() != null) {
        for (Parameter parameter : condition.getParameter()) {
          System.out.println("Parameter Type = " + parameter.getType());
          System.out.println("Parameter Key = " + parameter.getKey());
          System.out.println("Parameter Value = " + parameter.getValue());
        }
      }
    }
  }
  System.out.println("Rule Fingerprint = " + rule.getFingerprint());
}

Python

Usa a biblioteca cliente de Python.

# Note: This code assumes you have an authorized tagmanager service object.

# This request lists all rules for the authorized user.
try:
  rules = tagmanager.accounts().containers().rules().list(
      accountId='123456',
      containerId='54321'
  ).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 list method are stored in the rules object.
# The following code shows how to iterate through them.
for rule in rules.get('rules', []):
  print 'Account Id = %s' % rules.get('accountId')
  print 'Container Id = %s' % rules.get('containerId')
  print 'Rule Id = %s' % rule.get('ruleId')
  print 'Rule Name = %s' % rule.get('name')
  print 'Rule Notes = %s' % rule.get('notes')
  for condition in rule.get('condition', []):
    print 'Condition Type = %s' % condition.get('type')
    for parameter in condition.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
  print 'Rule Fingerprint = %s\n\n' % rule.get('fingerprint')

Confira!

Use o APIs Explorer abaixo para chamar esse método em dados ativos e ver a resposta.