CS代考 Metric Collection Through Google Forms

Metric Collection Through Google Forms
Written by:

This method of metric collection allows us to send our metric to a Google Form through Unity for easy metric tracking. We can then get a spreadsheet with all the metrics tracked to easily make graphs for the project using Google Sheets. Turnaround time for the metrics data is only a few minutes

Copyright By PowCoder代写 加微信 powcoder

Making the Form
1) Create a new Google Form
2) Fill out the form with the metrics you wish to track. In this example, we will be generating a random int and float as well as a boolean value
a) Make sure all responses are the “short answer” response type
b) TIP: Having some unique identifier for each playtest (sessionID) will help keep individual playtests separate for easier analysis

Example of form layout
3) If the form was created with a USC email, go to Settings ⇒ Responses and make sure the highlighted section is turned off

The form should now be ready for use and we can turn our attention hooking it up to code in a Unity project.

Implementing Code
1) Create a new script called “SendToGoogle” that will handle submitting a response to the form
2) Create any variables that you choose to track as well as a string for the URL
[SerializeField] private string URL;

private long _sessionID;
private int _testInt;
private bool _testBool;
private float _testFloat;

Variables used for the example

3) If you are using a sessionID, set it in Awake
private void Awake()
// Assign sessionID to identify playtests
_sessionID = DateTime.Now.Ticks;

Using the current time to at start to determine sessionID

4) Create a Send method to initialize the variables and eventually start the form submission. The Post method at the bottom will be created in the next step
a) NOTE: Post will need strings so either convert variables to strings in the method call like below or do so in Post
public void Send()
// Assign variables
_testInt = Random.Range(0, 101);
_testBool = true;
_testFloat = Random.Range(0.0f, 10.0f);

StartCoroutine(Post(_sessionID.ToString(), _testInt.ToString(), _testBool.ToString(), _testFloat.ToString()));

Example of how the Send method could look

5) Call the Send method from wherever you want to send metrics from
a) In this example, Send will be called on the startup of the scene in Awake
private void Awake()
// Assign sessionID to identify playtests
_sessionID = DateTime.Now.Ticks;

6) Create the Post method shown below replacing the example variables with your own that you wish to track
private IEnumerator Post(string sessionID, string testInt, string testBool, string testFloat)

Example of the Post method call

7) Create a new WWWForm and add fields for all of your variables.
a) We will replace the empty strings in a future step
private IEnumerator Post(string sessionID, string testInt, string testBool, string testFloat)
// Create the form and enter responses
WWWForm form = new WWWForm();
form.AddField(“”, sessionID);
form.AddField(“”, testInt);
form.AddField(“”, testBool);
form.AddField(“”, testFloat);

8) Submit the form using a UnityWebRequest
private IEnumerator Post(string sessionID, string testInt, string testBool, string testFloat)
// Create the form and enter responses
WWWForm form = new WWWForm();
form.AddField(“”, sessionID);
form.AddField(“”, testInt);
form.AddField(“”, testBool);
form.AddField(“”, testFloat);

// Send responses and verify result
using (UnityWebRequest www = UnityWebRequest.Post(URL, form))
yield return www.SendWebRequest();

if (www.result != UnityWebRequest.Result.Success)
Debug.Log(www.error);
Debug.Log(“Form upload complete!”);

Hooking Everything Up
1) Go to the form you created earlier and click the preview button in the top right (the eye icon)
2) Right click on the page and select Inspect to bring up the HTML code
a) You can also use the keyboard shortcut (ctrl + shift + I for Windows)
3) Search the code (ctrl + F for Windows) for the term “entry” and find the list of entry numbers

4) Copy the entry values into the empty strings we left in the Post method
form.AddField(“entry.1870008492”, sessionID);
form.AddField(“entry.839933719”, testInt);
form.AddField(“entry.2018632110”, testBool);
form.AddField(“entry.1475042058”, testFloat);

Example of what the entry list will look like

5) Copy the URL found a few lines above the entries (top of the image above) under “form action” for future use
a) NOTE: The URL at the top of the page will NOT work, you need to use this link
b) You can also find this link by viewing the page source (ctrl + U for Windows) and searching for “form action”
c) The URL for this example is “https://docs.google.com/forms/u/3/d/e/1FAIpQLSd3_5DnpX08k7YDUCt5nExM_gdKehryGb_oLjdFSD5lPSQWlg/formResponse”
6) Go to your Unity project
7) Attach the SendToGoogle script to a game object in the scene
a) In this example, it is attached to a “Game Manager” object however you can attach it to whatever makes sense, i.e. an “Analytics Manager” or the Player

8) Add the URL you copied earlier to the URL field in the Inspector

9) Your metrics are now ready to go! Test it out and make sure that you are getting results back from the game

To view the results, click on the Responses tab and click on the Google Sheets icon

Example of how metrics will look

Useful Tips

Cleaning Up Code

There are a few methods to clean up the method call of Post
· Pass in an object that contains everything that the Post method needs.
· Reduces the number of variables in the method call to one but requires a bit more setup code
· Allows for easier expansion and some more customization potential
· Make a class that contains static variables for all tracked metrics
· All variables can be accessed from anywhere in the code allowing easier metric tracking over multiple files
· More prone to errors as anything can change the variables at any time (e.g. accidentally duplicating a call to update a variable)

Organizing Data

Here are some ways to organize the data you are collecting
· Make separate forms for different types of metrics (e.g. one when the player dies and one when they beat a level)
· Can make forms more specific for each case leading to better analysis
· Keep your editor testing separate from playtests
· This makes sure you only collect the data you care about
· Can be done using a normal if normal if statement in code or a preprocessor #if statement
· Color coordinate playtests to differentiate them
· If there are distinct periods of playtesting at different days/times, color coding the results will help you identify the different playtests at a glance

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com