
At some point in the development of your game project there is a need to collect statistics on it. After all, this will allow us to understand what a player does, how a player thinks while using our game and will give us the opportunity to refine some moments, point us to things that annoy a player, show that he likes and much more.
And here comes the choice of which analytics system to choose. Our choice is quite decent: our own development of Unity, Google Analytics, Appat, Flurry, Localitycs - and this is only a small part of the systems that are available to us. Who wants to know for what reason the analytics system from Google was chosen and how to work with it, please under the cat.
System selection
So, we see such a large variety of analytics systems, but I have taken Google Analytics, so why?
')
There are a lot of reasons and here are the main ones :
- There is an assembly under Unity3D
- Good documentation
- Simple API
- Free
- Work with PC
And now we can sort things out by points so that it becomes much clearer :
- Build under Unity3D is always great, no need to “dance with a tambourine" and write something extra to work with the plugin. Not every analytic system can boast of such a thing, but the most famous one has such a thing.
- The documentation is done at a very good level, everything is counted on 2 web pages, the setting and further work with the plugin are explained intuitively and clearly. Other systems either do not have documentation specifically for an Unity3D assembly, or it is there, but leaves much to be desired.
- C API can be figured out even without going into the documentation, that's all that can be said here. Other plug-ins based on a lot of additional things to work with the plugin, which this system does not have analytics.
- As for the price, everything is simple, Google Analytics has a limit on the number of tracking per month, 1 million, a very decent figure, especially if your application does not have a multimillion audience, then this will be quite enough, but if your application is one, then will have to mess with google. Other analytics systems cannot offer this, usually their limit on the number of tracking is much less, or some tracking functions are not available, i.e. can not track purchases, etc.
- There is nothing to disassemble at this point, many analytics systems may simply not work with PCs and are intended only for mobile platforms.
Now it’s pretty clear what this analytics system was chosen from, and now we can proceed to the plug-in integration phase in our application.
Integrating Google Analytics into a project
The first thing to do is download our plugin from the repository and this is what we see:

We are only interested in a few things: this is actually GoogleAnalyticsV4.unitypackage, the file from the iOS Extras folder and from the source folder is the library for Android.
So, importing files from Google Analytics V4.unitypackage, upload the file from the iOS Extras folder to the Editor folder in the Assets root, this file will be needed for compiling for iOS, which I’ll tell you about later and from the source / Plugins folder copy the Android folder to the Plugins folder, without this The library will simply not work on the Android platform.
And now a little about compiling for iOS. The file that we transferred from iOSExtras is necessary for the libraries needed for the plugin to be automatically connected, but we also need mod_pbxproj.py, which is also downloaded from the repository, the link to which is in the Google Analytics documentation. It also needs to be placed in the Editor folder. Now all the necessary libraries will be connected automatically, but you need to take into account that this will work only when you are compiling from under Mac,
otherwise the libraries will need to be manually connected to the project .
Libraries to connect :
- AdSupport.framework
- CoreData.framework
- SystemConfiguration.framework
- libz.dylib
- libsqlite3.dylib
To set it up for Android, we still need to modify the manifest file, adding the following lines after the tag:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
With the import of files into the project and their configuration is finished, now let's move on to the settings inside the project and start with the prefab GAv4.prefab, which is located along this path:

I will tell only about the basic settings that we need and these are:

Android Traking Code - the code of the application that you receive, when creating an application in Google Analytics, you can use both the code for the application that you created in your Unity account and purely for Android
IOS Traking Code - the code of the application that you receive when creating an application in Google Analytics, you can use both the code for the application that you created in your Unity office and purely under IOS
OtherTraking Code - the code of the application that you receive, when creating an application in Google Analytics, you can use only the code for the application that you created in your office under Unity
Product Name - the name of the product that you specified when creating the application
Bundgle Identifire - application identifier by type com.company.name
Bundle Version - application version
A little bit about tracking codes. You can create one application to track immediately from all platforms, or you can create a separate application for each platform. Codes have the form UA-XXXXXXX-1.
These are the basic settings that need to be specified, the rest can be gathered from the documentation, because they are not so critical for the operation of the plugin.
It remains only to transfer the prefab to the scene and you can get to work. Everything is pretty simple here, I’ll give just one script as an example that describes the whole essence of working with Google Analitycs.
using UnityEngine; public class Analitycs : MonoBehaviour { public GoogleAnalyticsV4 componentAnalitycs;
That's all, now you can safely work with the analytics system. If it’s interesting to work specifically with Google Analytics personal account, I can write a separate article, but I don’t think what I need, everything is painfully simple and intuitive.