We need to show the number of visits for pages of our website. We already use GA for general reports and we assumed that it might make sense to use GA API to get number of visits data from GA instead of building our own counters and increase load to our database and web server.
I read documentation and already know how to build queries that I need. The main problem I'm trying to work around right now is an authorization process. Sounds like if we use OAuth 2.0 each user has to authenticate before he/she can see the statistics on the page and they will have access to statistics of their websites (if they have them registered with GA). In our case this is incorrect, everything we need is just to show our own GA stats at our own website. Easy task as we thought initially but it doesn't sound like that anymore.
Is there a way to authorize our website to Google (like we send come credentials when we use Maps API) and show stats automatically to any user? We wanted to implement it on client side via JS but if this is possible to implement it on server-side only - that's OK. The target platform for server-side implementation is ASP.NET (just in case). Can someone point us in the right direction?
Quite a few options:
You can use OOCharts and a script like this
Use a service like embedded analytics (paid)
Use SeeTheStats and it's widgets
Use google charts and JavaScript
Use explanium to embed a ga chart
Piwik can embed charts too.
Related
I need to implement a system (www . mydomain .com) where users can register to get a custom JS snippet and embed it on their website (www . userdomain .com). This snippet displays a widget on their site (www . userdomain .com) and performs some other actions as well.
I need to collect page views which users can view by signing-in to their dashboard on mydomain .com, so I figure there are 2 ways:
using an image pixel element which has its src attribute set to mytrackingscript.php. This script will receive a request when the image element loads and thus I can store the metrics in DB.
Something like this:
Instead of using image pixel, I make an XHR request to mytrackingScript.php and save the metrics to DB.
I understand there would CORS restrictions coming in place with the 2nd approach, and I would have to allow CORS for my site.
My questions:
Is the first approach preferable to the second approach
If I enable CORS, are there security implications, given that I would be doing so(enabling CORS) only for that script and it would be just writing the metrics to DB and not interacting with any critical data?
I realize that either of these approaches can be used for tracking page views, but if I need to collect more data which requires periodically connecting to the DB (eg click events and other user interactions with the widget), can this be done using the first approach?
I am thinking along the lines of reloading the image pixel src at regular intervals would server the purpose by connecting to the script periodically?
Are my assumptions correct?
And very importantly, do I need to even write custom code for this? Can I use Google Analytics tracking pixel for this? The flow I want is:
1. users A and B register on mydomain, and get a JS snippet and embed on their sites userdomainA and userdomainB
2. snippet displays a widget on their sites and tracks the activity on the sites
3. A and B can login to display their dashboards on mydomain.com/dashbaord and see the analytics for just their domains i.e userdomainA and userdomainB respectively
Is it possible to achieve this use Google Analytics? I have not used Google Analytics much so I thought I'd ask
Thanks.
I have a static blog using Jekyll hosted on GitHub. I have set up Google Analytics for it and works well enough.
Now I want to show how many people viewed each post in my blog. I found Google Analytics JavaScript API to get the information. But it seems that this API uses OAuth for data access. So I think this might not be the API I needed.
Is it possible to do so with Google Analytics? I don't have any server since it's hosted on GitHub.
I finally solved this problem by Google Analytics superProxy as suggested in the comment of #EikePierstorff.
I wrote a blog on it.
Here's the main idea.
I first build a project on Google App Engile, with which I authenticate for the access of my Google Analytics. Then a URL of query (which can be pageview of certain pages) is generated in JSON format. I can set the refresh rate on this GAE project so that the JSON file can be updated from Google Analytic.
Sounds almost perfect to me. Thank you all guys for help!
You can't query the Google Analytics API without authorization by someone, that's the most important thing to remember.
It's certainly possible to display Google Analytics data on your website to users who don't have access to your account, but in order to do that, someone with access to the account needs to authorize and get an access token in order to run queries.
Normally this is done server side, and once you have a valid access token you can query the API client side (to display charts and graph, etc.). Access tokens are typically valid for 1 hour, so if you want to have your website up all the time, you'll also have to deal with refreshing the access token once it expires.
Now, since you're using Github Pages and don't have a back end, which means all the authorization will need to happen client side. While it's technically possible to do the same thing client side as server side, it's generally not a good idea because private data like your client secret, refresh token, etc. will be visible in the source code.
Applications that do auth client side typically don't authorize on behalf of a user. They require the users themselves to go through an auth flow for security reasons (as I just explained), but that would mean those users 1) have to log in, and 2) can only see the analytics data they have access to, which probably isn't what you want.
--
What you can do is run reports periodically yourself and export that data to a Google Spreadsheet. Google Spreadsheets allow you to embed charts and graphs of data as an <iframe> in external pages, so that might be an option.
At the end of the day, if you can't authorize server side you'll have to come up with some kind of workaround to make this happen.
Here are a few possibly helpful links that might point you in the right direction:
https://developers.google.com/analytics/solutions/google-analytics-spreadsheet-add-on
https://developers.google.com/analytics/devguides/reporting/embed
https://developers.google.com/analytics/solutions/report-automation-magic
I am looking at developing an app to leverage the Google Doc side of Google Apps Scripts. I have a couple of questions about the security of Google Apps Scripts.
How easy is it for a user to copy the code from a shared Google Apps Script? Is there any way to prevent this?
Are there any plans to create a similar API for the Google App Engine for manipulating Google Documents( not just listing what documents are available) so that document manipulation could be done on the server side?
Is there a way planned to share out Google Apps Scripts per Google User or per group, and not just "Publish to the World" or "Within a domain" as is currently the case?
Thanks
Bob
About copying the shared script: dont share it there is no need to share. Publish as webapp and share the url. Nobody can get to the script that way.
About opening the api: no plans that i know of (im not from google), but note that apps script does run server side.
The last one: publish to your domain and run as owner, then in your handler (Roget) use user services to tell the active user email. Use group services to see it she belongs to a group. If user shouldnt access show an access error.
Voila.
I want to retrieve page views for my website using the google api. I need to use the core reporting API to do this:
https://developers.google.com/analytics/devguides/reporting/core/v3/
I want, on page load, to pull down data about page views for my website. At the moment I'm having problems seeing how to achieve this without first needing to manually authenticate the user (via a popup asking for a users google credentials). I don't want this - I simply want to retrieve some data for a given Google analytics profile.
I've generated a client id and an api id and am ready to go but can't find a clear example of how to query the api in the way I need.
Any ideas where in the documentation I can find what I need?
I wish to access Google Analytics data through their API using Javascript.
Basically I want to display on a website a list of the most visited pages for the past week/month. I can only use javascript for this.
I found this example on the official site http://code.google.com/p/google-api-javascript-client/wiki/Samples#Google_Analytics_API
Is there any way of accessing Google Analytics data without authentication? Do I need to somehow load a username/password in? To be clear, I want a website (that has Google Analytics tracking) to load analytics data from its own account.
I thought there might be a way to make certain data public, then query that somehow... Or perhaps create a limited user to access it. I can find no examples of either.
You can't access GA withouth authentication for rather the same reason you cannot access you bank account without authentication (because that would allow everybody else to access your account without authentication which might cause some inconvenience).
Google provides a complete example for GA access via Javascript: https://developers.google.com/analytics/solutions/articles/hello-analytics-api. However I don't think that's what you want (I think for that you need to be logged in to Google to actually retrieve data).
You could however use Google Apps Script to pull data into a Google Spreadsheet and embed that into your page (at least I think that should be safe).
Updated: Google has since released the Google Analytics superProxy which allows to share Analytics data with the public safely.