Passing Calendly Variables to an Embedded Typeform | Community
Skip to main content
Answered

Passing Calendly Variables to an Embedded Typeform


Hello everyone,

About Me:
I'm new to coding, so please bear with me.

Issue:
I have managed to pass Calendly variables to an embedded Typeform via HTML using the parameter 'transitiveSearchParams'. However, I'm having trouble implementing this solution in Javascript. The reason I need to use Javascript is because I have custom fields in Calendly that pass URL data with parameters like answer_1, answer_2, etc.

Typeform does not accept answer_ as a hidden field, so I cannot use the default Calendly variables with 'transitiveSearchParams'.

 

Attempted Solution:

Part 0-a:
This is the URL that Calendly passes to the embedded Typeform. I’ve removed some of the extra variables that Calendly passes by default:

 

https://mysite.com/embed-typeform?invitee_first_name=Bob&invitee_last_name=Jones&invitee_email=bob.jones@gmail.com&answer_1=Red&answer_2=Blue&answer_3=Yellow

 

Part 0-b:
The expected result I want to see in my Typeform is:

  • invitee_first_name: Bob
  • invitee_last_name: Jones
  • invitee_email: bob.jones@gmail.com
  • ans1: Red
  • ans2: Blue
  • ans3: Yellow

Note: The variables should be ans1, ans2, etc., not answer_1, answer_2, etc.

Part 1:
My approach:

  1. Pass information via Calendly.
  2. Assign a new variable (ans1) to answer_1.
  3. Load ans1 into the hidden field.

Part 2:
I've created a new Typeform with hidden variables: ans1, ans2, ans3, invitee_first_name, invitee_last_name, and invitee_email.

Part 3:
Here's my code snippet that fetches values from the current URL:

javascript

var url_string = window.location.href;

var url = new URL(url_string);

var ans1 = url.searchParams.get("answer_1");

var ans2 = url.searchParams.get("answer_2");

var ans3 = url.searchParams.get("answer_3");

 

Part 4:
I need to combine the above snippet with the following one, and this is where I'm facing issues:

<script>
import { createWidget } from '@typeform/embed';
import '@typeform/embed/build/css/widget.css';

var url_string = window.location.href;
var url = new URL(url_string);
var ans1 = url.searchParams.get("answer_1");
var ans2 = url.searchParams.get("answer_2");
var ans3 = url.searchParams.get("answer_3");

window.tf.createWidget('u67kOcjW', {
  container: document.getElementById('wrapper'),
  transitiveSearchParams: ['invitee_first_name', 'invitee_last_name', 'invitee_email'],
  hidden: {
    ans1: ans1,
    ans2: ans2,
    ans3: ans3,
  },
});
</script>

<div 
     id="wrapper" 
     data-tf-widget="u67kOcjW" 
     data-tf-inline-on-mobile 
     data-tf-medium="snippet">
</div>

 

Part 5:
Can someone help me finalize this? I'm looking for the complete code to paste into my site and test. Please remember I'm a beginner, so any explanations should be beginner-friendly. Thank you for your assistance.

Best answer by mathio-tf

Hi @pizzame ,

your code seems to work fine, you did a great job!

The only minor issue I see that your typeform has hidden fields named a1, a2 and a3 while you are trying to pass hidden fields named ans1, ans2 and ans3. If you rename those variables in the hidden object of the createWidget method it should work as expected.

You can use shorthand notation to create the hidden object like this:

var url_string = window.location.href;
var url = new URL(url_string);
var a1 = url.searchParams.get("answer_1");
var a2 = url.searchParams.get("answer_2");
var a3 = url.searchParams.get("answer_3");

window.tf.createWidget('u67kOcjW', {
  container: document.getElementById('wrapper'),
  transitiveSearchParams: ['invitee_first_name', 'invitee_last_name', 'invitee_email'],
  hidden: { a1, a2, a3 },
});

Hope this helps and sorry for the wait. Cheers!

View original

Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • October 18, 2023

Tagging @mathio in case they have any advice. 

Also, what a great username, @pizzame ! 🍕


  • Author
  • Explorer
  • 2 replies
  • October 18, 2023

Thank you Liz! I do love pizza 🍕


Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • October 19, 2023

You and me both, @pizzame ! I realize @mathio is currently OOO until next week, but if you’re ok hanging on until then, he’ll be your best help!


  • Explorer
  • October 23, 2023

Sure. I’ll wait. Thanks for letting me know. 


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • October 23, 2023

Hi @pizzame ,

your code seems to work fine, you did a great job!

The only minor issue I see that your typeform has hidden fields named a1, a2 and a3 while you are trying to pass hidden fields named ans1, ans2 and ans3. If you rename those variables in the hidden object of the createWidget method it should work as expected.

You can use shorthand notation to create the hidden object like this:

var url_string = window.location.href;
var url = new URL(url_string);
var a1 = url.searchParams.get("answer_1");
var a2 = url.searchParams.get("answer_2");
var a3 = url.searchParams.get("answer_3");

window.tf.createWidget('u67kOcjW', {
  container: document.getElementById('wrapper'),
  transitiveSearchParams: ['invitee_first_name', 'invitee_last_name', 'invitee_email'],
  hidden: { a1, a2, a3 },
});

Hope this helps and sorry for the wait. Cheers!


Reply