Google analytics API - how to create new account - google-analytics

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.

Related

Is it possible to create Service account and get p12 key programmatically for google accounts?

I need to extract Google Analytics data through it's API. However I do not want to generate any account and key manually (the reason is I do not want to let this technical this to be performed by any non-techie person) and want to dump that data for analysis purpose.
In order to use any of Googles APIs they need to know who you are. You as a developer are identified by the project you create on Google Developer console. Once the project is created you can create a number of different types of credentials including Service account credentials and Oauth2 Credentials.
Answer: No there is no way to programmaticlly create service account credentials. Nor is it possible to use the a Google api without first creating a project on Google developer console.
Note: Google Cloud Resource Manager does exist but is very limited in what it allows you to do.
If someone else is going to be running your application to access their Google analytics Data you should idealy be using Oauth2 in your application and not a service account.
Service accounts are designed as way for the developer to grant others access to data owned by the developer in question. They are not really intended for novice users to be creating their own projects on google developer console and generating credentials.
You are basically asking if you can obtain the credentials necessary to query the API via the API. This does not work.
I am also not sure how this would help you. Before you can do any API operations to a Google Analytics account you need to have an authorized user (e.g. a service account) added to your view or property. If you are in a situation where you can add a user programmatically to an account you might as well just read the data you need.

Is it possible to integrate google analytics dashboard to our own website?

I want to show google analytics dashboard to my users. It is not possible to give access of "google analytics dashboard" to all users. So I want to integrate it on my own website. Will it be possible to integrate google analytics dashboard on a particular website?
This question gets asked quite a bit. It is important to understand the security model for the API. All Google APIs use OAuth2.0 to authenticate the user. This is designed to make it easy to use the API to access the Users's data on behalf of the user. In contrast you will need to do work to show Your data to your users.
With that said, an example of what you are looking for is the Server side Auth example provided by the Analytics API team.
The simplest answer is to query the API on the server side, with a service account and serve that data as you serve any other data to your users. Read the scenarios in detail, and pick one that best suits your end goals. Understand how the API views the following entities.
A User uses an application.
A Developer develops Application.
An Application has a project id and its associated credentials.
A user authorizes an application to access their data via the API.
You are breaking this paradigm because you are the user and developer from the API's perspective. You want to share your data with people who are not authorized to view it, so you will need to use a service account to access that data and share it directly with your users.
Also remember to add the service account to Analytics View you wish it to access.
Check out EmbeddedAnalytics if you prefer not to get bogged down learning oAuth2, the CoreReporting API, and lastly a charting tool. We simplify the process. All you do is create your chart and embed a snippet of code in your site where you want the chart/dashboard to show.

Google Analytics API: Create a new profile

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.

Google Calendar API integration

My scenario is the following: We currently own an online rental marketplace that uses peer to peer bookings just like Airbnb. This means each user has a calendar for their property.We have a Vaway calendar for the bookings on our site however are wanting to integrate google calendar so we can be able to 2 way sync/asynchronous all the Ical calendars to each other from our partner sites who support it.
After much research I have tested my personal google calendar to see how the iCal works and it seems to work perfectly so we decided this architecture would need to be implemented on a much larger scale. This would be used in all new users signups to give our users an all in one calendar that syncs all our Partner sites into one completely synced google calendar for their listing. This basically allows a user who has their listing on 7 different platforms to sync to one calendar showing availability for them to keep track of inside Vaway account.
The google calendar would be completely separate from our Vaway calendar specifically to allow our users to sync all their property bookings from other sites into one integrated calendar.. The problem when reading about google calendar API is it requires OAuth 2.0 which is required user sign in from their existing google account (Calendar, Gmail...etc). Many of our users and new signups will not have google accounts and we do not want them to have to go through a google signup process to log into their calendar. Is there any way around OAuth 2.0? We really just need the functionality of the google calendar and its syncing capabilities inside our dashboard to give read write permission and sync back and forth 2 way with other calendars on other platforms.
With all of the features the google calendar has it seems to be perfect for what we are doing when testing. Each user that signs up with us will have google calendar in their Vaway dashboard provided by vaway however they will manage their own google calendar inside the Vaway platform for their property bookings. All calendars events/bookings would be public to allow the Ical syncing option to push through.
We do not want the users accessing this calendar outside of the platform because the pulls them away from the site. I'm not sure what solution would best suit this business model and am totally at my wits end here after researching. We are trying to keep our overhead low so google apps marketplace is not an option.
You really should reformulate your question, because it's really hard to read and understand right now.
But if I really get your question, you want to enable managing google calendar from a personal application without the end user having to log to any google personal account.
If this is clearly what you want to do, I suggest you to have a look to Service Account with OAuth2.0.
(See here : https://developers.google.com/accounts/docs/OAuth2#serviceaccount)
It will provide a service account for your application, from which you will be able to handle calendars for your app.
And here you will find a sample showing how to do it with Java. (https://code.google.com/p/google-api-java-client/wiki/OAuth2#Service_Accounts)

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