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

Container Versions:list

需要授权

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

请求

HTTP 请求

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

参数

参数名称 说明
路径参数
accountId string GTM 帐号 ID。
containerId string GTM 容器 ID。
可选查询参数
headers boolean 仅在值为 true 时检索标头。(默认值:false
includeDeleted boolean 值为 true 时,还检索已删除(已归档)的版本。(默认值:false

授权

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

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

请求正文

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

响应

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

{
  "containerVersion": [
    accounts.containers.versions Resource
  ],
  "containerVersionHeader": [
    {
      "accountId": string,
      "containerId": string,
      "containerVersionId": string,
      "name": string,
      "numMacros": string,
      "numRules": string,
      "numTags": string,
      "numTriggers": string,
      "deleted": boolean,
      "numVariables": string
    }
  ]
}
属性名称 说明 备注
containerVersion[] list GTM 容器的所有版本。
containerVersionHeader[] list GTM 容器的所有容器版本标头。
containerVersionHeader[].accountId string GTM 帐号 ID。
containerVersionHeader[].containerId string GTM 容器 ID。
containerVersionHeader[].containerVersionId string 唯一标识 GTM 容器版本的容器版本 ID。
containerVersionHeader[].name string 容器版本的显示名。
containerVersionHeader[].numMacros string 容器版本中宏的个数。
containerVersionHeader[].numRules string 容器版本中的规则数。
containerVersionHeader[].numTags string 容器版本中的代码数。
containerVersionHeader[].deleted boolean 如果值为 true,则表示该容器版本已被删除。
containerVersionHeader[].numTriggers string 容器版本中的触发器数。
containerVersionHeader[].numVariables string 容器版本中的变量数。

示例

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

Java

使用 Java 客户端库

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

/*
* This request lists all container versions for the authorized user.
*/
try {
  ListContainerVersionsResponse versions = tagmanager.accounts().
      containers().versions().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 versions object.
 * The following code shows how to iterate through them.
 */
for (ContainerVersion version : versions.getContainerVersion()) {
  System.out.println("Account Id = " + version.getAccountId());
  System.out.println("Container Id = " + version.getContainerId());
  System.out.println("Container Version Id = "
      + version.getContainerVersionId());
  System.out.println("Version Name = " +  version.getName());
  System.out.println("Version Deleted = " + version.getDeleted());
  System.out.println("Version Notes = %s" + version.getNotes());
  System.out.println("Version Fingerprint = " + version.getFingerprint());

  // Print the Container details.
  Container container = version.getContainer();
  System.out.println("Container Name = " + container.getName());
  if (container.getDomainName() != null) {
    for (String domain : container.getDomainName()) {
      System.out.println("Domain Name = " + domain);
    }
  }
  System.out.println("Timezone Country Id = "
      + container.getTimeZoneCountryId());
  System.out.println("Timezone Id = " + container.getTimeZoneId());
  System.out.println("Container Notes = " + container.getNotes());
  for (String usageContext : container.getUsageContext()) {
    System.out.println("Usage context = " + usageContext);
  }
  System.out.println("Container Fingerprint = " + container.getFingerprint());

  // Print the Macro details.
  for (Macro macro : version.getMacro()) {
    System.out.println("Macro Id = " + macro.getMacroId());
    System.out.println("Macro Name = " + macro.getName());
    System.out.println("Macro Type = " + macro.getType());
    System.out.println("Macro Notes = " + macro.getNotes());
    if (macro.getParameter() != null) {
      for (Parameter parameter : macro.getParameter()) {
        System.out.println("Parameter Type = " + parameter.getType());
        System.out.println("Parameter Key = " + parameter.getKey());
        System.out.println("Parameter Value = " + parameter.getValue());
      }
    }
    if (macro.getEnablingRuleId() != null) {
      for (String enabllingRuleId : macro.getEnablingRuleId()) {
        System.out.println("Macro Enabling Rule Id = " + enabllingRuleId);
      }
    }
    if (macro.getDisablingRuleId() != null) {
      for (String disablingRuleId : macro.getDisablingRuleId()) {
        System.out.println("Macro Disabling Rule Id " + disablingRuleId);
      }
    }
    System.out.println("Macro Fingerprint = " + macro.getFingerprint());
  }

  // Print the rule details.
  for (Rule rule : version.getRule()) {
    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());
  }

  // Print the Tag details.
  if (version.getTag() != null) {
    for (Tag tag : version.getTag()) {
      System.out.println("Tag id = " + tag.getTagId());
      System.out.println("Tag Name = " + tag.getName());
      System.out.println("Tag Type = " + tag.getType());
      if (tag.getFiringRuleId() != null) {
        for (String firingRuleId : tag.getFiringRuleId()) {
          System.out.println("Firing Rule Id  = " + firingRuleId);
        }
      }
      if (tag.getBlockingRuleId() != null) {
        for (String blockingRuleId : tag.getBlockingRuleId()) {
          System.out.println("Blocking Rule Id = " + blockingRuleId);
        }
      }
      System.out.println("Tag Live Only = " + tag.getLiveOnly());

      // Get tag priority.
      Parameter priority = tag.getPriority();
      if (priority != null) {
        System.out.println("Tag Priority Type = " + priority.getType());
        System.out.println("Tag Priority Key = " + priority.getKey());
        System.out.println("Tag Priority Value = " + priority.getValue());
      }

      // Get tag dependencies.
      Parameter dependencies = tag.getDependencies();
      if (dependencies != null) {
        System.out.println("Dependencies Type = " + dependencies.getType());
        System.out.println("Dependencies Key = " + dependencies.getKey());
        System.out.println("Dependencies Value = " + dependencies.getValue());
      }

      System.out.println("Tag Notes = " + tag.getNotes());
      System.out.println("Tag Schedule Start ms = " + tag.getScheduleStartMs());
      System.out.println("Tag Schedule End ms = " + tag.getScheduleEndMs());

      // Get tag parameters.
      if (tag.getParameter() != null) {
        for (Parameter parameter : tag.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("Tag Fingerprint = " + tag.getFingerprint());
    }
  }
}

Python

使用 Python 客户端库

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

# This request lists all container versions for the authorized user.
try:
  versions = tagmanager.accounts().containers().versions().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 versions object.
# The following code shows how to iterate through them.
for version in versions.get('containerVersion', []):

  print 'Account Id = %s' % version.get('accountId')
  print 'Container Id = %s' % version.get('containerId')
  print 'Container Version Id = %s' % version.get('containerVersionId')
  print 'Version Name = %s' % version.get('name')
  print 'Version Deleted = %s' % version.get('deleted')
  print 'Version Notes = %s' % version.get('notes')
  print 'Version Fingerprint = %s\n\n' % version.get('fingerprint')

  # Get the container object.
  container = version.get('container', {})
  print 'Container Name = %s' % container.get('name')
  for domain in container.get('domainName', []):
    print 'Domain Name = %s' % domain
  print 'Timezone Country Id = %s' % container.get('timeZoneCountryId')
  print 'Timezone Id = %s' % container.get('timeZone')
  print 'Notes = %s' % container.get('notes')
  for usageContext in container.get('usageContext'):
    print 'Usage Context = %s' % usageContext
  print 'Container Fingerprint = %s\n\n' % container.get('fingerprint')

  # Get the macro objects.
  for macro in version.get('macro', []):
    print 'Macro Id = %s' % macro.get('macroId')
    print 'Macro Name = %s' % macro.get('name')
    print 'Macro Type = %s' % macro.get('type')
    print 'Macro notes = %s' % macro.get('notes')
    print 'Schedule Start ms = %s' % macro.get('scheduleStartMs')
    print 'Schedule End ms = %s' % macro.get('scheduleEndMs')
    for parameter in macro.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
    for enablingRuleId in macro.get('enablingRuleId', []):
      print 'Macro Enabling Rule Id = %s' % enablingRuleId
    for disablingRuleId in macro.get('disablingRuleId', []):
      print 'Macro Disabling Rule Id = %s' % disablingRuleId
    print 'Macro Fingerprint = %s\n\n' % macro.get('fingerprint')

  # Get the rule object.
  for rule in version.get('rule'):
    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 'Condition Parameter Type = %s' % condition.get('type')
        print 'Condition Parameter Key = %s' % condition.get('key')
        print 'Condition Parameter Value = %s' % condition.get('value')
    print 'Rule Fingerprint = %s\n\n' % rule.get('fingerprint')

  # Get the tag objects.
  for tag in version.get('tag', []):
    print 'Tag Id = %s' % tag.get('tagId')
    print 'Tag Name = %s' % tag.get('name')
    print 'Tag Type = %s' % tag.get('type')
    for firingRuleId in tag.get('firingRuleId', []):
      print 'Tag Firing Rule Id = %s' % firingRuleId
    for blockingRuleId in tag.get('blockingRuleId', []):
      print 'Tag Blocking Rule Id = %s' % blockingRuleId
    print 'Tag Live Only = %s' % tag.get('liveOnly')

    # Get tag priority.
    priority = tag.get('priority', {})
    print 'Tag Priority Type = %s' % priority.get('type')
    print 'Tag Priority Key = %s' % priority.get('key')
    print 'Tag Priority value = %s' % priority.get('value')

    # Get tag dependencies.
    dependencies = tag.get('dependencies', {})
    print 'printing Dependencies: %s' % dependencies
    print 'Dependencies Type = %s' % dependencies.get('type')
    print 'Dependencies Key = %s' % dependencies.get('key')
    print 'Dependencies Value = %s' % dependencies.get('value')

    print 'Tag Notes = %s' % tag.get('notes')
    print 'Tag Schedule Start ms = %s' % tag.get('scheduleStartMs')
    print 'Tag Schedule End ms = %s' % tag.get('scheduleEndMs')
    for parameter in tag.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
    print 'Tag Fingerprint = %s\n\n' % tag.get('fingerprint')

试用一下!

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