Google Analytics API 创建新属性
我遇到的问题是,当我尝试使用 Google Analytics Api 插入新的网络媒体资源时,我收到错误: “reason”:“insufficientPermissions”, “message”:“您的项目无权访问此功能。”
即使我使用以下页面,也会出现这种情况: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/insert
有人能够成功创建新的网络媒体资源并返回其跟踪代码吗?
在撰写此问题时,写入操作仍处于测试阶段。当时,需要请求访问测试版。来自当时的 GA 文档:
Write operations in the Management API (e.g. create, update, delete, patch) for Web Property, View (Profile), and Goal resources is currently available as a developer preview in limited beta. If you're interested in using these features, request access to the beta .
申请测试版后,开发人员不太可能收到 GA 的回复,但 24 小时后它就可以正常工作了。
如果您正在寻找为 GA 4 创建属性 api 解决方案,那么您可以尝试以下操作:
const property = {"account":"accounts/123","displayName":"displayName","currencyCode":"USD","propertyType":"PROPERTY_TYPE_ORDINARY","timeZone":"America/Los_Angeles","parent":"accounts/123","industryCategory":"INDUSTRY_CATEGORY_UNSPECIFIED"};
// Imports the Admin library
const {AnalyticsAdminServiceClient} = require('@google-analytics/admin').v1alpha;
// Instantiates a client
const adminClient = new AnalyticsAdminServiceClient({keyFilename: credentialFile});
async function callCreateProperty() {
// Construct request
const request = {
property,
};
// Run request
const response = await adminClient.createProperty(request);
console.log(response);
}
更多详细信息请参见
https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1beta/properties#Property
https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1beta/properties/create