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

使用Google Tag Manager REST API创建带过滤器触发器报错

Google Tag Manager REST API 创建触发器报错排查

错误信息

Unable to parse trigger data com.google.analytics.containertag.common.CtApiaryException: trigger.filter[0].parameter[1]: Filter's second argument must be string.

原请求负载代码

const body = {
                accountId: googleTagManagerAccountId,
                containerId: containerId,
                workspaceId: workspaceId,
                name: `Bla bla PageViews Disabled JS - ${domainUrl}`,
                type: 'pageview',
                tagFiringOption: 'somePageViews',
                filter: [
                    {
                        parameter: [
                            {
                                type: 'template',
                                value: '{{ my Variable }}',
                                key: 'arg0',
                            },
                            {
                                type: 'boolean',
                                value: 'false',
                                key: 'arg1',
                            },
                        ],
                        type: 'contains',
                    },
                ],
            };

问题原因

错误提示明确指向:过滤器的第二个参数必须为字符串类型。你使用的contains属于文本匹配类过滤器,这类过滤器要求所有参数的类型必须是template,但你将第二个参数(arg1)的type设置为了boolean,即便value是字符串格式的'false',类型声明不匹配仍会导致API解析失败。

修正后的代码

将arg1的type改为template即可解决问题:

const body = {
    accountId: googleTagManagerAccountId,
    containerId: containerId,
    workspaceId: workspaceId,
    name: `Bla bla PageViews Disabled JS - ${domainUrl}`,
    type: 'pageview',
    tagFiringOption: 'somePageViews',
    filter: [
        {
            parameter: [
                {
                    type: 'template',
                    value: '{{ my Variable }}',
                    key: 'arg0',
                },
                {
                    type: 'template',
                    value: 'false',
                    key: 'arg1',
                },
            ],
            type: 'contains',
        },
    ],
};

补充说明

Google Tag Manager REST API对不同类型过滤器的参数类型有严格要求:文本匹配类过滤器(如contains、equals等)的参数都必须声明为template类型,无论传入的是变量引用还是固定字符串,这样才能保证API正确解析参数格式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 20:25:02