Google Analytics API: Create a new profile - google-analytics

Is it possible to create a new profile via the Google Analytics API?
This way we can automatically register the tracking when we have new landingpages created.
I am curious if anyone is working with an automated way of automatically setting up GA tracking.

Yes! The Google Analytics Management API has changed... As you can see from the documentation, available methods for profiles are delete, get, insert, list, patch and update.
You can even insert new Web Properties, but beware of the 20 properties per account limit.

No - the Google Analytics Management API is read-only. As you can see from the documentation, the only available method for accounts, properties, and profiles is list.

Related

How do I create audiences in Google Analytics 4 using an API?

Google Analytics 4 allows new custom audiences to be created:
I want to do this programmatically through a web API, but I can't see any documentation. Is it possible to create audiences in Google Analytics 4 using an API?
Google have confirmed that "the creation of audiences is not yet supported in Admin API" and have raised a feature request. They've not given a timeline for implementation but suggested following the Google Analytics API Notify group for future updates.
I need to remember that even after this feature is implemented in the GA Admin grpc API, it will also need to be supported in the .NET client library that I'm using, so there will take some additional time.
Not sure when added, but...
Web API:
https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties.audiences/create
.NET client:
https://googleapis.dev/dotnet/Google.Analytics.Admin.V1Alpha/latest/api/Google.Analytics.Admin.V1Alpha.AnalyticsAdminService.AnalyticsAdminServiceClient.html#Google_Analytics_Admin_V1Alpha_AnalyticsAdminService_AnalyticsAdminServiceClient_CreateAudience_Google_Analytics_Admin_V1Alpha_CreateAudienceRequest_Grpc_Core_CallOptions_

Define Google Analytics 4 custom dimensions via API

Is there a way to programmatically define custom dimensions using the Google Analytics Admin API (that works with GA4)?
I'm talking about defining the dimensions ahead of time so I can send them along with events, which is what you'd manually do in the Google Analytics user interface (under All events > Manage Custom Definitions). This is what I'd like to do programmatically. Once they're defined, sending these custom dimensions along with tracking events is easy enough (using gtag).
Apparently, this was possible in the previous version of the API, but that API says that it "does not support GA4 properties".
You already can programmatically define/create custom dimensions and metrics with the Google Analytics Admin API for GA4 properties.
Custom dimensions
Can be created with this method providing:
description
displayName
parameterName (it hasn't need to exist beforehand)
scope (User or Event)
Custom metrics
Can be created with this method providing:
description
displayName
measurementUnit
restrictedMetricType
scope (Metric_Scope_unspecified or Event)
Warning from Google: This is an early preview version of the API and
is subject to change. While we will try to notify you of upcoming
changes, you should expect to encounter breaking changes before the
APIs are publicly released.
Jan,
You are correct that the Google Analytics Management API V3 cannot be used to configure GA4 properties. The Analytics Admin API V1, which supports GA4, does not currently have methods to create custom metrics/dimensions.
I will update this question once we have more information on when this feature can become available.
Thanks,
Ilya
The Google Analytics Team

Google analytics API - how to create new account

Okay, some heads-ups as I feel I'm an idiot and missing some simple stuff. As far as I understand Google Analytics works with a 3 tiers system: account -> property -> view. and I should be able to manage these 3 levels via the google analytics management api.
For some context as to why I encounter this issue. I am making a CMS in which I want to register a new google analytics account per user, and a property per website this user has. (implementation and usage of views out of scope for now, I will implement those on a later date). To achieve all of this I started following Google's documentation on the Google Analytics Management API (according to Google this is what manages accounts, properties and views). Therefor I have made a service-user-account which should have enough permissions to manage GA-accounts.
However I can't seem to be able to create a new account via the API. Am I missing something obvious? Is it not possible at all this way? If so, how then? Because my goal is to have GA on every website, without the user having to config anything.
You can't do it. The management API only allows for the list operation on accounts: https://developers.google.com/analytics/devguides/config/mgmt/v3/account-management#account_summaries
The only solution would be to use the Provisioning API. It can be used to create new Google Analytics accounts and enable Google Analytics for your customers at scale: https://developers.google.com/analytics/devguides/config/provisioning/v3/
Anyway, the Provisioning API is currently available by invitation only.

It is possible to create a script for generating new sites on a google analytics account?

I need to create a script (php for example) to generate new sites on a google analytics account.
I need to obtain the ID of the generated site.
¿It is possible to do it? How can i achieve it?
Thanks
No. All of the Google Analytics APIs are read-only. The only way to create new accounts is manually.
As #jk added below, from the Google Analytics Management API docs:
Google Analytics provides developer access to the configuration data
through the Management API, which is a read-only API for account and
configuration data.

How can I generate a GA tracking code programmatically?

How to generate Google Analytics tracking code programmatic-ally?
I am new to Google Analytics API, can someone please help
It is NOT possible to create new Google Analytics accounts or profiles programmatically using the existing APIs.
There are two APIs available, the Data Export API and the Management API. However, they are bot read-only.
With the Google Analytics Data Export API, you can develop client applications to request data from an existing Analytics profile for an authorized user, and refine the results of the request using query parameters. Currently, the Data Export API supports read-only access to your Google Analytics data.
Currently, the Management API supports read-only access to five components of the Google Analytics Management system: Account data,Profile data, Web property data, Goal data, Advanced segments
Seems like it's finally possible in 2021 with alpha api.
https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties/create#authorization-scopes
It's not currently possible to create Google Analytics accounts automatically at the moment but generating the tracking code is possible.
The only real variation between the tracking code generated each time you create a profile for a new domain is the web property ID. This is in the format UA-XXXXXXX-X. Each X is a number - the first 7 numbers are the account number and the number after the last dash relates to each web property set up for the account.
You can use the accounts feed of the API to get a list of accounts and their profiles. If an account only has one profile then it's possible to use the web property ID of it to automatically generate the tracking code. However, if there's multiple web properties then you would need a way to decide which one to use (present the user with a selection list etc).

Resources