Record Time taken to complete a google form

若如初见. 提交于 2019-12-02 17:23:12

问题


I am trying to record the total time taken to complete and submit a Google form. My logic is simple that the following code would record and put the timestamp as a multiple choice option. Then upon submitting the form, we get a time stamp anyway but along with that, we would get the initially recorded timestamp as an answer to that question.

This is my cute little code:

function initial() {
  var form = FormApp.getActiveForm();
  form.getItemById(1589920082).asMultipleChoiceItem().setChoiceValues([new Date()]);
}

I have set the trigger as OnOpen but surprisingly, it does not renew the timestamp every time I open the form. Theoretically, it should record the time when the form was open but I think I am missing something here.

On the other hand, if I change the trigger to OnSubmit, it starts recording fresh timestamps every time I submit the form. But I don't want that as we get submission timestamps anyway. What I am trying to record is the time the form was open.


回答1:


I know this question was asked a year ago, but here is a workaround I just came up with.

Have 2 forms! The first form can be a disclaimer, instructions, etc. The second form is the original form you intended for the users to fill out. Turn on email collection for both, so you can know which user submitted the test.

Get the sharing link and in the settings of the first form add the link in the confirmation message:

Then link both forms into a spreadsheet and you will see the time stamp of each submissions. From there you can easily do a calculation to determine the duration.




回答2:


Unfortunately you cannot have any code executed when user opens form for filling in, as onOpen trigger is not supposed to be run in this case:

https://developers.google.com/apps-script/guides/triggers/#onopen

The onOpen() trigger runs automatically when a user opens a spreadsheet, document, or form that he or she has permission to edit. (The trigger does not run when responding to a form, only when opening the form to edit it.)

There is an open feature request in Google Issue Tracker to introduce some kind of onOpen trigger when form opened for response, you can "star" it to make it more possible to appear: https://issuetracker.google.com/issues/63985842



来源:https://stackoverflow.com/questions/47942995/record-time-taken-to-complete-a-google-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!