Tags: list

Cần có sự cho phép

Liệt kê tất cả các thẻ GTM của một vùng chứa. Thử ngay hoặc xem ví dụ.

Yêu cầu

Yêu cầu HTTP

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

Các tham số

Tên thông số Giá trị Nội dung mô tả
Tham số đường dẫn
accountId string Mã tài khoản GTM.
containerId string Mã vùng chứa Trình quản lý thẻ của Google (GTM).

Ủy quyền

Yêu cầu này cần được uỷ quyền với ít nhất một trong các phạm vi sau (đọc thêm về quy trình xác thực và uỷ quyền).

Phạm vi
https://www.googleapis.com/auth/tagmanager.readonly
https://www.googleapis.com/auth/tagmanager.edit.containers

Nội dung yêu cầu

Đừng cung cấp nội dung yêu cầu bằng phương thức này.

Phản hồi

Nếu thành công, phương thức này sẽ trả về một nội dung phản hồi có cấu trúc như sau:

{
  "tags": [
    accounts.containers.tags Resource
  ]
}
Tên tài sản Giá trị Nội dung mô tả Ghi chú
tags[] list Tất cả các thẻ GTM của vùng chứa GTM.

Ví dụ

Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).

Java

Sử dụng thư viện ứng dụng Java.

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

/*
 * This request lists all tags for the authorized user.
 */
try {
  ListTagsResponse tags = tagmanager.accounts().containers().tags().
      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 tags object.
 * The following code shows how to iterate through them.
 */
for (Tag tag : tags.getTags()) {
  System.out.println("Account Id = " + tag.getAccountId());
  System.out.println("Container Id = " + tag.getContainerId());
  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("Tag Dependencies Type = " + dependencies.getType());
    System.out.println("Tag Dependencies Key = " + dependencies.getKey());
    System.out.println("Tag 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

Dùng thư viện ứng dụng Python.

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

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

  print 'Account Id = %s' % tag.get('accountId')
  print 'Container Id = %s' % tag.get('containerId')

  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')

Hãy dùng thử!

Hãy sử dụng APIs Explorer bên dưới để gọi phương thức này trên dữ liệu trực tiếp và xem phản hồi.