如何在AnalyticsAdminserviceClient(GA4)Nodejs上修复Update_mask.Paths错误?
我尝试使用nodejs中的Google Analytics Admin Client(GA4)更新“ DatarEtentionSettings”,但是我收到以下错误。
Error: 3 INVALID_ARGUMENT: One or more values in the field 'update_mask.paths_list' was invalid, but all values must be valid.eventDataRetention, resetUserDataOnNewActivity
at Object.callErrorFromStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
at Object.onReceiveStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\client.js:189:52)
at Object.onReceiveStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:365:141)
at Object.onReceiveStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:328:181)
at C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\call-stream.js:187:78
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
code: 3,
details: "One or more values in the field 'update_mask.paths_list' was invalid, but all values must be valid.eventDataRetention, resetUserDataOnNewActivity",
metadata: Metadata {
internalRepr: Map(1) { 'grpc-server-stats-bin' => [Array] },
options: {}
},
note: 'Exception occurred in retry method that was not classified as transient'
}
代码如下。
const analyticsAdmin = require("@google-analytics/admin");
class Main {
constructor() {
this.analyticsAdminClient = new analyticsAdmin.AnalyticsAdminServiceClient({
keyFilename: "./mykeyfile.json",
});
}
async updateDataRetentionSettings() {
const name = "properties/*********/dataRetentionSettings";
const request = {
dataRetentionSettings: {
name: name,
eventDataRetention: "FOURTEEN_MONTHS",
resetUserDataOnNewActivity: true,
},
updateMask: {
paths: ["eventDataRetention", "resetUserDataOnNewActivity"],
},
};
let retention = {};
try {
retention = await this.analyticsAdminClient.updateDataRetentionSettings(request);
} catch (e) {
console.log(e);
process.exit(1);
}
return retention[0];
}
}
const client = new Main();
client.updateDataRetentionSettings();
我还将“名称”添加到UpdateMask的路径属性中,结果是相同的。
这是我提到的文档。 nofollow noreferrer
“
如何通过API更新DatarEtentionsettings?
I tried to update "DataRetentionSettings" using Google Analytics Admin Client(GA4) in Nodejs, but I got the following error.
Error: 3 INVALID_ARGUMENT: One or more values in the field 'update_mask.paths_list' was invalid, but all values must be valid.eventDataRetention, resetUserDataOnNewActivity
at Object.callErrorFromStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
at Object.onReceiveStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\client.js:189:52)
at Object.onReceiveStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:365:141)
at Object.onReceiveStatus (C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:328:181)
at C:\my_working_path\GA4_manager\node_modules\@grpc\grpc-js\build\src\call-stream.js:187:78
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
code: 3,
details: "One or more values in the field 'update_mask.paths_list' was invalid, but all values must be valid.eventDataRetention, resetUserDataOnNewActivity",
metadata: Metadata {
internalRepr: Map(1) { 'grpc-server-stats-bin' => [Array] },
options: {}
},
note: 'Exception occurred in retry method that was not classified as transient'
}
The code is as follows.
const analyticsAdmin = require("@google-analytics/admin");
class Main {
constructor() {
this.analyticsAdminClient = new analyticsAdmin.AnalyticsAdminServiceClient({
keyFilename: "./mykeyfile.json",
});
}
async updateDataRetentionSettings() {
const name = "properties/*********/dataRetentionSettings";
const request = {
dataRetentionSettings: {
name: name,
eventDataRetention: "FOURTEEN_MONTHS",
resetUserDataOnNewActivity: true,
},
updateMask: {
paths: ["eventDataRetention", "resetUserDataOnNewActivity"],
},
};
let retention = {};
try {
retention = await this.analyticsAdminClient.updateDataRetentionSettings(request);
} catch (e) {
console.log(e);
process.exit(1);
}
return retention[0];
}
}
const client = new Main();
client.updateDataRetentionSettings();
I also added "name" to the paths property of updateMask and the result was the same.
Here is the document I referred to.
AnalyticsAdminServiceClient
And the client version is 4.0.0.
How can I update DataRetentionSettings via API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要更新GA 4中的属性,然后您可以尝试以下尝试:
To update property in GA 4 then you could try as follows :
在C#中,
技巧是
request.updatemask = updatemask.paths
而不是request.updatemask = updateMask
。In C#,
The trick is
request.UpdateMask = updateMask.Paths
instead ofrequest.UpdateMask = updateMask
.