Google Community Connector 指标与维度显示异常求助
问题解决:Google Community Connector 指标全部显示为维度
核心问题出在代码的指标创建逻辑里:在遍历reportConfig.metrics时,你错误调用了fields.newDimension()方法,而非fields.newMetric(),这直接导致所有本该是指标的字段被创建成了维度。
修正后的代码片段
reportConfig.metrics.forEach((metricConfig) => { // 把 newDimension() 替换为 newMetric() fields.newMetric() .setId(metricConfig.id) .setName(metricConfig.name) .setType(getCCMetricType(types, metricConfig)); });
额外检查点
- 确认
UrlFetchApp.fetch返回的响应已正确解析为JSON对象:原代码中reportConfig是HTTPResponse对象,需要先调用getContentText()再转成JSON,否则遍历会出错:const response = UrlFetchApp.fetch(schemaUrl, params); const reportConfig = JSON.parse(response.getContentText()); - 验证
getCCMetricType函数返回的是Looker Studio支持的指标类型,比如types.NUMBER、types.PERCENT、types.CURRENCY等,避免返回维度类型(如types.TEXT、types.DATE)。
内容的提问来源于stack exchange,提问作者user2119405
相关产品推荐
相关产品推荐

