配置文件过滤器关联:insert

需要授权

创建一个新的配置文件过滤器关联。 立即试用查看示例

请求

HTTP 请求

POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/profileFilterLinks

参数

参数名称 说明
路径参数
accountId string 要为其创建配置文件过滤器关联的帐户 ID。
profileId string 要为其创建过滤器关联的配置文件 ID。
webPropertyId string 要为其创建配置文件过滤器关联的网络媒体资源 Id。

授权

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

范围
https://www.googleapis.com/auth/analytics.edit

请求正文

在请求正文中提供一个具有以下属性的“配置文件过滤器关联”资源

属性名称 说明 备注
必需属性
filterRef.id string 过滤器 ID。 可写入
可选属性
rank integer 此配置文件过滤器关联相对于关联到同一配置文件的其他过滤器的排名。

对于只读(即,列表和获取)操作,排名总是从 1 开始。

对于写入(即,create、update 或 delete)操作,可以指定 0 至 255 之间的任意值,包括 0 和 255。要在列表末尾插入一个关联,可以不指定排名,或者将排名设置为超出列表中最大排序的某个数字。要在列表开头插入一个关联,可以指定一个小于或等于 1 的排名。新的关联将使现有的所有具有相同或更低排名的过滤器在列表中向下移动。在插入/更新/删除关联之后,所有配置文件过滤器关联将从 1 开始重新编号。

可写入

响应

如果成功,此方法将在响应正文中返回一个“配置文件过滤器关联”资源

示例

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

Java

使用 Java 客户端库

/*
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Filters Developer Guide for details.
 */

/*
 * This request creates a new profile filter link.
 */

// Construct the filter reference.
FilterRef filterRef = new FilterRef();
filterRef.setId("1223334444");

// Construct the body of the request.
ProfileFilterLink body = new ProfileFilterLink();
body.setFilterRef(filterRef);

try {
analytics.management().profileFilterLinks().insert("123456",
    "UA-123456-1", "7654321", body).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

Python

使用 Python 客户端库

# Note: This code assumes you have an authorized Analytics service object.
# See the Filters Developer Guide for details.

# This request creates a new profile filter link.
try:
  analytics.management().profileFilterLinks().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      profileId='7654321',
      body={
          'filterRef': {
              'id': '1223334444'
          }
      }
  ).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))

试试看!

请使用下面的 API Explorer 针对实时数据调用此方法并查看响应。或者,您还可以尝试使用独立的 Explorer