Reputation: 53
The issue I'm having is when I try and insert a new web property using the Google Analytics Api I'm getting the error: "reason": "insufficientPermissions", "message": "Your project does not have access to this feature."
This is even when I use the page: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/insert
Has anyone being able to successfully create a new web property and return its tracking code?
Upvotes: 5
Views: 2035
Reputation: 4374
If you are looking for create property api solution for GA 4 then you could try as follows :
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);
}
More details can be found under
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
Upvotes: 0
Reputation: 116918
At the time that this question was written, write operations were still in beta. At the time, it was required to request access to the beta. From the GA documentation at the time:
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.
After applying for the beta, developers were unlikely to hear back from GA, but after 24 hours it normally worked.
Upvotes: 4