Timer for google forms

1,657 views
Skip to first unread message

Inga Ingólfsdóttir

unread,
Mar 8, 2023, 12:04:08 PM3/8/23
to Google Apps Script Community
I need to log each time a responder opens my Google Form to track the duration.

Any advice? I'm at the point of considering putting up a website that logs the time when a button linking to the form is clicked but then I don't know how I can link that timestamp with the correct instance of the form... help

Inga Ingólfsdóttir

unread,
Mar 8, 2023, 12:05:50 PM3/8/23
to Google Apps Script Community
Additionally: I would not like to set a time limit or use an add-on.  I'm comfortable writing code and using apps script but I am horribly stuck >.<

Marcos Gomes

unread,
Mar 8, 2023, 12:33:13 PM3/8/23
to google-apps-sc...@googlegroups.com
Just an idea.
You can create a link to the form url and record the user and time of the click (Start) and capture the end when the user clicks SEND (end) on the form


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0c5805a2-09fb-481b-8940-c6015c70751bn%40googlegroups.com.

Inga Ingólfsdóttir

unread,
Mar 8, 2023, 1:07:43 PM3/8/23
to Google Apps Script Community
Thank you for the suggestion! I thought about that but haven't found a way to log the start and end time with the response ID as it doesn't seem to be available until after the form is submitted and unfortunately my script must handle multiple responses at a time... any ideas?

Marcos Gomes

unread,
Mar 8, 2023, 2:12:26 PM3/8/23
to google-apps-sc...@googlegroups.com

Create a function that takes the timestamp and will be activated with SUBMIT.
You can do this using the onFormSubmit() trigger


image.png



Inga Ingólfsdóttir

unread,
Mar 8, 2023, 2:55:04 PM3/8/23
to Google Apps Script Community
I've thought of this as well, but how can the function know when the form was opened if it is triggered on submit?

Marcos Gomes

unread,
Mar 9, 2023, 12:59:46 PM3/9/23
to google-apps-sc...@googlegroups.com
Hello,

You will need to create a spreadsheet to record the START/END time
Example:
https://docs.google.com/spreadsheets/d/1to-j1jFiJMG70G_pgpyc2Tb-Mcd0RomUaLNY7zO_Fjg/edit?usp=sharing

This spreadsheet records a moment the user click on the link to open the form.
The form link is displayed in a WebApp. When clicked, the data is recorded in DB worksheet.

In Form, use this Script:

function createTrigger() {
    const form = FormApp.openById('ID FORM HERE');
    ScriptApp.newTrigger('finish')
        .forForm(form)
        .onFormSubmit()
        .create();
}


function finish() {
    // find position and save
    const ss = SpreadsheetApp.openById('ID SHEET TO REGISTER'); // Sheet to write END time
    const db = ss.getSheetByName("DB");

    let timeZone = Session.getScriptTimeZone();
    let date = Utilities.formatDate(new Date(), timeZone, 'dd/MM/yyyy HH:mm:ss');
    let email = Session.getEffectiveUser().getEmail();

    //find user in DB
    const userCol = db.getRange(1, 2, db.getLastRow(), 1).getDisplayValues();

    let c = 0;
    while(userCol[c] != email){
        c++;
    }

    db.getRange(c + 1, 3).setValue(date);
}


Execute createTrigger() to active trigger to get END time.

Hope this helps

Jonathan Butler

unread,
Mar 9, 2023, 5:33:07 PM3/9/23
to google-apps-sc...@googlegroups.com
A somewhat hacky solution would be to send a link to a web app that iframes a Google form. You can record the start time by using the onload event of the body tag. You can use the submission time as the end time. When generating the Google form, you can use some unique identifier to bind the two.

1. Create a uuid when a doget function is called serving your web app
2. Pass the unique id to the front end using templating.
3. Run a function that uses the unique id to create a prefilled form
4. Serve the response link in an iframe.
5. Once that is submitted join the data together with a query or a trigger based on the unique id field.


6 (optional) If generating the form on the fly takes too long you can pre generate a bunch of them and serve them as needed.

Inga Ingólfsdóttir

unread,
Mar 9, 2023, 5:58:06 PM3/9/23
to Google Apps Script Community
@Jonathan, that is what I ended up doing... after 3 days of wracking my brain on this!! ...later the same day I came up on another online form solution that has this built in og I'm just going to use that!  Thank you so much for your answers and effort ^^

Caio Gragnani

unread,
Jan 28, 2024, 9:09:14 AM1/28/24
to Google Apps Script Community
@Inga, what online form solution did you adopt in the end? I see some plugins that currently have this fearure$$$ but not interested in that right now because of monetary and data security issues.
Reply all
Reply to author
Forward
0 new messages