GA4 Google Analytics for Unity

I’ve been a Web Analyst for marketing agencies for a decade as well as creating ios/web/mac/pc Unity Apps freelance. I ran into this asset, and I have to say it’s one of the most important assets on the entire asset store.

Why GA?

  • Google Analytics is the #1 way to measure analytics on user actions, period. Just by sheer market share, it is the most used analytics product. Almost every website on the entire internet uses it.

Google Analytics upgraded to a new version called “GA4”:

  • GA4 treats data completely different than it’s previous version (called Universal Analytics, thats now deprecated).

Why this asset?
This plugin is the only working connection between Unity and Google Analytics (4). Not even Google itself has a working Unity to GA4 plugin.

A quick rundown on why GA is amazing is below:

  • Public Dashboards Creation: Utilize Google’s Looker Studio to create accessible, comprehensive dashboards. This free tool by Google allows developers to not only track in-game economics but also establish leaderboards for a variety of events, dimensions, and metrics.
  • In-depth Analytics: The dashboard serves more than a mere monitoring tool; it enables players and developers to drill down into metrics to determine the “king of the game” across multiple parameters. This feature not only enhances user engagement but also ensures daily traffic due to continuous updates and leaderboards.
  • Seamless Integration: The asset provides a smooth, hassle-free integration process with Unity, allowing developers to focus more on development and less on backend complexities.
  • Real-Time Data Processing: GA4 supports real-time data processing and visualization, which is crucial for making timely decisions based on player behavior and game performance.
  • Advanced User Segmentation: With GA4, you can segment users more precisely than ever before, enabling targeted marketing and improved user experience based on robust data analytics.

I followed the plugin install, what else do I need to setup?

  • To fully integrate and utilize the plugin after installation, you need to configure settings within GA4. Specifically, any custom dimension you generate should be registered as a “Custom Dimension” in the GA4 admin settings. Within GA4, these custom dimensions are often referred to as “parameters” and are essentially dictionaries contained within events.

For instance, to track users who complete a quest (let’s refer to this event as quest_Event), you would monitor the following data points:

  • playerArray: An array that might include detailed dimensions such as character name (charName), character level (charLevel), character class (charClass), guild (charGuild), and the zone they are in (zone).
  • npcName: The name of the non-player character involved in the quest.
  • questID: A unique identifier for the quest.
  • itemsArray: An array detailing items involved or obtained during the quest.
  • currencyArray: An array detailing any form of in-game currency exchanged or earned.
  • xpEarned: The experience points gained from the quest.

Arrays marked with an asterisk (*) can contain multiple dimensions (or dictionaries), offering a more granular look at the data.

For a comprehensive layout of analytics tailored to a typical multiplayer RPG, including all necessary GA4 configurations, please refer to the following document:

This setup will ensure that you are fully leveraging the capabilities of GA4 in your Unity projects, providing deep insights into user interactions and the overall game economy.

Example Code for an Event:

GoogleAnalytics.Instance.TrackEvent("Event_Green", new Dictionary<string, object> {
                { "event_name", "mouse_click" },
                { "event_value", 1000 }
            });

Example Data Sent:

{
    "client_id": "0026D1B0-6F55-5454-B71C-221D41212B87",
    "events": [
        {
            "name": "Event_Green",
            "params": {
                "session_id": "90981f42-3ba2-4d17-930b-8565985c5780",
                "engagement_time_msec": 100,
                "event_name": "mouse_click",
                "event_value": 1000
            }
        }
    ]
}

Example Code for an event with an Array as a param:

GoogleAnalytics.Instance.TrackEvent("Event_Blue", new Dictionary<string, object> {
                { "items", new[]
                    {
                        new Item { item_id = "SKU_123A", item_name = "Item1", item_price = 123 },
                        new Item { item_id = "SKU_123B", item_name = "Item2", item_price = 234 }
                    }
                }
            });

Example Data Sent:

{
    "client_id": "0026D1B0-6F55-5454-B71C-221D41212B87",
    "events": [
        {
            "name": "Event_Blue",
            "params": {
                "session_id": "90981f42-3ba2-4d17-930b-8565985c5780",
                "engagement_time_msec": 100,
                "items": [
                    {
                        "item_id": "SKU_123A",
                        "item_name": "Item1",
                        "item_price": 123
                    },
                    {
                        "item_id": "SKU_123B",
                        "item_name": "Item2",
                        "item_price": 234
                    }
                ]
            }
        }
    ]
}

For a better understand of “Events” and Parameters, here is how a typical website tracks clicks on links on a website:

Here are some random graphs from Google Looker Studio:




1 Like