Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I restrict analytics embed api to display only one google analytics account

How can I restrict analytics embed api to display only one google analytics account. Right now I have three accounts showing up under dropdown.

like image 589
Rustam Aliyev Avatar asked Sep 09 '15 17:09

Rustam Aliyev


People also ask

Do I need a separate Google Analytics account for each website?

A given web property should only be tracked in one Analytics account. Tracking a single web property in different Analytics accounts is not currently recommended. You do not need to sign in separately for each Analytics account that you have access to.


2 Answers

As Philip Walton said, the viewselector will always show all accounts etc. And to have only one 'view' you will not need the selector and add the id to the chart data

As example, in case you would use the https://developers.google.com/analytics/devguides/reporting/embed/v1/devguide demo as a starting point. To have it show only one view, replace step 3 to 6 by:

<script>
gapi.analytics.ready(function() {

  // Step 3: Authorize the user.

  var CLIENT_ID = 'insert client id here';

  gapi.analytics.auth.authorize({
    container: 'auth-button',
    clientid: CLIENT_ID,
  });



  // Step 4: Create the timeline chart.

  var timeline = new gapi.analytics.googleCharts.DataChart({
    reportType: 'ga',
    query: {
      'ids': 'ga:insert view id here',
      'dimensions': 'ga:date',
      'metrics': 'ga:sessions',
      'start-date': '30daysAgo',
      'end-date': 'yesterday',
    },
    chart: {
      type: 'LINE',
      container: 'timeline'
    }
  });

    timeline.execute();


});
</script>

So you can delete step 4 and 6 of the original one and edit step 5 by adding ids: YOURVIEWID to var timeline. Afterwards add timeline.execute() to render the chart

The ids needed can be found by using https://ga-dev-tools.appspot.com/account-explorer/ and the needed id is displayed at the button under 'view'

like image 163
Pepe Avatar answered Oct 17 '22 07:10

Pepe


The Embed API's ViewSelector component is always going to show you a list of all your accounts, properties, and views.

If you know exactly what view you want to display data for, then you don't need to use the ViewSelector component at all, you just need to pass the view ID (ids) directly to the Report or DataChart components.

like image 3
Philip Walton Avatar answered Oct 17 '22 06:10

Philip Walton