I want to add third-party analytics to my game but don’t know how since this guide seems to have fallen apart. Could somebody provide some tips on how to go about this?
That old guide used a ModuleScript from 2014 that used a HttpService postAsync to send data to Google’s servers.
Could this be adapted to use Google Analytics 4 instead of Universal Analytics? The GA4 documentation I looked at seemed to insist on inserting JavaScript into a web page.
local HTTPService = game:GetService("HttpService")
local MeasurementId = "G-XXXXXXXXXX"
local ApiSecret = "xXXxXXXXXXxXXxXXXXXXXx"
local ServerSessionId = game:GetService("HttpService"):GenerateGUID()
local url = string.format("https://www.google-analytics.com/mp/collect?measurement_id=%s&api_secret=%s", MeasurementId, ApiSecret)
local data = HTTPService:JSONEncode({
client_id = game.JobId;
events = {
name = 'UserVisit',
params = {
exampleParam = 1234;
},
}
})
while wait(5) do
print("response: ", HTTPService:PostAsync(url, data, Enum.HttpContentType.ApplicationJson))
end
Placing this code in a server script will result in an event being sent every 5 seconds.
I don’t see any change in my analytics dashboard on the main page at first
“In order for user activity to display in reports like Realtime, engagement_time_msec and session_id must be supplied as part of the params for an event .”
So I updated my code to the following:
local HTTPService = game:GetService("HttpService")
local MeasurementId = "G-XXXXXXXXXX"
local ApiSecret = "xXXxXXXXXXxXXxXXXXXXXx"
local ServerSessionId = game:GetService("HttpService"):GenerateGUID()
local url = string.format("https://www.google-analytics.com/mp/collect?measurement_id=%s&api_secret=%s", MeasurementId, ApiSecret)
local data = HTTPService:JSONEncode({
client_id = game.JobId;
events = {
name = 'UserVisit',
params = {
exampleParam = 1234;
engagement_time_msec = "100";
session_id = "123";
},
}
})
while wait(5) do
print("response: ", HTTPService:PostAsync(url, data, Enum.HttpContentType.ApplicationJson))
end
Now I need to figure out what other secret parameters I can use to make the dashboard acknowledge the data I’m sending it.
No. I gave up on Google Analytics and am using Game Analytics instead which has an official Roblox implementation. Their library has a few bugs I’ve needed to fix but otherwise works well and is decently powerful.
I haven’t had any issues with its datastore usage cutting into my quota so far and my game uses datastores fairly heavily.
I didn’t like that it wanted me to put scripts in 3 different locations in every place I use it in so I modified it slightly so they would all work from a single folder in the workspace (I have a module that allows localscripts to run in the workspace)