NOTE: Google Analytics has officially released a similar Unity plugin today, only 2 years after we released ours GitHub - googleanalytics/google-analytics-plugin-for-unity: Google Analytics plugin for the Unity game creation system
Hey guys - we at Mass Threat recently launched 50 Ways to Survive on iOS/Android and are pleased to report itâs already a top ranking app in many countries! We couldnât have done it without Unity3D and its awesome community of developers who share their knowledge and hard work with others.
During the dev process for 50 Ways we created a simple lightweight plugin to report data to Google Analytics, in order to receive realtime stats about our app after we launched. Flurry is a great solution to mobile analytics, but itâs missing that oh-so-cool realtime element.
Free Download:
GoogleAnalyticsPlugin.unitypackage - v0.1
So, what is it?
In 2012 Google Analytics introduced support for Mobile Apps (iOS / Android), which offers all of the great features of web analytics but with nomenclature suitable for mobile and a concept of âscreen viewsâ and events as opposed to webpage visits and the like. Google released great SDKs for both iOS and Android, and weâve been using them with much success in our non-game applications.
However - despite offering great SDKs for native iOS and Android apps, there was no good way to use Google Analytics Mobile within a Unity3D game. We have built a plugin that allows you to easily report what screen your players are on within Unity3D, using one line of code. Our solution is very lightweight and utilizes Unityâs native WWW class to report the data to Google.
This is a plugin for Google Analytics more recent addition of âAppâ analytics. You must create an app property in Google Analytics, not a regular website property.
At Mass Threat we utilize a range of analytical tools in our games, including Flurry - and while Flurry works great for collecting event-based data, generating reports and quickly finding gameplay trends, it does lack certain features that we had grown so accustom to when managing our web-based properties. For example, Flurry does not have native support for city / state-level geographic data (you would need to perform your own user location lookup, and report the data to Flurry), nor does it have the type of neat realtime stats weâve grown to love so much with Google Analytics.
Because our implementation of Google Analytics is lightweight and only allows you to log screen views, we would still recommend using Flurry as a supplemental solution. Having Google Analytics in our games affords the ability to quickly glance and see realtime player data (whoâs doing what) and a much more granular look at geographic trends. We still utilize Flurry to gather information about player hardware and other more complex metrics.
Installing the Plugin
Download the Unity Package from the above URL, and import it to your project. âGoogleAnalytics.csâ contains everything you need to get started reporting your data to Google. In order to initialize the plugin, create an empty GameObject in your Unity3D scene and call it âGoogleAnalyticsManagerâ or similar. Next (this is the important part), attach the GoogleAnalytics.cs script to your empty GameObject.
The GameObject you place this script on will persist throughout the session, which makes the plugin available across all scenes. Take care to add the GameObject to a loading scene or initialization scene, so that it will be ready for usage across your entire game.
Once youâve added the script to your GameObject, you will be able to configure the script to match your Analytics credentials.
Property ID - You can find your property ID by visiting the âAdminâ panel of your application within Google Analytics.
Bundle ID - Specify your bundle ID here.
App Name - Specify the name of your application - the same as would appear beneath your gameâs icon on a playerâs homescreen.
App Version - Your current app version.
Implementation / Usage
Once youâve setup the plugin as described above, logging screens to Google Analytics is easy. The code below will report that the user is on the âMain Menuâ screen.
// Reports that the user is viewing the Main Menu
if (GoogleAnalytics.instance)
GoogleAnalytics.instance.LogScreen("Main Menu");
Think about what your game consists of in terms of âscreensâ - in our case we normally log each gameplay level as a screen (i.e., âLevel 12â), and also log anytime a GUI dialog of any meaning is displayed (i.e., âLevel 12 - Player Deathâ or âPowerups Menuâ)
The Result
Once setup, you will be able to access great realtime data such as users online, geographic location and more. Weâve found that itâs much easier to identify player trends (and possible problems) by monitoring realtime usage.
Known Limitations
- iOS traffic (iPhones/iPods/iPads) will show as âDesktopâ, while Android traffic will be accurately separated into either Mobile or Tablet. For reliable device stats, we utilize Flurry.
- As mentioned above, for analytical heavy lifting we still utilize Flurry, as it handles metrics in an industry-standard way. Additionally, Flurry will gather data from offline devices and report it once the user goes online. This plugin does not.
- This plugin will report the viewing of âScreensâ, it does not currently have a method for âEventsâ (events will accept key/value data, whereas Screens accept a single string) - again, for deep event data we recommend using a full-fledged mobile analytics suite like Flurry.