Google Analytics Embed API authentication - google-analytics

I'm looking at getting some stats out of Google Analytics using the Embed API to display on our site using javascript.
My question is:
Is it possible to display the stats without the user authenticating? I.e. I would like to make some traffic statistics available to anonymous users.
Thanks,
Chris.

This is definitely possible, but you'll have to get the access token yourself (server side, using whatever OAuth 2.0 flow you want).
Once you have a valid access token, you can pass it to the gapi.analytics.auth component and use the Embed API as normal.
Here's some documentation on that:
https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#auth
UPDATE: (07/27/2015)
A demo of server-side authorization with the Embed API is now featured on the Google Analytics Demos & Tools site. You should look there to see a working example.

Related

How can I use the Google Analytics API to pull GA Account Change History?

I want to be able to pull the Change History report from Google Analytics... any ideas/help would be much appreciated!
*It looks like the AdWords API offers this function, but I need it for the Analytics API
You can't. The relevant API for this would be the management API, but that does not list a function to get the account history, so you do not have programmatic access to that.
You could probably write a script using a bowser automation framework like Selenium that logs into Google Analytics using your own credentials, navigates to the account history, downloads the HTML content of the account summary page and then parses it to extract the desired information, but that would not involve the Analytics API at all (and is nothing that can adequately described in a Stackoverflow answer).

Google API javascript

I am doing a custom google map with API
I put the URL link :
https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|label:C|40.718217,-73.998284&key=AIzaSyCTFUKmdIRSSod5v1oqhIXJOmkOPMsdFp0
I received this error:
The Google Maps Platform server rejected your request. This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/static_maps_backend?project=_
I enabled API AND THE error still exist
Can you please help me find the solituion for my problem
In order to use the Google maps api your going to have to first off enable the maps api in the Google developer console for that project. Then you will need to enable billing for the project as there is no longer a free tear for maps api.
Once you have done that you can create an api key and use it in your code.
The Google Maps Platform server rejected your request. This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/static_maps_backend?project=_
This message means that you have not enabled the maps api for your project. It can take a few minutes before it kicks in if you just enabled it. Make sure you have done it for the cogrect project as well by clicking on the link that it showed you.
You are going to need maps javascript API for a real map and embed it in a div
Here is a basic example on how to achieve that.
In the script tag in the html section you need to replace YOUR_API_KEY for the real one from google.
jsbin example
https://jsbin.com/xiragigegi/edit?html,css,js,output

Google analytics using REST api

I want to add Google analytics manually on each pages and events in my website. Is there any ways to add Google analytics using REST api or any library in PHP. so i can track specific events of my website.
There is no REST API for Google Analytics. You will have to use one of the available libraries provided by Google.
To track particular events, you can use tag manager or simply use custom dimensions.
TL;DR, Google Analytics is great if all you ever use is their GUI dashboard. If you need API access, go with another service.
If you need to access analytics data programmatically, especially if you are using NodeJS, I suggest you use some other service besides Google. Their documentation is incredibly lacking, they try to pigeon-hole you into using a client library rather than steering you in the direction of a REST API, and authenticating is a nightmare. The new v4 API purportedly consists of a single endpoint that you need to query with a complex combination of HTTP body and query params. Again, documentation is nearly non-existent.

Google Maps APIs sometimes requires domain verification?

I maintain a WordPress store locator plugin, and this week someone told me it wasn't working anymore. Eventually he fixed it by verifying his domain in the API Console.
That this was a solution to some APIs of Google Maps not working was new to me, and it's also the first time someone told me they fixed it this way.
The problem is that I can't find any information in which scenario verifying your domain fixes a Google Maps API related problem. I read through the Geocode API / Google Maps JavaScript API / Google Places API Web Service pages, but no where do I see something about the need to verify your domain ( I could of course have missed it ).
Does anyone know when you need to verify your domain if you want to use the Google Maps APIs? Normally it works fine without doing it, but in his case it wasn't, and I really like to know what he could possible have done to make it a requirement.
You shouldn't need to verify the domain for using Google Maps API.
You need to generate one API Key for your app so you can use it when you call the Google Map JavaScript API like this:
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>
Substitute the value YOUR_API_KEY for the one that Google generated for you.

Allowing user access to analytics

I would like to enable (some) of my users to view my website's analytics data.
Our website has a bunch of groups where users can add content. I would like to enable certain users (group admins), to view usage statistics for that specific group. Ofcourse the data should only be accessable to those users with the VIEW_ANALYTICS right, not to any others.
Is there any way to do this in Google Analytics, or is there some other platform I could use to easily achieve this goal (we use AWS for our hosting)?
Regards,
klmdb
The Google Embed API allows you to display analytics data in your own pages. Pages that are only accessible to the members of your VIEW_ANALYTICS group.
You can create a service account and give it the appropriate access in the analytics user management for the property.
You also authorize the service account to use the embed API in the developers API console. (I don't have enough points to include more than two links in an answer.) In the API console you can generate a private key (p12 or json format) which you then use on your server to authenticate the request for analytics data.
You don't say which technologies you are using, but they show Java and Python examples of how to set up the authentication by the Service Account. I've also seen some node.js and php libraries.
This way you don't have to manage who has access through the google anayltics admin system, you just need to control who has access to your "dashboard" page.
I have done this all with client-side javascript and it works. Of course the client-side nature means that anybody who knows how to use browser debug tools can get our private-key, but in our particular case I'm not worried about it. On the other had it seem like you need to keep some security around this so I wouldn't recommend the client-side solution.

Resources