Overview
We will be covering three methods of collecting user feedback including... - Opening the user's email client - Opening a link to a Google Form for the user to manually fill out - Automatically completing a Google Form using a UnityWebRequest This tutorial include snippets from the full FeedbackCollecter.cs found here. Setup I have created a simple Unity scene for testing which includes an input field, a button, and the script we will be writing. The script has the text of the input field and the button linked to it as Serialized Fields. There is also a serialized enum so that switch between methods.
Setup
I have created a simple Unity scene for testing which includes an input field, a button, and the script we will be writing. The script has the text of the input field and the button linked to it as Serialized Fields. There is also a serialized enum so that we can switch between methods.
For now, we don't need to worry about the last two lines, they will only be needed once we get to the Google Forms approach. the kReceiverEmailAddress should be initialized with the email address you would like the feedback emails to be sent to. This may be your email or your company's email. The following code will complete our setup including connecting several methods we will write to the submit button's onClicked event.
Opening the user's email client
For our first approach, we will use data entered into the text field to populate an email that will open on the native email app of their device. To do this, we construct a link using the information provided and we will make use of a OpenLink helper method. This method is required because we must escape space characters on iOS devices (they simply cannot open links that contain spaces, poor Apple). It would just so happen that google search results also reject spaces so I included that in the method in case you use it elsewhere in your code. (Preview of what it looks like on device: LINK).
Opening a Google Form
The email approach was great for empowering players but I have found it can sometimes be easier to sift through player data on a spreadsheet. Google Forms is an easy alternative. With the below method we can simply direct them to a form for them to fill out. This method will require that we create a Google Form on a Drive account. Then view the form and to find it's URL. That should look something like this: "https://docs.google.com/forms/d/e/1FAIpQLSchQzdbNs_wY_EWSpAtohQHRDQeliy0o6yLoRs7C5D17B-1qg/viewform" We will be using the "base URL" which is everything before the "viewform" in my case, my base URL would be: "https://docs.google.com/forms/d/e/1FAIpQLSchQzdbNs_wY_EWSpAtohQHRDQeliy0o6yLoRs7C5D17B-1qg/" Find your base URL and use it to for the kGFormBaseURL constant which we defined earlier.
Automatically completing a Google Form
The above code will successfully open a Google Form for the user to edit. But we can do better. Below is an approach that uses Unity's web request system to complete the Google Form all on its own. For this method to work we will need to find the kGFormEntryID we defined earlier. This ID corresponds to the question on the form, each question has a unique ID. To find the ID of your question, right click on the form, select "inspect page" then Ctrl+F your way to the text "entry." this text is a prefix of the ID we desire. See this .gif if you have any trouble finding it!
Once you find the entry ID, use it to properly intialize kGFormEntryID and then the below code will be good to go! Note that is makes use of a JSON serializer. This can be useful if you want to save data this is not a string. For example, you may desire to record a player's save data or settings. By converting this data into a JSON string, we can send it along to the form. However, we need to avoid using the utility when dataContainer is actually of type string because the serializer will otherwise convert the string to simply "{}". Not very helpful!
These are only a few homebrew approaches to collecting player data, trying different approaches is the best way to find the right fit for your needs. Please consider "liking" this post or commenting on which aspects were most helpful / confusing. Your readership is very much appreciated!
14 Comments
Michael
1/11/2020 06:09:23 pm
Hey, great post! Thank you for helping me.
Reply
Olivia
1/11/2020 07:24:43 pm
Thank you!!
Reply
aman
5/19/2020 04:28:24 pm
Please can u help me on how to send attachments too with the mail
Reply
Matthew
5/19/2020 05:21:39 pm
I've tried to do this before, unfortunately I don't think it's possible because to open up the email is its own privileged process on the device whether that is PC or mobile. However there are workarounds. On a PC application I created, I opened up the containing folder of the attachment as well as their email client so that they could just drag it in. I also used a server to save the attachment and then just gave the user a code that they could email to another user and then they could use that code to download the content from this shared server. That latter is actually what riot games used in Legends of runeterra. For mobile devices, there is a share feature which is probably the closest we'll get.
Reply
Nninj
8/3/2020 10:56:56 am
Hi there.
Reply
Matthew
8/3/2020 01:03:15 pm
Hmm, I haven't worked with that system. I would say just abstract the multiple choice to a short response. Present the dropdown or radio buttons in your app but send only the text of the choice or the index of the choice,
Reply
Matthew Ventures
10/21/2020 08:35:42 pm
Hello =) thank you for following the tutorial. If a public variable is not showing up it you may try the SerializeField keyword.
Reply
PL
11/28/2020 02:51:35 pm
It does not work anymore. They changed the encoding and the input field does not have any "entry.XXXXX"
Reply
Matthew Ventures
11/28/2020 04:13:26 pm
Nice catch, looks like they updated it. If you search the string of your question prompt, you should be able to find two numbers adjacent to it within the data-params section. Try these and let me know if one works so I can update the guide.
Reply
Tristan
7/27/2021 08:19:12 am
Thanks for a great tutorial!
Sanat Biswal
9/28/2022 11:33:26 am
Hi I am unable to determine what should be the "entry ID". Can anyone please specify it with an example of what to take?
Reply
Matthew
9/28/2022 02:30:31 pm
Check the top pinned comment on the Youtube video:
Reply
Leave a Reply. |