Blog

Author Archive

Using the Google Analytics API with C Sharp

Wednesday, February 15th, 2012

We’ve recently launched the latest version of The BMC website (http://www.thebmc.co.uk) and we’ve had some great feedback. One of the ideas to motivate and incentivise the staff to write articles was to provide analytics for each article right in the CMS. That way they could easily see how popular their article was without having to trawl through google analytics every time.

As the site is written in ASP.net web forms I went straight to http://code.google.com/apis/analytics/docs/mgmt/v3/mgmtLibraries.html to look for a c# library which at the time of writing this is still in beta. I ran into a few problems getting everything to work out of the box. Here is what I did to get everything running smoothly

OpenAuth 2.0

With version 3 of it’s analytics api Google strongly pushes you to use OpenAuth 2.0, there is already a mature library which google uses in it’s samples – DotNetOpenAuth to do the leg work. Unfortunately I was getting the follwing error when trying to redirect to gain authorisation;

DotNetOpenAuth.Messaging.ProtocolException was caught

Message=Precondition failed.: !authorization.AccessTokenExpirationUtc.HasValue || authorization.AccessTokenExpirationUtc < DateTime.UtcNow || authorization.RefreshToken != null

Thanks to the following thread http://code.google.com/p/google-api-dotnet-client/issues/detail?id=174 I established I needed to add

response.Headers["Location"] += “&access_type=offline&approval_prompt=force”;

to the outgoing request, this would force the refresh token to be added to the response.

Retrieving Data

Now that I could authenticate the application I could start querying analytics for data. I soon ran into a problem with the ReportResource.GetRequest.Dimensions property, internally it’s converted into a List<string> but that conversion fails with.

Newtonsoft.Json.JsonSerializationException was unhandled by user code

Message=Error converting value “ga:date,ga:pagePath” to type ‘System.Collections.Generic.IList`1[System.String]‘.

The only way I could get it to to work was to copy the Google.Apis.Analytics.v3.cs to my project and stop using the pre compiled dll. I then changed the Dimenstions property and dimensions field of the QueryData class to type String rather than IList<String>

As I said this file is generated from Google’s services so it is only a temporary solution.

As these c# libraries are only in beta hopefully these kinks can be ironed out soon.

Exciting Office Move and SEO

Wednesday, November 16th, 2011

Once again it’s time for us to up sticks and relocate the HQ of Evolutia. To be fair we’re not moving very far (over the road) and we’re still saying in the same science park – Manchester Science Park that we have grown up in, still it’s a logistical nightmare. This will be the third office we have moved in to, and that’s the beauty of staying in a business/science park, they can accommodate your growth (or decline) without having to move very far.

From the small office we started in with just three of us and a shared 28.8k baud dial up modem we are now twelve mighty web warriors. The biggest reason for the increased rate of growth is our SEO side of the business. We’ve just launched a dedicated site – http://www.evolutiaseo.co.uk which features our new branding (which we’ll hopefully incorporate into this site soon). Initially we weren’t too keen to offer SEO as a service, but we found that we couldn’t find a partner company that matched our expected level of customer service and professionalism.

Now we have a dedicated SEO team we’re getting some excellent results for our clients and it’s a great complimentary service. We’ll continue to grow our SEO team and we’re really excited to be offering a whole new range of services to our clients.

Mooving to jQuery

Tuesday, September 13th, 2011

JavaScript frameworks are a godsend. Before we had the likes of Prototype, MooTools and jQuery doing anything in JavaScript was tedious and painstaking. So tedious and painstaking that unless it wasn’t anything more complicated than hiding an element I probably wouldn’t have bothered.

Image of cows, barely relevant © Joost J. Bakker

Then along came the frameworks, no longer did we have to check what browser and version the user was running, we could just code once and be happy forever. Well, almost. Even today when adding options to a select box I still have to wrap a non IE friendly statement in a try block to make it cross platform. But, still, it’s a massive improvement.

For no reason other than it was the first framework I really stumbled upon, I’ve been using MooTools since version 1.something, and it’s awesome. The abstraction for cross browser compatibility aside, it’s got a a load of functions that make doing fairly complicated effects, ajax calls and UI improvements a piece of cake. It also had also built on ProtoType’s OOP style inheritance into something that appealed to me coming from that background. Which brings me to jQuery.

I had obviously heard of jQuery and it always seemed the more popular sibling to the unappreciated MooTools, but every time I though about turning to the dark side I wasn’t convinced. I’d have a cursory glance at the API and seeing that it still wasn’t based on ‘classes’ like MooTools, I’d turn away in disgust. Now of course there’s nothing that MooTools can do that jQuery can’t and it does really come down to personal preference in terms of what style you prefer. Yes one framework may be faster for certain operations, but we’re talking slight differences and I imagine they’re all much of a muchness overall.

However we have decided that from now on all future projects are going to use jQuery as the framework of choice. Why did we decide to do this now? Aside from nasty conflicts with ASP.net web forms JS library (which I don’t blame the contributors of MooTools for, but then equally they aren’t doing themselves any favours by refusing to look at it currently), I think the weight of community support and speed of development releases has finally shifted the balance to such an extent that jQuery is now the only sensible option. A quick completely non-scientific example.; searching StackOverflow for “mootools” gives you 2,860 results, “jQuery” brings back 112,207. Now I know that’s just one source and it’s not exhaustive, but still it’s a large difference. Which framework am I going to get more help on when I need some pointers, or which framework will I be able to easily get some UI components to use in my next web app?

So for these reasons we’re giving MooTools the hoof, it’s a shame really as I much prefer its class based API and layout. Now looking forward to learning a whole new framework and all the fun that entails!

 

how to contact us
t: 0161 868 0008
e: enquiries@evolutiadesign.co.uk

Evolutia Design, Williams House,
Manchester Science Park, M15 6SE
or we will call you