solimanware
solimanware

Reputation: 3052

How To Expose Google Analytics Realtime Active Users To Public

I want to embed real-time Google Analytics active users number within my web app

Here how it looks on Google Analytics dashboard -the number changes real-time with actual active users now-:

enter image description here

What I need is to put this number on my web app.

But the API is a bit weird: it gives "you" (with google account authorization) just this access

gapi.analytics.ready(function() {
  /**
   * Authorize the user immediately if the user has already granted access.
   * If no access has been created, render an authorize button inside the
   * element with the ID "embed-api-auth-container".
   */
  gapi.analytics.auth.authorize({
    container: 'embed-api-auth-container',
    clientid: '1061030166084-94nlg92ep9aejnepvggfr72pkg4h2lnc.apps.googleusercontent.com'
  });
  /**
   * Create a new ActiveUsers instance to be rendered inside of an
   * element with the id "active-users-container" and poll for changes every
   * five seconds.
   */
  var activeUsers = new gapi.analytics.ext.ActiveUsers({
    container: 'active-users-container',
    pollingInterval: 5
  });
});

So how can I expose this real-time number to "public" as an app download promotion

Upvotes: 0

Views: 1217

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117146

"public" as an app download promotion

I am not sure I understand what you mean by download promotion.

However here are a few things you should be aware of. There is a limit to the number of requests you can send to this API per day per view. That limit being 10000 requests per day. This quota limit is across the view across all applications so if the user has your web app installed looking at their real time data and they have mine installed looking at their Google Analytics data we are sharing the 10000 requests. If you do this you are going to quickly blow out the quota for your users. In which case they wont be able to request anymore data for the rest of the day.

Assuming that you are only displaying the real-time google analytics data for your own web site. What you should be doing is having a service run in the background that runs every five minutes or something and gets the current count then you can display this stored count to all your users rather than making requests for each of your users.

You may want to consider doing this using a service account as you wont have to worry about authentication then. Note: Service accounts dont work with JavaScript you will need to use a server sided language for this.

Upvotes: 1

Related Questions