How to Create Personalized Form Links Using Typeform Hidden Fields and Google Sheets

  • 27 September 2023
  • 5 replies
  • 242 views

Userlevel 3
Badge +1

Hi everyone! In this guide, I will show you a cool trick to generate personalized links to forms using Typeform data and the hidden fields option in Google Sheets.

 

Example Use Cases:

  • Generate personalized feedback forms
  • Create customized surveys based on individual preferences
  • Collect personalized data for targeted marketing campaigns
  • Create personalized registration forms for events or workshops

 

Before You Start, You Will Need:

  • The Typeform from which you will gather the data or a Google Sheets document with the data you want to add to your hidden fields link.
  • Your Typeform link with hidden fields. (This will be your feedback form)
  • Access to Google Sheets and TypeScript

 

 

Step 1: Connect Your Typeform to Google Sheets

To begin, open the Typeform containing the data you want to use for creating links and connect it to Google Sheets.

 

 

 

Step 2: Open the Apps Script Extension

Next, open the Apps Script extension in Google Sheets where we will write our script.

 

 

 

Step 3: Add the UI Function

Now, let's add the UI function to create a menu option for generating links. This will make the process more user-friendly.

 

 

Code:

function onOpen() {
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu('Generate Links');
menu.addItem('Create new Links', 'createNewLinks')
menu.addToUi();

}

 

 

Step 4: Add the createNewLinks Function

In this step, we'll add the createNewLinks function. This function will iterate through the rows in your Google Sheets document, generate personalized links based on the data, and add them to the specified column.

 

Code:

function createNewLinks() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheet = spreadsheet.getSheetByName('Tutoring Form');
const rows = sheet.getDataRange().getValues();

rows.forEach(function(row, index) {
if (index === 0 || row[8]) return; // Skip headers and already generated links

const name = row[0].replace(/ /g, "+");
const tutor = row[4].replace(/ /g, "+");
const studentId = row[2].replace(/ /g, "+");
const url = `https://bpnc.typeform.com/to/vAgYN9QT#name=${name}&tutor=${tutor}&studentid=${studentId}`;

sheet.getRange(index + 1, 9).setValue(url);
});
}

 

Code Breakdown:

In the code, you will need to create variables for each column you want to add to your URL. These variables represent the data you want to include in the personalized links.

 

 

Next, you need to replace the hidden fields in your Typeform URL with ${your_variable}. This will dynamically populate the hidden fields with the corresponding data from your Google Sheets.

 

 

Finally, you can add the generated URL to the desired column in your Google Sheets document. In the example, it is added to column 9.

 

 

Example: (Google Sheets)

 

Once you have completed writing the script, save it, and head back to your Google Sheets document to generate the links.

 

 

In your Google Sheets document, click on Generate Links to generate the personalized links based on the data in your sheet.

 

 

 

That's it! You have successfully created personalized form links using Typeform hidden fields and Google Sheets.

Now you can share these personalized links for various purposes, such as feedback forms, customized surveys, targeted marketing campaigns, or registration forms for events or workshops. Happy linking!

 

Form Example:

 


5 replies

Userlevel 7
Badge +5

Hi @Jsanchez204 THIS IS SO COOL!!! Thank you so much for sharing this! We get this asked a lot, so this is going to be handy for so many people. 

 

Userlevel 3
Badge +1

@Liz Awesome! I'm glad people are going to be able to use this. I love using Google sheets, especially with Typeform, I'm currently working on creating something where we can send out automated Typeform HTML emails using Google Sheets so I can't wait to share that with everyone. 

Userlevel 7
Badge +6

@Jsanchez204 - glad to see the App Script example.. it’s cool but beyond my grey hair to figure out (i stopped writing code when COBOL was in vogue). I wonder if the method i use below to create the url might make it easier in the scripting, if the url is already in a field?  just a thought if you’ll bear with me.. 

 

here’s the sample typeform that i used to start the sequence that i outline below

 

i’ve done something similar to create links ‘dynamically’ based on fields in google sheets and send them out via email using Document Studio - much less ‘coding’ for me lol.. 

note that i created a ‘report’ tab in my google sheet and pulled in the columns from the Typeform dump tab - gives me shorter field names to use in the link generation formula below. 

here’s a screenshot from a google sheet connected to a simple typeform set that does something similar to what you generated. 

if you look at the arrayformula() function in the c2 cell shown at the top of the image, you can see that i have used a static text string to one of my typeforms and pulled the email and name fields into the url string - these will be passed into the following form as hidden fields. 

 

here’s the arrayformula() in case it is easier to read here: 

=ARRAYFORMULA(if (isblank(B2:B), " " , "https://desborough.typeform.com/to/OZbaRxr7#email="&B2:B&"&name="&A2:A))

in Document Studio, i chose to set up only a “send email’ step in the workflow - the neat trick inside Document Studio is that you can set the ‘link’ to be a field in the data: 

Note the {{tf_link}} marker in the url box. that will send the reader to the personalized feedback form. 

 

I like what you did with the App Script in this example and the earlier one you did. Don’t get me wrong on that. This method seems to be a whole lot simpler to my brain and I don’t have to do any app scripting - i try to be as ‘no code’ as possible lol.. 

 

I’ve actually used a variation of the method i showed where, based on some segmentation logic and assigning a ‘tag’ variable to in the original source form, I have my arrayformula go lookup the appropriate typeform url to which i want to send THAT respondent. ie i have one where i have 10 possible forms to choose from and so i replace the static text from the example above with the lookup’d value. i hope that makes sense.. 

 

for those who haven’t heard of using Document Studio with Google Sheets, you can see a workshop where a couple of examples were shown at this link.

 

hope either of these methods can help folks move the needle!

 

des

 

Userlevel 3
Badge +1

@john.desborough - This is really cool! I'm going to try to replicate this in Document Studio. Thanks, Des! Also the array formula you provided will definitely come in handy. I'm still trying to figure out how to send Typeform HTML emails with app script, but the code is getting too large. 

this approach is definitely more user-friendly, and I love the fact that you can send an email from 10 possible forms just by assigning a tag. And the ability to send links as hyperlinks is amazing!

Thanks again for sharing this. You've inspired me to try to add more features to my code 😅, so it might take longer than expected to finish, lol.

Userlevel 7
Badge +5

Oh man, I feel like we need a webinar with you both on there just building things, @john.desborough and @Jsanchez204 ! Our minds would all be like: 

 

Reply