注意:此开发者网站正在向 developers.google.com/tag-platform 迁移,2021 年 9 月 30 日起系统会将您重定向到新的网址

Triggers:list

需要授权

列出容器的所有 GTM 触发器。 立即试用查看示例

请求

HTTP 请求

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

参数

参数名称 说明
路径参数
accountId string GTM 帐号 ID。
containerId string GTM 容器 ID。

授权

此请求至少需要获得以下任一范围的授权(详细了解身份验证和授权)。

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

请求正文

请勿使用此方法提供请求正文。

响应

如果成功,此方法将返回采用以下结构的响应正文:

{
  "triggers": [
    accounts.containers.triggers Resource
  ]
}
属性名称 说明 备注
triggers[] list GTM 容器的所有 GTM 触发器。

示例

备注:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。

Java

使用 Java 客户端库

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

/*
 * This request lists triggers for the authorized user.
 */
try {
  ListTriggersResponse triggers = tagmanager.accounts().containers().
      triggers().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 triggers object.
 * The following code shows how to iterate through them.
 */
for (Trigger trigger: triggers.getTriggers()) {
  System.out.println("Account Id = " + trigger.getAccountId());
  System.out.println("Container Id = " + trigger.getContainerId());
  System.out.println("Triger Id = " + trigger.getTriggerId());
  System.out.println("Triger Name = " + trigger.getName());
  System.out.println("Triger Type = " + trigger.getType());
  if (trigger.getCustomEventFilter() != null) {
    for (Condition customEventFilter: trigger.getCustomEventFilter()) {
      System.out.println("Custom Event Filter Type = "
          + customEventFilter.getType());
      for (Parameter parameter: customEventFilter.getParameter()) {
        System.out.println("Parameter Type = " + parameter.getType());
        System.out.println("Parameter Key = " + parameter.getKey());
        System.out.println("Parameter Value = " + parameter.getValue());
      }
    }
  }
  if (trigger.getFilter() != null) {
    for (Condition filter: trigger.getFilter()) {
      System.out.println("Filter Type = " + filter.getType());
      for (Parameter parameter: filter.getParameter()) {
        System.out.println("Parameter Type = " + parameter.getType());
        System.out.println("Parameter Key = " + parameter.getKey());
        System.out.println("Parameter Value = " + parameter.getValue());
      }
    }
  }
  if (trigger.getAutoEventFilter() != null) {
    for (Condition filter: trigger.getAutoEventFilter()) {
      System.out.println("Auto Event Filter Type = " + filter.getType());
      for (Parameter parameter: filter.getParameter()) {
        System.out.println("Parameter Type = " + parameter.getType());
        System.out.println("Parameter Key = " + parameter.getKey());
        System.out.println("Parameter Value = " + parameter.getValue());
      }
    }
  }
  if (trigger.getWaitForTags() != null) {
    Parameter parameter = trigger.getWaitForTags();
    System.out.println("Wait For Tags Type = " + parameter.getType());
    System.out.println("Wait For Tags Key = " + parameter.getKey());
    System.out.println("Wait For Tags Value = " + parameter.getValue());
  }
  if (trigger.getCheckValidation() != null) {
    Parameter parameter = trigger.getCheckValidation();
    System.out.println("Check Validation Type = " + parameter.getType());
    System.out.println("Check Validation Key = " + parameter.getKey());
    System.out.println("Check Validation Value = "
        + parameter.getValue());
  }
  if (trigger.getWaitForTagsTimeout() != null) {
    Parameter parameter = trigger.getWaitForTagsTimeout();
    System.out.println("Wait For Tags Timeout Type = "
        + parameter.getType());
    System.out.println("Wait For Tags Timeout Key = "
        + parameter.getKey());
    System.out.println("Wait For Tags Timeout Value = "
        + parameter.getValue());
  }
  if (trigger.getUniqueTriggerId() != null) {
    Parameter parameter = trigger.getUniqueTriggerId();
    System.out.println("Unique Trigger Id Type = " + parameter.getType());
    System.out.println("Unique Trigger Id Key = " + parameter.getKey());
    System.out.println("Unique Trigger Id Value = "
        + parameter.getValue());
  }
  if (trigger.getEventName() != null) {
    Parameter parameter = trigger.getEventName();
    System.out.println("Event Name Type = " + parameter.getType());
    System.out.println("Event Name Key = " + parameter.getKey());
    System.out.println("Event Name Value = " + parameter.getValue());
  }
  if (trigger.getInterval() != null) {
    Parameter parameter = trigger.getInterval();
    System.out.println("Interval Type = " + parameter.getType());
    System.out.println("Interval Key = " + parameter.getKey());
    System.out.println("Interval Value = " + parameter.getValue());
  }
  System.out.println("Trigger Fingerprint = " + trigger.getFingerprint());
}

Python

使用 Python 客户端库

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

# This request lists triggers for the authorized user.
try:
  triggers = tagmanager.accounts().containers().triggers().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 triggers object.
# The following code shows how to iterate through them.
for trigger in triggers.get('triggers', []):
  print 'Account Id = %s' % trigger.get('accountId')
  print 'Container Id = %s' % trigger.get('containerId')
  print 'Trigger Id = %s' % trigger.get('triggerId')
  print 'Trigger Name = %s' % trigger.get('name')
  print 'Trigger Type = %s' % trigger.get('type')
  for customEventFilter in trigger.get('customEventFilter', []):
    print 'Custom Event Filter Type = %s' % customEventFilter.get('type')
    for parameter in customEventFilter.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
  for filter in trigger.get('filter', []):
    print 'Filter Type = %s' % filter.get('type')
    for parameter in filter.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
  for autoEventFilter in trigger.get('autoEventFilter', []):
    print 'Auto Event Filter Type = %s' % autoEventFilter.get('type')
    for parameter in autoEventFilter.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
  waitForTags = trigger.get('waitForTags', {})
  print 'Wait For Tags Type = %s' % waitForTags.get('type')
  print 'Wait for Tags Key = %s' % waitForTags.get('key')
  print 'Wait for Tags value = %s' % waitForTags.get('value')
  checkValidation = trigger.get('checkValidation', {})
  print 'Check Validation Type = %s' % checkValidation.get('type')
  print 'Check Validation Key = %s' % checkValidation.get('key')
  print 'Check Validation Value = %s' % checkValidation.get('value')
  waitForTagsTimeout = trigger.get('waitForTagsTimeout', {})
  print 'Wait For Tags Timeout Type = %s' % waitForTagsTimeout.get('type')
  print 'Wait For Tags Timeout Key = %s' % waitForTagsTimeout.get('key')
  print 'Wait For Tags Timeout Value = %s' % waitForTagsTimeout.get('value')
  uniqueTriggerId = trigger.get('uniqueTriggerId', {})
  print 'Unique Trigger Id Type = %s' % uniqueTriggerId.get('type')
  print 'Unique Trigger Id Key = %s' % uniqueTriggerId.get('key')
  print 'Unique Trigger Id Value = %s' % uniqueTriggerId.get('Value')
  eventName = trigger.get('eventName', {})
  print 'Event Name Type = %s' % eventName.get('type')
  print 'Event Name Id Key = %s' % eventName.get('key')
  print 'Event Name Id Value = %s' % eventName.get('Value')
  interval = trigger.get('interval', {})
  print 'Interval Type = %s' % interval.get('type')
  print 'Interval Key = %s' % interval.get('key')
  print 'Interval Value = %s' % interval.get('Value')

  print 'Trigger Fingerprint = %s\n\n' % trigger.get('fingerprint')

试用一下!

请使用下面的 API Explorer 针对实际数据调用此方法,并查看响应。