Fastest way to get basic information from google analytics api - google-analytics

My GA Account has a number(50) of profiles associated with it and I am trying to build an api which shows me the basic information like visits, bounce rates etc. for each profile.
This query gets me what I want from GA, but for each profile:
URL ="https://www.google.com/analytics/feeds/data?ids=ga:11111&start-date=2011-07-01&end-date=2011-07-02&metrics=ga:visitors&prettyprint=true&alt=json"
The id is table id and the metrics gives me the information I want.
Now the problem is, I want to show all the information together. So, everytime I will have to send 50 requests to the API, which just doesn't work out. Is there a way I can get the information for all the profiles associated with me in a single request?

You unfortunately will be required to perform 50 requests if you want metrics for 50 different profiles. You can easily automate this, however, by using a combination of the Management API and the Data Export API.
The Management API allows you to pull information about the account. For example, you can very easily pull all profile IDs and names associated with an Analytics account through this API for use in an automated query.
The Data Export API, which I am sure you already are familiar with, is the only way to pull collected data/statistics for individual profiles.
If you are concerned about speed, you might want to build an automated process that uses both the Management API and the Data Export API. Pull all of the profiles associated with your account with the Management API, then loop through each and pull the basic data you'd like through the Data Export API. Have this run at regular intervals based on your needs and cache it between runs. This way it won't execute every time the page is hit (though you honestly might be fine, depending on your traffic - I've found it to be extremely quick).

Related

Is there anyway to run Firebase realtime database queries with multiple keys?

I am working on a personal project to recreate the news feed of Facebook. So what I am trying to do is to recreate the scenario where when the user goes to the news feed, the user gets posts of everyone he follows only. Is there any way to run a query like that using the Firebase real-time database using an of "followings".
I can successfully generate single users posts in the android studio app using snapshot and recycler view.
If you're asking whether you can get posts from multiple userUID values with a single query, that is not possible.
If you're asking whether you can pass a list of postUID values to retrieve, that is also not possible.
In both cases the solution is to execute a separate query/read operation for each of the values, and merge the results in your application code. This is not nearly as slow as you may think, since Firebase pipelines the requests over a single web socket connection - which is quite efficient. For more on this, see Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly

Firebase - Perform Analytics from database/firestore data

I am using Firebase as my authentication and database platform in my React Native-Expo app. I have not yet decided if I will be using the realtime-database or Firestore database.
I need to perform statistical analysis on daily data gathered from my users, which is stored in the database. I.e. the users type in their daily intake of protein, from it I would like to calculate their weekly average, expected monthly average, provide suggestions of types of food if protein intake is too low and etc.
What would be the best approach in order to achieve the result wanted in my specific situation?
I am really unfamiliar and stepping into uncharted territory regarding on how I can accomplish this. I have read that Firebase Analytics generates different basic analytics regarding usage of the app, number crash-free users etc. But can it perform analytics on custom events? Can I create a custom event for Firebase analytics to keep track of a certain node in my database, and output analytics from that? And then of course, if yes, does it work with React Native-Expo or do I need to detach from Expo? In addition, I have read that Firebase Analytics can be combined with Google BigQuery. Would this be an alternative for my case?
Are there any other ways of performing such data analysis on my data stored in Firebase database? For example, export the data and use Python and SciKit Learn?
Whatever opinion or advice you may have, I would be grateful if you could share it!
You're not alone - many people building web apps on GCP have this question, and there is no single answer.
I'm not too familiar with Firebase Analytics, but can answer the question for Firestore and for your custom analytics (e.g. weekly avg protein consumption)
The first thing to point out is that Firestore, unlike other NoSQL databases, is storage only. You can't perform aggregations in real time like you can with MongoDB, so the calculations have to be done somewhere else.
The best practice recommended by GCP in this case is indeed to do a regular export of your Firestore data into BQ (BigQuery), and you can run analytical calculations there in the meantime. You could also, when a user inputs some data, send that to Pub/Sub and use one of GCP Dataflow's streaming templates to stream the data into BQ, and have everything in near real time.
Here's the issue with that however: while this solution gives you real time, and is very scalable, it gets expensive fast, and if you're more used to Python than SQL to run analytics it can be a steep learning curve. Here's an alternative I've used for smaller webapps, which scales well for <100k users and costs <$20 a month on GCP's current pricing:
Write a Python script that grabs the data from Firestore (using the Firestore Python SDK), generates the analytics you need on it, and writes the results back to a Firestore collection
Create an endpoint for that function using Flask or Django
Deploy that server application on Cloud Run, preventing unauthenticated invocations (you'll only be calling it from within GCP) - see this article, steps 1 and 2 only. You can also deploy the Python script(s) to GCP's Vertex AI or hosted Jupyter notebooks if you're more comfortable with that
Use Cloud Scheduler to call that function every x minutes - see these docs for authentication
Have your React app query the "analytics results" collection to get the results
My solution is a FlutterWeb based Dashboard that displays relevant data in (near) realtime like the Regular Flutter IOS/Android app and likewise some aggregated data.
The aggregated data is compiled using a few nodejs based triggers in the database that does any analytic lifting and hence is also near realtime. If you study pricing you will learn, that function invocations are pretty cheap unless of-course you happen to make a 'desphew' :)
I came up with a great solution.
I used the inbuilt firebase BigQuery plugin. Then I used Cube.js (deployed on GCP - cloud run on docker) on top of bigquery.
Cube.js just makes everything just so easy. You do need to make a manual query It tries to do optimize queries. On top of that, it uses caching so you won't get big bills on GCP. I think this is the best solution I was able to find. And this is infinitely scalable and totally real-time.
Also if you are a small startup then it is mostly free with GCP - free limits on cloud run and BigQuery.
Note:- This is not affiliated in any way with cubejs.

Querying Link Over REST API

I'm running a few car simulations using the HERE Routing REST API, and I'd like to be able to get the accurate speed limit for where the car is so that it doesn't go too quickly or slowly for the simulation.
I can see that the speed limit is included within a link.
However, I can't seem to find how to get a link given its Link ID, or if that's even possible with the current API.
In the old API it seems like there was a getlinkinfo.json endpoint which ought to do what I need, but using it on my current freemium account says that I'm unauthorized.
Is this a feature tied only to pro accounts, is it deprecated, or is there just some other way I have to go about this?
As mentioned in the comment above getlinkinfo.json from Routing API has been depricated for sometime now and the alternative is to use HERE Telematics Advanced Data Sets API (https://developer.here.com/documentation/platform-data/dev_guide/topics/quick-start-view-map-data.html) The data is split into different layers and tiles which could be queried for link attribute information.

Remote analytics tracking for multiple sites

I am trying to track some basic data from multiple domains (Monthly hits, Session length, etc). Each domain is owned by a client, and it is a business requirement for me to have access to their statistics.
I have the access needed to add in a tracking code to each domain, similar to GA's tracking code. Each of these should transmit data to my master server, which consolidates and stores the info.
What would be the best way to go about doing this? Is this sort of tracker best built from scratch, or is there an open source analytics provider which can meet this specific use case? (Many tracking end-points, single database)
I will be aggregating the visits, duration, etc for each user separately, so as to compare and rank them against each other.
Hello Sainath Krishnan,
In general terms, it all depends on how you want to see these data: whether you want to aggregate all the sites together, whether you want to see the users as only one across these multiple sites, and so on.
For instance, since you've installed the proper tracking code, which you administrate, on these site, you will be able to see all sort of traffic data that these tracking codes will send to your Google Analytics account and properties.
Could you be more specific regarding the way you want to see the data, or even if you'll deal with goals os specifics KPI's ?

How do the limits work for the Google Javascript Places Library?

I'm working on building my first web/mobile app with Meteor, using Javascript for both the client and server.
Essentially, the app will allow users to rate restaurants based on a variety of factors, such as how loud it is or how nice it smells. The averages of each of these attributes would then be stored in my database along with the Google ID of the associated restaurant. Other users can then search for places near them and sort the results based on any of the rated attributes.
So if a user requests a list of places and a request is made to the Google places library API, and then those places are matched against data in my database, how are the limits applied? Since the server is also running with Javascript, can I call the API with the server? And if I do, is the API able to distinguish between different users and apply the individual limits? Or if it's all coming from a single server will it give me a total limit equivalent to a single user?
Thanks for any help and guidance.
The Google Maps JavaScript Places Library does not have a documented limit. However, if you perform request that have gone over its request quota, you will get OVER_QUERY_LIMIT. So maybe the Javascript API Usage Limits can help you to know more about limits by using this API.
Check also this related SO ticket.

Resources