Setup and configuration

Choose a platform for configuration details:

Android

If your project does not already have a file called
AndroidManifest.xml in the <YOUR PROJECT
ROOT>/Assets/Plugins/Android/ directory, build the project for
Android and then copy the AndroidManifest.xml from the
Temp/StagingArea/ directory (it will be under the
directory you chose to build in). Paste it into <YOUR PROJECT
ROOT>/Assets/Plugins/Android/.

Add the following permissions to the
AndroidManifest.xml in <YOUR PROJECT ROOT>
/Assets/Plugins/Android/ above the
<application> tag:

If you prefer to have the libraries automatically added when building
for iOS, copy the file PostProcessBuildPlayer_GA from the
iOS Extras directory and put it in the <YOUR
PROJECT ROOT>/Assets/Editor directory.

Download the mod_pbxproj.py
script and copy it into the Editor directory. The
libraries will now be added automatically during the build.

Note: libsqlite3.dylib
is only required if using the -ObjC linker flag in Xcode and
can be safely removed from the PostProcessBuildPlayer_GA
file if you are not using this flag.

Configure the GAv3 prefab

The following steps are required to configure the GAv3 prefab:

Click on the GAv3.prefab prefab object, which can be found in
Assets/Plugins/GoogleAnalyticsV3 in the Project
View.

The Inspector view will display a Script
component attached to the prefab with several properties listed.
Populate these properties with the correct values for your project. This will
populate the object so that it can be used everywhere in your project. For
example:

Android Property ID: UA-XXXXXXX-1

iOS Property ID: UA-XXXXXXX-2

Other Property ID: UA-XXXXXXX-3

App Name: MyGame

Bundle ID: com.example.games

App Version: 1.0

Dispatch Period: 5

Sample Frequency: 100

Debug Mode: VERBOSE

Anonymize IP: false

Dry Run: false

Drag the populated GAv3 from the Project view up into the
Object Hierarchy.

Track an object

After configuring the GAv3 prefab you're ready to start
tracking an object using Google Analytics by following these steps:

Identify a GameObject you wish to track (for example, a
Player object) and click it in the Object Hierarchy view. If
you do not already have a script attached to the object that you want to
track then create a new script using the Add Component button
in the Inspector view.

Create a public variable in the class to hold the GoogleAnalyticsV3
object. For example:

public GoogleAnalyticsV3 googleAnalytics;

Save the script and return to the Unity window.

In the Inspector view for the GameObject
you wish to track, you will see the script you created and a field to populate
called Google Analytics (or the variable name you chose). Drag the
GAv3 object from the Object Hierarchy view
onto the field.
If you do not see the field to add the
GAv3 prefab, check to make sure there are no compile errors
in your script. The Inspector will not update if there are
existing errors.

You are now ready to start tracking that GameObject.
Repeat the process for other objects you wish to track using the same prefab.

Next steps

Review the API Reference to
learn what kind of hits you can send to Google Analytics.