Logging Data with Google Sheets 2023

Disclaimer: This tutorial is how to send and log data to a google sheets document, this tutorial doesn’t show how to get/retrieve data from a sheet.

This tutorial focuses on taking in-game data and sending it to a Google Spreadsheet document. Most tutorials I found were outdated from 2015. This tutorial is quite similar to @Dummiez’s but updated to work in 2023. Dummiez 2015 Tutorial.

Keep in mind, Google spreadsheets has limits whether its size or how many requests you can do in a fixed period of time.

  1. Create a new Google Spreadsheet. In your Roblox studio place, create an empty script. Make sure your studio place can make HTTP requests, this will be in “Game Settings”.

  2. Next we want to create a form to submit the data with. In the spreadsheet, Click on Tools → Create New Form.

  3. In your Google form, add in any data (as questions) you would like to log. Each question should be of the short answer type.

  4. Make sure your form is accepting answers and is not a quiz. This should be the default anyways. (Modifyable in settings).

  5. When you entered all your questions, click send at the top. Take the URL it gives you (take the long URL not the Shortened link), the link should look like this: https://docs.google.com/forms/d/e/abcde123/edit
    That space in the middle “abcde123” will be your Form key, save that as a string variable in your script.

local formKey = "abcde123"
  1. In the Form, click on more (3 dots at the top) → Get pre-filled link
    On the shown page, type your answers as something identifiable, or just paste the question as the answer (This is only necessary for readability in the next step)
    Make sure every box is filled out. At the bottom, click “Get Link” and copy it.

  2. That link will look something like this:
    https://docs.google.com/forms/d/e/abcde123/viewform?usp=pp_url&entry.0123456789=PlayerCount&entry.456789123=RandomGameStat1&entry.789123456=RandomGameStat2
    You can see the pattern &entry.[randomNumber] = yourAnswer. This number is your question entry.
    Copy each question entry into its own variable, name or comment the variables based on its associated question. If you typed distinct answers in the last step, you should know which entry corresponds to which question.

local PlayerCount = "0123456789"
local RandomGameStat1 = "456789123"
local RandomGameStat2 = "789123456"
  1. Using the following function, add in your variables
-- Make sure you define local HttpService = game:GetService("HttpService")
local function logSheet(variables)
	local url  = "https://docs.google.com/forms/d/e/" .. formKey.."/formResponse?usp=pp_url" --formKey would be your key like "abcde123"
		.."&entry."..PlayerCount .."=".. variables[1] -- PlayerCount would be your question entry, variables[1] would be the data that your would want to set for that question/entry
		.."&entry."..RandomGameStat1 .."="..variables[2] -- RandomGameStat1 would be your question entry, variables[2] would be the data that your would want to set for that question/entry
		.."&entry."..RandomGameStat2 .."="..variables[3] -- RandomGameStat2 would be your question entry, variables[3] would be the data that your would want to set for that question/entry
       -- add more lines if you have more questions to submit

	HttpService:PostAsync(url, "")
end
logSheet( { 1, 2, 3 } )  
  1. Go back to your Google Spreadsheet. On the bottom, there should be a button with something like “Form Responses 1”, click on that.

  2. Run your function, you should notice the data you entered will start appearing in the spreadsheet along with a time stamp.
    Q10

: )

7 Likes

An alternative way would be to use the Google Sheets API directly:

You’re able to read & write data to the sheet.

2 Likes

The tough part with this (iirc - I was playing around with something like this before) is that you pretty much need to do it from a service account and then manage signing the JSON Web Token with RSA-256, which is a major pain to implement in Roblox Lua, because of the lack of relevant cryptological libraries

3 Likes

You shouldn’t be using Google Sheets for analytics and data as it isn’t meant to be used in that way as a form of database.

Consider using Google Analytics as it is more specialized for this purpose and has it’s own service for first party support.

3 Likes

hi, I was previously using Google Analytics for data analysis. However, Google Analytics is going to be upgraded to GA4 soon. I found that the new version’s Measurement ID is “G-XXXXXXX”, instead of “UA-XXXXXXX-X”. Do you know how to use the new version in Roblox?

3 Likes