How a list of all a users Google analytics views - javascript

I have many Analytics properties and accounts.
I am now working on JavaScript to get the reports from the Google Analytics API.
In order to make these requests I need the view idea for the account i wish to access so that i can load the related data from the backed.
The only way i have found to find these view ids is to use the Official GA Query Explorer every time to get the id by selecting Account and Property.
This is quite annoying. Because it involves human action.
Is there any way I can look up the id by the UA-xxxx string?

If you are already using the Google Analtyics API to get the reports why not use the Management APi to get a list of all the accounts the user has access to
Account summeries.list will give you that.
I am not a Javascript developer but the code should be something like this.
function queryAccounts() {
// Load the Google Analytics client library.
gapi.client.load('analytics', 'v3').then(function() {
// Get a list of all Google Analytics accounts for this user
gapi.client.analytics.management.accountSummaries.list().then(handleAccounts);
});
}
Code shamelessly ripped from Hello Analytics API: JavaScript quickstart for web applications and altered a bit using a wild guess.

Related

Seeking decent documentation on creating a way to link a Google account with my app

I'm trying to develop a react native application that won't require a user to sign into a bunch of different services every time. For now I'm trying to get the google side of things setup where a user can click a button which will allow me to link my application to there Google user account so that when they next visit the app the don't need to log into google for the functionality to continue to work.
I'm having a hard time finding documentation about how this link can be set up but I have found this page on Google which suggests it's possible.
https://myaccount.google.com/accountlinking?hl=en-GB&pli=1
The idea would be a bit like last.fm handles Spotify. a simple login and approve the service will mean that last.fm can listen to the Spotify account without requiring further auth every time its doing said functionality.
I can't find much in terms of tutorials or documentation on this specific thing.
Google OAuth and Scopes
It sounds like you're looking to implement Google identity federation in your app - specifically, OAuth 2.0. Google gives you quite a few options depending on the complexity of your authenticated user experience.
As for permissions, the Google API documentation calls these scopes. Here's a list of all the available scopes for every Google API. Setting scopes can take a few additional steps depending on which Google apps/information your app needs access to. By default, the Google API scopes for a new project are email, profile, and openid. Here's a video explaining how to view and modify the scopes in the Google API console(mentioned below).
1. Google Sign-in Button with scopes
The simplest method would be to follow this guide from Google which explains how to set up Google Auth on the frontend.
In short, you first set up a project within the Google API Console. Create a new project and take a look at your project scopes by clicking the Credentials tab, then the OAuth Consent Screen tab. Then back in your frontend code, include a script tag to call the Google API related to authentication functionality. Next, include a meta tag containing the client key found in the Google API Console. Then just create a sign in button with a certain class and data attribute(mentioned in the guide) and users should be able to sign in. This will return a small amount of user data in your code which you can use for validation within your app.
2. Firebase with scopes
A more complex solution would be Firebase authentication which returns even more user data, the use of a database to save and retrieve data related to the user and their session, and many other handy features that would normally be time consuming to develop. As such, Firebase is often called a backend as a service(BaaS).
To get the same level of granularity of scopes as the standard OAuth scenario outlined above, you may need to use a combination of the two as described in this article from Fireship.io.

Downloading Google Analytics Data By Client_id

I'm allowing users of my site to download their google analytics data at their free will for transparency sake and I don't want to deal with CCPA requests for data myself.
I'm using Node.js as my backend and was wondering if it's possible to download google analytics by client_id. I'm using a service account for my google console access.
If there's some documented api endpoint that I'm not seeing that would help a lot.
Sure you have, it came in for that purpose
The User Activity API allows a Google Analytics property owner to
retrieve all analytics measurement data associated with a single user.
Specifically, the API retrieves all of the measurement data associated
with a particular User ID or Client ID.
https://developers.google.com/analytics/devguides/reporting/core/v4/user-reporting

Show unique/returning user count on my website

I am working on the admin dashboard of my website and I was wondering if there is a way to display unique or returning user count.
Can I link/fetch my google analytics return value in any way possible.
This way the admin does not necessarily needs to go to Google Analytics, simply logon to the website and have the information readily available.
If you need historical data i think that the easiest way to do that is using the embed api
https://developers.google.com/analytics/devguides/reporting/embed/v1/
With that you can create easyly some chart to be embed on you html page, if yu can handle you can use the api.
Now,If you want to do it with the realtime report( the analytics module), it's not possible, because that metric is not available on that plataform

Access Google Analytics API via javascript with service account

Title pretty much says it all - I need to access Analytics data for a site, using the Javascript API and authenticating via a service account. Is this possible, if so, how? Have spent hours running in circles in the Google docs to no avail.
I'm looking to build a dashboard to publically display stats for the site, hence the need for the service account.
Javascript is a must - I need a completely client-side solution.
Any ideas?

Use Google Analytics custom events for feedback form

I was thinking of having a simple feedback form in my website.
It would be something like:
Your Feedback will help us improve.
[ ]
and then a textfield/textarea where the user can type (let's say) up to 100 characters of feedback.
Rather than handling it all myself on the server-side I was thinking to use Google Analytics (since my site is already wireup) and every time a user writes a comment, send a custom event to google analytics.
I think it might work.
Can people suggest a better approach or point out any problem with this idea?
There are a few problems with this.
First of all, it's against the Google Analytics Terms of Service to pass personally identifiable information to Google Analytics (#7). So, if you were to want to collect their feedback, you legally could not collect their name or email address without risking your account getting shutdown by Google.
Second, this is not at all what Google Analytics is for; its for collecting aggregate traffic and site interaction data. There's no easy-to-use interface for viewing long-form text information; I'm not even sure how you'd view event information thats longer than a few words.
Finally, Google Analytics sends its information in URLs, and there are size limitations to URLs (in Internet Explorer), and so Google Analytics will be default truncate any request with more than 2048 characters, meaning that your data will not collect accurately for longer feedback forms. (EDIT: Google Analytics recently raised this cap to 8096, by configuring the requests to use POST when >2048 characters.)
There are lots of free and easy to use data and form collection tools. Google Docs, for example, connected with Google Forms, can collect this data for you with ease. Then there's Wufoo, SurveyMonkey, UserVoice...I could go on forever.
Don't use Google Analytics for this. It's a bad idea with no upside.
Google Analytics events weren't made for gathering user feedback. Aside from the impracticalities of using the analytics console to view feedback, GA uses JSON to pass event information (which has size restrictions).
Why not try out uservoice.com or suggestionbox.com?

Categories

Resources