Last week we published a short blog post, proudly announcing the release of our SDK for Google Analytics tracking of the new Apple tvOS on GitHub. This Swift library (and soon-to-be Objective-C library) connects any app written for Apple tvOS to Google Analytics, allowing insights into user behavior and UX usage and measure cross-device behavior.
Now that Apple has opened up the world to the creation of any app on Apple TV for any business, we at Analytics Pros have opened analytics tracking on tvOS for the first time, ever. TV shows, movies, music, shopping—everything is possible on tvOS, and is all trackable in Google Analytics with our code library.
The new Apple TV and its brand new tvOS operating system for the first time allows developers to build and release apps easily. The existing Google Analytics SDK for iOS does not work for tvOS leaving no publicly available solution for Google Analytics—until the Analytics Pros library.
Tracking User Behavior
What do users view, read, buy, or where do they stop in the funnel on an iPhone, vs the Apple TV at home? If you own a video app like Hulu, or retail like Amazon, or online publishing like The New York Times, users can use your apps on many devices during their day. They may start on their iPhone to start viewing or purchasing, and then go home, turn on their Apple TV, and continue viewing again or complete a purchase. With the Analytics Pros tvOS library, it’s now possible to track user activities across devices based upon their user id.
The ability to track user behavior in-app is very important because you can measure app engagement, answering questions like: How long do users spend in the app? What countries are they coming from? When you know these answers you can inform your marketing spend and formulate strategy. You can also improve your UX and UI, understanding what features people like, what screens they view most and why, where they get stuck, and which app features are being used the most. You can also connect Apple TV to other parts of your marketing mix, like web, Android, or iOS. Cross-device tracking helps you build invaluable attribution models and in turn better attract and serve your customers.
Installing the Library
So, how do you actually install the library? We’ve put together a step-by-step guide to help in the installation process.
All the code for the Apple tvOS Google Analytics wrapper is located inside a single file GATracker.swift.
The first step of the implementation is adding the GATracker file to your project directory. Once the file is accessible the application needs to initialize the singleton object with the following call in the app delegate’s applicationDidFinishLaunchingWithOptions:
GATracker.setup("<GA PROPERTY ID>")
Once the object is created your application can start sending hits to the property that was specified.
Once the tracker is set up you can start sending Google Analytics hits from your Apple TV application.
When sending the screenview hit type, the screenname parameter is a required field.
GATracker.sharedInstance.screenView("FirstScreen", customParameters: nil)
When sending the event hit type, the event category and action are required fields
GATracker.sharedInstance.event("category", action: "action", label: nil, customParameters: nil)
When sending the exception hit, the exception description and exception “fatality” are both required parameters
GATracker.sharedInstance.exception("This test failed", isFatal: true, customParameters: nil)
Sending Additional Parameters
With each hit you are also able to send additional parameters as specified in the Measurement Protocol reference. Examples include: “non interactive hit”, “event value”, “custom dimensions”, “custom metrics” etc.
In the following example we will add custom metric values and set this event hit as non interactive. The example shows how to send a video progress hit that includes video name as custom dimension 1, video author as custom dimension 2 and sets the event as non interactive (since this event is not a result of user interaction).
GATracker.sharedInstance.event("Video", action: "Progress", label:"50%", customParameters: ["cd1":"Incredible Video", "cd2":"Amazing A. Uthor", "ni":1])
As mentioned before you are able to use any measurement protocol parameters inside the customParameters dictionary. https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=en
Sending Other Hit Types to Google Analytics
Screenview, event and exception are not the only hit types available in Google Analytics, to send a different hit such as a transaction, item, social or timing hit use the send function.
In the following example we will send a transaction hit with transaction id 10001 and transaction revenue of $425,00.
GATracker.sharedInstance.send("transaction", params: ["tid":"10001", "tr":"425,00", "cu":"USD"])
At Analytics Pros, we love what we do and are experts at implementing connected device analytics. We’re releasing more and more libraries to support your needs, and are eager to be your source for analytics excellence as you use Apple tvOS to create apps for your amazing business. Please contact us at email@example.com for any questions, and for all of your consulting needs.