Mohanraj
Mohanraj

Reputation: 97

Accessing Google analytics api using api key

I'm trying to implement Google analytics API using API key to make it available without authorization. But i can get examples using CLIENT ID in google developer console itself. Can anyone help me with an example using api key?

Upvotes: 0

Views: 4706

Answers (2)

MarkeD
MarkeD

Reputation: 2631

Google Analytics' EmbedAPI will allow you to display your Google Analytics via javascript, and users will be able to log in on page.

You will still need to get your clientAPI, but then users will be able to login independently.

The javascript code is described in the dev guide and a sample is below:

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

    // Step 3: Authorize the user.

    var CLIENT_ID = 'Insert your client ID here';

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

The API limit should be no problem, its 50,000 calls per day.

Upvotes: 0

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117146

It is not possible to access Google Analytics API with the API key. You must use Open Authentication.

If you are trying to access your own data you can use a service account. Create new credentials choose Service Account.

You can then take the service account email address:

1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp@developer.gserviceaccount.com

Add it as a user at the ACCOUNT level it is very important that it be at the ACCOUNT level it wont work other wise. Your application with then be able to access your Google Analytics data with out a log in.

Without knowing what language you are working with I cant give you any examples.

Update:

If as you say you are planning on doing this with JavaScript then you will have to go with Oauth2 and request access. There is no way to use a Service account with JavaScript.

There for I strongly recommend that you find a server sided programing language to do this in. Even if it did work with JavaScript you would end up running out of quota on the API before to long.

Upvotes: 1

Related Questions