You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GAM API中获取CUSTOM_DIMENSION_KEY_ID?

如何获取自定义维度Key ID以生成包含自定义字段的报表

我在运行包含自定义字段的报表时,需要在代码中提供Custom field id和Custom dimension key id。已经通过custom field service拿到了Custom field id,但不知道怎么获取Custom dimension key id。

以下是代码片段:

public class Report_CustomFields {

  private static class RunReportWithCustomFieldsParams extends CodeSampleParams {
    @Parameter(
        names = ArgumentNames.CUSTOM_FIELD_ID,
        required = true,
        description = "The ID of the custom field to include in the report.")
    private Long customFieldId;

    @Parameter(
        names = ArgumentNames.CUSTOM_DIMENSION_KEY_ID,
        required = true,
        description = "The ID of the custom key field to include as a Dimension in the report.")
    private Long customDimensionKeyId;
  }

我查阅了文档,找到如下内容:

customDimensionKeyIds xsd:long[]

The list of custom dimension custom targeting key IDs being requested
in this report. This will include dimensions in the form of
TOP_LEVEL_DIMENSION_KEY[id]_ID and TOP_LEVEL_DIMENSION_KEY[id]_VALUE
where ID is the ID of the custom targeting value and VALUE is the
name.

To add IDs, you must include Dimension.CUSTOM_DIMENSION in dimensions,
and specify a non-empty list of custom targeting key IDs. The order of
cusotm dimension columns in the report correspond to the place of
Dimension.CUSTOM_DIMENSION in dimensions. For example, if dimensions
contains the following dimensions in the order:
Dimension.ADVERTISER_NAME, Dimension.CUSTOM_DIMENSION and
Dimension.COUNTRY_NAME, and customCriteriaCustomTargetingKeyIds
contains the following IDs in the order: 1001 and 1002. The order of
dimensions in the report will be: Dimension.ADVERTISER_NAME,
Dimension.TOP_LEVEL_DIMENSION_KEY[1001]_VALUE,
Dimension.TOP_LEVEL_DIMENSION_KEY[1002]_VALUE, Dimension.COUNTRY_NAME,
Dimension.ADVERTISER_ID, Dimension.TOP_LEVEL_DIMENSION_KEY[1001]_ID,
Dimension.TOP_LEVEL_DIMENSION_KEY[1002]_ID,
Dimension.COUNTRY_CRITERIA_ID.

解决方法

Custom dimension key id其实就是自定义定向键(Custom Targeting Key)的ID,和你拿到的自定义字段ID不是同一个概念,获取途径如下:

  • 通过对应平台的API服务查询:比如使用CustomTargetingKeyService的get或query方法,拉取所有自定义定向键的列表,从中筛选出目标键的ID。
  • 后台管理界面查找:登录平台管理后台,进入自定义定向/自定义维度的配置页面,查看对应键的详情页,通常会直接显示ID。
  • 关联自定义字段查询:如果你的自定义字段和自定义定向键存在关联关系,可以通过自定义字段的详情接口,查看是否包含对应的定向键ID字段。

另外注意,文档里提到的customCriteriaCustomTargetingKeyIds就是代码中需要的customDimensionKeyId,二者是同一参数的不同命名表述。

内容的提问来源于stack exchange,提问作者Lakshmi_N

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 06:45:59