How to query Google Analytics using Javascript - google-analytics

We're want to query Google Analytics remotely, to retrieve (and display) a list of most popular pages (in a certain period) on a website. The examples I've looked at, for querying Analytics using Javascript, seem to require an user/person to login. Is this correct? Is there a way of skipping this step, and querying Analtyics unattended?
Thanks,
Toby

No. the data inside Google Analytics is potentially strategic and the tool doesn't provide non-logged in access at any time.
In order to do what you want the best approach is probably to query the data using your credentials on the server side and store the data on a database. Run that again every night or so.
Then you just query the database and generate the count to display on the frontend.
You don't want to do that on javascript because you would be exposing your credentials to anyone visiting your site to query all your Google Analytics data.

Related

System design - Google Analytics

I'm working on the architecture for a project that includes a Android and iOS apps and a web interface with a subset of the mobile apps functionalities. The project is basically a e-commerce solution. In all three interfaces I'm using Google Analytics to track some information. However I'm having an internal discussion about the extent of the information I should send to GA. What should I store in GA and what should I store in my own server?
Let me give you some examples.
Session tracking is clearly something that belong to GA.
ProductDetailViews. Sounds like something that should go into GA, specially considering the enhanced e-commerce module.
Shared item. When a user shares some content over a social network, should I store that information on GA or in my own server? I'm inclined to GA but it becomes more ambiguos.
Do you see my point? Can someone share a general rule or recommendation on what should be saved in GA and what should be saved on the projects own server?
Thanks
For those examples I would generally send all the hits to Google Analytics. Here are a few reasons:
Preventing data silos. You want all of your data in one place and Google provides you with a database reachable via the API where you can keep all your data organised in one place. This is important when you are considering measuring performance, as you want to avoid duplication of conversions or traffic hits
Useage of Google Analytics advanced segments. With all your data in GA, you will be able to create advanced segments for analysis. But the real power is if you are using AdWords or retargeting, as you can send those Advanced Segments to AdWords, and target those users around the web with your custom data
Single point of reference for users All analytics are inaccurate, but you want to make sure they are inaccurate to the same degree. Using GA keeps all your data on the same playing field
Usability and Freedom of information Its easier to serve up your data to users within the GA interface as people are more likely to know how to navigate that than your database. You can also use the GA API to pull out any data you need to push into other visualisation tools.
User session merging With your data and userID tracking in GA, you may be able to track users as they arrive via mobile to desktop and back again, over multiple sessions.
What you need to avoid putting in to Google Analytics is personal info such as names, email address etc. There are against the TOS. But you can capture a unique userID, and match that outside of the tool later.

Accessing Google Analytics Reports using the API

I know how to use the Google API to access different metrics and dimensions to query for specific data. However, I am faced with a different scenario. I would like to know if there is any mechanism to access the reports/custom reports that are already created using the Google Analytics web user interface.
Our client has created about 15 different reports and now wants us to simply get the data into his own database rather than having to log into the Google Analytics website and run the report and export the data.
Can anyone please guide me on this?
Not sure if this is exactly what you are thinking, but you can always use the Reporting API to extract the data using python/javascript/etc and then store the data locally in your database. For more info, check out the Google Analytics Query Explorer and try out different combinations of dimensions and metrics to be able to extract the data. You can then use any number of different Core Reporting API Client libraries to access the analytics database.

Separate analytics for each profile page within a single website

There are multiple profiles on my website and each user is managing his/her profile himself. I am trying to find the most efficient way to present analytics of each profile to its owner. Here are 3 ways I found:
Record each and every hit made on a profile page against that profile. This is not just count of hits, this requires to record IP, country, referrer, search terms etc. against each hit. This would require me to manage a huge database as there would be a lot of hits on each page. And a lots of processing on this database. Even if I have to de this, what database is recommended for such use?
Use Google Analytics on each page. But I am not sure that Google Analytics provide an API to fetch Analytics for individual pages.
Use some open source solution like piwik. Again I'm not sure if they provide per page analytics or not.
Please suggest the pros and cons of using each approach.
Update: More explanation - Think of it like a facebook page where each user can see hits on his page. What solution you'd suggest?
For Piwik, you can create a site id for each user, because you are allowed unlimited site ids with Piwik. You can can use a tracker with that user siteid, so when your member logs in, they get data only on their pages. You might also want to look at using custom variables and use the Piwik API to filter data.
Check here for info on multi-tracker: http://piwik.org/docs/javascript-tracking/#toc-multiple-piwik-trackers

Can I present google analytics data to users within my application?

I'm creating an auction site and would like to provide my sellers with analytics related to their product pages - visitors, search terms, etc. I could roll my own analytics but want to know if it is possible (or forbidden) to use google analytics within my application and present that data to my users. Is this possible, has anyone done this and, if so, how did you go about it. Thanks in advance
Sure, you can do this.
The easiest method is to give your sellers direct access to GA. I have no idea how you have your GA interface setup but you can setup profiles in lots of different ways (filters, segments, etc..) to have the profile show data only for the specific seller, and give their GA account access only to their profile.
Alternatively, GA provides an API for retrieving data from them and displaying on your own site.
Also you can provides Real time data reporting via Google's Real Time API - https://developers.google.com/analytics/devguides/reporting/realtime/v3/devguide
Which will provide several data in the manner of dimensions and metrics

Google analytics api

I would like to have a div on my companies website that is filled with links to our most-visited pages dynamically by querying our google analytics account. From everything I've been looking at in the DataExport API though, it seems like the user viewing the site has to authenticate. Am I missing something?
This is correct: google analytics only supplies exported data to an authenticated user (you wouldn't want it otherwise after all, with your competitors peeking at your data, right?-).
You can run the application querying analytics separately, with all required authentication, and have that application supply such data selectively to "your company's website" with whatever level of validation you think is warranted (to avoid snooping competitors) -- if the exact subset of data that you supply (just most-visited pages, for example) is not sensitive according to your judgment, you may in fact get away without the "validation" part!-).
You could add a server side script that grabs your analytics data using the api and write some javascript that inserts it into the div.
There are a number of different client libraries for google analytics you could use.

Resources