Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Gamasutra: The Art & Business of Making Gamesspacer
arrowPress Releases

If you enjoy reading this site, you might also want to check out these UBM Tech sites:


Google Analytics in games

by Nemanja Bondzulic on 08/25/15 01:22:00 pm   Featured Blogs

4 comments Share on Twitter    RSS

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.


During the development of SUPERVERSE game we needed a way to track how the players interact with the game, what kind of hardware are they playing on, screen resolutions, operating system and similar informations. This kind of data will be handy for debugging purposes but also for examining behaviours and patterns in player interactions.

Of course, we needed a solution for this and the choice was between these three options:

  • Develop our own tracking solution from scratch on both the game, client side, and the back-end side.
  • Choose a 3rd party solution (e.g.¬†GameAnalytics).
  • Adopt Google Analytics we all know and love.

First two options seemed more costly in terms of time or money needed to have them running, so instead we decided to try using Google Analytics to track and report game events.

Using Google Analytics has been quite popular for the web sites and mobile apps lately but this is not the case with the desktop PC software. The reason for this is most probably the lack of easy-to-use pre-packaged solution in the form of SDK that you could just plug in to your project, such is the case for iOS and Android apps.

Basic setup

In order to start tracking events from your game you need to:

  • Setup the Google Analytics account if you don't have one yet.
  • Setup a new tracking property, thus get a tracking ID - it¬†looks like this: UA-12345678-2.
  • Use¬†Measurement Protocol¬†and send hits to Google Analytics using HTTP.

That's it.

Or if that was not enough detailed for you read on for step by step tutorial how to add Google Analytics tracking into your PC game.


Sending data to Google Analytics can be achieved using either GET or POST requests. Google Analytics allows secure data transfers by relying on HTTPS protocol but also plain HTTP can be used. For the matter of simplicity we'll be using unsecured HTTP POST requests in this text. For our game we've utilized libCURL as it handles communication well and we'll be eventually using it for some other tasks. Opening a TCP socket on port 80 and sending an HTTP POST request shall do the job equally well.

void Send2GoogleAnalytics(char *postdata, char *useragent)
  CURL *curl_handle = curl_easy_init();
  if ( curl_handle ) {
    curl_easy_setopt(curl_handle, CURLOPT_URL, "h t t p : / / w w w . g o o g l e - a n a l y t i c s . c o m / c o l l e c t";);

    curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, useragent);
    curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, postdata);



Post data (postdata)

postdata variable should point to the string that contains all the information you want to send to Google Analytics.

Required information for every Measurement Protocol request are:

Name Parameter Example Description
Protocol Version v v=1 The protocol version. The value should be 1.
Tracking ID tid tid=UA-123456-1 The ID that distinguishes to which Google Analytics property to send data.
Client ID cid cid=xxxxx An ID unique to a particular user.
Hit Type t t=pageview The type of interaction collected for a particular user.

* API may change in the future, please consult Measurement Protocol reference documentation

So, the exemplar postdata may look like:


User identification (UUID)

In order for Google Analytics to figure out that the data is coming from the single user, you need to send client ID parameter with each HTTP request. This parameter expects the universally unique identifier (uuid) and you can generate one using code like this. Once you generate a random uuid you should store it and use that uuid next time the game is started. This will make Google Analytics know that the player currently playing is the same one that played the game last week - even if he quit the game in the meantime.

Game version and operating system (useragent)

Google Analytics tracks the browsers and their version numbers as well as the operating system the browser is working on. We can use this to track our game's version number and the system it's running on by providing this information in the form the user agent string, e.g:

Superverse/0.3 (Windows NT 6.2)

Windows system version number can be obtained by calling GetVersionEx(). "Windows NT 6.2" in the example actually marks Windows 8.0.

Tracking data

Once you have those basics in place you can start sending Google Analytics information of interest for your measurements and tracking. Two most basic types of hits are pageview and event, but there are others such as transaction, timing, social, exception and item. Each of those is well documented in the reference guide.


In order to see when the player started the game and how long her played it, you should start a session and end it before she leaves the game. This is achieved by appending following commands to postdata string:


Sessions could also be used to mark beginning and end of player playing the match or the level within the game.

Reporting frequency

Google defines how often data can be transmitted to them. The game should not be sending data more often than once in two seconds. In addition to that the number of events is limited to 500 hits per session. However, those limitations should be more than enough for tracking happenings in your game.

Putting it all together

Tracking events should be seamless and asynchronous task that has no impact on other components of the game.

Suggested solution would be to have a buffer of requests that's being filled from the main thread of the game whenever you like to track some information. On the other hand there should be a background thread that processes the buffered requests and sends them to Google Analytics, making sure the sending rate is acceptable to Google and doesn't break the limits and quotas they have in place.

Related Jobs

Tactic Studios
Tactic Studios — London, Ontario, Canada

Senior Gameplay Programmer
Square Enix Co., Ltd.
Square Enix Co., Ltd. — Tokyo, Japan

Experienced Game Developer
Sony PlayStation
Sony PlayStation — San Francisco, California, United States

Sr. Product Manager, Player Engagement & Social Experiences
Playco — APAC, Remote, Remote

Senior Product Manager

Loading Comments

loader image