The work of a game developer on ROBLOX does not stop after a game is published. Bugs come up that did not appear during testing, new features have to be added to maintain interest in the game. Google Analytics is a very powerful tool used to monitor traffic, events, and behavior on websites. The Google Analytics Model allows you to connect a ROBLOX game to a Google Analytics account. With this integration a developer can see diagnostic data such as when visitors enter their games or when lua exceptions are thrown.


To track data using Google Analytics you need a Tracking ID which is a unique number that is attached to a web application to track it. To use Google Analytics with ROBLOX only one Tracking ID is needed as it can be shared between your games. That said, you can get multiple IDs if you prefer to add more organization in Analytics.

Tracking ID[edit]

To get a Tracking ID, you must first create an account on Google Analytics. If you already have an account on Google Analytics you want to use, create a new property for it, still following the steps below. To create an account, navigate to Google Analytics and press Access Google Analytics in the upper right hand corner. You can use any Google login you already have or can create a new one. If you have not setup any Google Analytics before you will be prompted to setup a new account. If you already have an account and want to add a new one, click on the Admin tab, then click on the accounts drop down menu and select Create new account from the bottom of the list.

Creating a new account will prompt you for several things. First, the account needs to have a name. Note that an account can hold multiple tracking IDs, so it is recommend to give it a very general name such as My ROBLOX. Next, you will need to enter a Property name. You can basically think of the property name as the name of the tracking ID. As was mentioned earlier, this ID can track as many or few games as you like, so you should name the Property accordingly. If you are just tracking one place, then naming the Property after the place is appropriate. If you are tracking multiple places (perhaps to track all of the places in a game), then the name of the game might work better. Keep in mind you can always change these names later if you like.

Next, a website is required. We aren't actually ever going to use this, so you can enter in any valid web address you like (note that the analytics will NOT track that page itself as you may not have access to that page to add analytics).

The rest of the information on this page is not pertinent to how ROBLOX uses Google Analytics, so fill the rest out as you feel is appropriate. Once you are done, click Get Tracking ID.

On the next page you will be shown a code with the format UA-########-#. Copy this as you will need it later.

Add Tracking ID to Place[edit]

To add a Tracking ID to one of your places, HttpService must first be enabled. In your place in Studio, navigate to the Insert tab, click on Service, then HttpService. In the explorer select HttpService and open the Properties window. Make sure the HttpEnabled flag is on.

Next, in a server script, add the following:

local GA = require(153590792)

Replace the UA-########-# with the Tracking ID obtained earlier. Your place is now tracked by Google Analytics.

If you want a more fine-tuned approach, you can use a table containing settings:

local config = {
	DoNotReportScriptErrors = true; -- Whether errors should be reported.
	-- Enabled by default. Set this field to true if you want to disable this feature.
	DoNotTrackServerStart = true; -- Whether a "ServerStartup" action will be reported when a server starts
	-- Enabled by default. Set this field to true if you want to disable this feature.
	DoNotTrackVisits = true; -- Whether visits are tracked. They appear under the action "Visit"
	-- Enabled by default. Set this field to true if you want to disable this feature.
local GA = require(153590792)

If you don't use the second argument, as in the first code example, it'll use the default settings. By default, all of those features are enabled.

Using Google Analytics[edit]

It is very easy to see real time statistics about your game. Log into Google Analytics and click on All Web Site Data under the Tracking ID you setup earlier. Once there, click on Events under Real Time on the left of the page. This will pull up a graph showing events as they happen in your game. To test, make sure your game is published and then launch it from ROBLOX. You should see a Visit event appear. If your game has any lua exceptions, they will also show in the chart when the exception happens.

You can also see a history of events by clicking on Behavior > Events. This shows all tracked events over time, and there are many ways to manipulate the charts to see trends over time. For example, here is a graph showing the total events, visits, and a specific lua error over the period of a couple of days:


Adding your own events[edit]

The module allows you to report your events. This allows you to report the data that you need or want.

local GA -- require module, call Init
local category = "PlaceId-" -- This is the default category.
-- If your game has several game modes (or maps), you could categorize your data for each map.
-- This is useful if you want to see if you want to log the amount of deaths and see if it's related to the map.
local action = "PlayerDied" -- This is the name of the event, which shows up as "Event Action" (e.g. "Visit" in the screenshot above)
-- Currently, the module uses those actions: ServerStartup and Visit, along with script errors (e.g. "Humanoid is not a...")
local label = "Lava" -- This isn't really important.
-- The module uses the value "none" for all events.
-- It allows you to specify more data, which you can fetch on the GA site.
-- We can use it to tell google how a player died, for if we really want to keep track of that.
local value = 1 -- This is the amount we want to report.
-- If we send a "PlayerDied" everytime someone dies, we would use the value 1.
-- We could at the end of a round also send "20 people died this round" with the value 20.
GA.ReportEvent(category, action, label, value)
-- And now we reported a death to the GA!

You can use ReportEvent to report any data you want. As an example, we've sent an event of someone dieing. You can report when a new round starts, someone buys a dev product, ...