💡 Presently sponsored by: ScriptRunner
Get your free PowerShell Security e-Book!
In one of the projects I’ve been involved we’ve looked at various solutions for providing analytics to users, site owners and system administrators. Most services offer a great way for webmasters or site administrators to review how their site or system is being visited – but there’s few options for letting the users of your system review specific data themselves.
In order to get around this I built on top of the Google Analytics API’s, enabling my application to post queries for analytics data directly to the Google Analytics API. This enables (for example) a site owner to review data specific for his site.
In this post I will not outline the technical steps but will try to focus on the solution from an architectural standpoint. Should someone be interested in the steps for setting such a solution up, I may post that later.
SharePoint has a lot of built-in Analytics functionality already, so why would one want to integrate Google Analytics into your portal/intranet?
Well first off, SharePoint’s analytics isn’t even close to being as advanced as the Google Analytics service and there’s really no good way to compare the both. After conducting various studies and trial-and-error runs, the decision falls easily on Google Analytics.
Just remember that if you are to choose an off-site hosted solution for analytics (or anything else) the data flows over the internet. You should be very careful with what information you choose to push into the cloud, whatever the service.
A normal setup for Google Analytics looks like this:
In this type of setup, which most people use, the users of the system gets a client script loaded in their browser which then communicates with the Google Analytics service to store information. Then only the administrators of the Google Analytics service can access and review the data.
We want all users, without the need to authenticate or navigate away from the portal, to be able to review data for their specific sites.
Right, we’re running Google Analytics and we’ve had it integrated in our solutions for a while now – how do we enable not only GA Administrators to review analytics data, but also end-users in their own portal?
What we really want to achieve is this:
- Users should be able to see live analytics data of their own sites (Owners)
- Users shouldn’t need to have an account in Google Analytics (ponder that you’ve got many thousands of users, you wouldn’t want to manage that…)
- Users should have the data easily accessible from SharePoint
Custom WCF Service as a Google Analytics API wrapper
I made a decision to wrap the Google Analytics API’s through a custom WCF service where I can expose the specific analytics queries we want to enable for the users. By doing this, we can have our custom service take care of the following:
- Authentication toward the Google Analytics API’s
- Contains a set of specific methods to request very specific queries only - This makes it impossible for the user to hijack the request and alter it, should there be a genius out there..
- Takes the current Site Url as a property for filtering the GA request, only returning data relevant to the specified site url
- Enable REST-formatted queries for easy jQuery requests in JSON format
The logic of the solution ended up something like this:
- User navigates to a custom Page in SharePoint, just like any other
- The Page has a jQuery script to request information from our custom WCF service
- The WCF service first handles authentication et al, then passes on the query to the GA API’s
- The WCF service, upon receiving the response from Google Analytics, returns the data in JSON
- The jQuery Page handles the JSON response and neatly pushes it into the Page for the user to review
By utilizing the stand-alone WCF service we could get rid of all the clutter of authentication, configuration and processing of the GA API service and only focus on exposing WCF Methods for the tasks we need, hence enabling a pretty neat asynchronous interface through jQuery for the users.
The Site Owners are obviously happy because they don’t have to send a ticket or request information from the system administrators as soon as they want to review some data about their sites.
The Administrators don’t have to handle requests for enabling site owners to see their statistics.
And yes, with this solution we enabled a ton of features that the built-in tools couldn’t handle and we didn’t have to buy any of the expensive third-party offerings for this.
Everyone’s happy, which makes me happy!