Management, Reporting, and SwiftUI

Ok, Where were we. Aah, yes, the Google Analytics Reporting API. The goal for the last two weeks was to hack my way through the reporting API and fetch user’s data. I’m pleased to say that endeavor has been successful 🥳. It has not been plain sailing (like always) but, I got there in the end.

Reporting and Management

The Google Analytics Reporting API has two supported versions, v3 and v4 with Google explicitly recommending developers to use v4 for all new projects. I, being not someone to go against explicit advice chose v4 but, here’s the caveat, v4 uses something called a viewId to headline all queries. There is no documentation on how one can programmatically get this viewId, with the Query Explorers all still linked to v3. So, I check the documentation of “all things analytics” to find that viewId can be obtained through Account Summaries in Management API. This API, instead of being a standalone service that supports multiple versions is deeply embedded in Google Analytics API. We now have to link the whole of Analytics Pod of Google APIs Client Library for Objective-C for REST to just access that one method from Management API, Phew! 

Aside from my exasperations, I understand why it is that way. A core component of software APIs’ is backward compatibility, and rewiring the Management API to work equally well with the new Reporting API could break v3 code without a significant duplication. I commend Google for supporting legacy APIs’, it’s just that they have to make the path easier through documentation in cases like this. Anyway, I got the viewId and used it to build my query and execute it on the Reporting API. The library makes this process seamless and the fetched data checked off my goal 😂.

SwiftUI

I’ve also spent a considerable amount of time trying to display the GA Accounts in a progressive table view, and achieving that in SwiftUI has been an exciting task. I’m starting to love SwiftUI’s declarative user interface style and it’s been a pleasure building table views (Lists in SwiftUI) with it. The delegates and data sources of the old table view no longer exist and updating data from async calls’ is impossibly easy, I’m enthused to get my hands dirty now. I definitely have to thank Paul Hudson and his SwiftUI by Example tutorials for helping me understand and implement the SwiftUI code.

What Next?! 

I’m at a stage where I’ve hacked together enough code to know that the app I want to build is feasible on the Google APIs’ front. I now have to research on WidgetKit to see the possibilities of configuration and flexibility I can offer a user. I’m going to spend the next two weeks researching the levers available in WidgetKit and design the v1 for the app. I will also whip up a widget to show the last 7 days page views (or) users for this website, That should allow me to get my hands dirty with WidgetKit.

Until next time, Cheers!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.