I want to pass a {{contactId}} from my website to identify my logged in customers who take the typeform survey embedded into my page. I embed videos through another company that provides this ability through the addition of a javascript snippet so am wondering if typeform allows for something similar? Hereβs an example of the snippet currently installed.
<script defer>
setTimeout(()=> {
var params = {
custom_id: xxxxxxxx,
}
var queryString = Object.keys(params).map(function(key) {return params[key] ? key + '=' + params[key] : ''
})
queryString = queryString.filter(Boolean).join("&")
if (queryString.length) {
frames = document.getElementsByTagName("iframe");
for (i = 0; i < frames.length; ++i) {
if (frames[i].src.includes("xxxxxx")) {
var url = frames[i].src + (frames[i].src.includes("?") ? "&"+queryString : "?"+queryString)
frames[i].src = url
}
}
}
})
</script>
Hi @KajabiChrystle Happy Monday! If you havenβt already seen it, I would first reference this article which will walk you through how to pass information not only into a typeform, but through an embedded one.
If you need further help, @mathio or @picsoung may be able to offer some guidance.
Thanks for the response @Liz. I had done this already, however the typeform is not accepting the name we have given the contact ID on our end to pass the value through. It just shows up as contactID in the responses. @mathio, @picsoung, tagging you in for some additional troubleshooting here please?
The other company I work with gives us an embed code for their videos, as well as a script that is placed on all site pages to allow them the grab the variables from our backend database and pass them through to the typeform response.
Thanks @mathio, does this snippet above work in conjunction with the embed code? Iβm new to coding so want to make sure weβre on the same page.
Let me lay out what we currently do w/ our typeforms, and what I want to achieve.
current state:
typeform code is embedded on a page that only logged in members can access. They have the option to complete this typeform after they have finished a course.
we manually configure the code to pass the name of the course into the typeform (course_name = xxxxx)
future state:
Keep both steps above
Additionally, pass the {{contactId}} of the logged in member from the page code through to an new hidden field on the embedded typeform (contact_id = {{contactId}}
See image of what the script looks like for a logged in member on our site
With this in mind, are you saying that I add the snippet above to the typeform embed code?
Thanks @mathio, does this snippet above work in conjunction with the embed code? Iβm new to coding so want to make sure weβre on the same page.
The snippet I provided is the embed code itself. There are 2 ways you can embed:
HTML code
You can use HTML code snippet. It is easier to use, however provides less flexibility, eg. you can not pass custom values from JavaScript. Eg you can only pass hardcoded values to the embedded typeform:
You can also build the embed using JavaScript. This requires some programming skills but provides more flexibility. For example you can pass dynamic variables to the typeform. In your case something like this could work:
<!-- this is where the form will be placed in your page --><divid="my-widget"></div><!-- this is the script to show the form --><scriptsrc="//embed.typeform.com/next/embed.js"></script><script>
window.tf.createWidget("<typeform-id>", {
hidden: {
contactId: whatever?.currentSiteUser?.contactId || "empty"
}
})
</script>
In your case I think you should use JS code to embed, as you have quite an advanced use case.
What I have above is just a modified version of the default html code typeform provides in the Share tab of your form. Note that in place of βmy-typeform-idβ and βmy-titleβ, you should put your actual typeform id and title. And thereβs some other styling code that typeform normally provides but I omitted it above for simplicity.
Also, make sure to actually add the hidden field to your form schema (and publish your changes!), as explained in Using Hidden Fields. And here is another article that adds some additional context to my code above: Use Hidden Fields in embedded typeforms
I want to pass a {{contactId}} from my website to identify my logged in customers who take the typeform survey embedded into my page. I embed videos through another company that provides this ability through the addition of a javascript snippet so am wondering if typeform allows for something similar? Hereβs an example of the snippet currently installed.
<script defer>
setTimeout(()=> {
var params = {
custom_id: xxxxxxxx,
}
var queryString = Object.keys(params).map(function(key) {return params[key] ? key + '=' + params[key] : ''
})
queryString = queryString.filter(Boolean).join("&")
if (queryString.length) {
frames = document.getElementsByTagName("iframe");
for (i = 0; i < frames.length; ++i) {
if (frames[i].src.includes("xxxxxx")) {
var url = frames[i].src + (frames[i].src.includes("?") ? "&"+queryString : "?"+queryString)
frames[i].src = url
}
}
}
})
</script>
Page 1 / 1
Hi @KajabiChrystle Happy Monday! If you havenβt already seen it, I would first reference this article which will walk you through how to pass information not only into a typeform, but through an embedded one.
If you need further help, @mathio or @picsoung may be able to offer some guidance.
Thanks for the response @Liz. I had done this already, however the typeform is not accepting the name we have given the contact ID on our end to pass the value through. It just shows up as contactID in the responses. @mathio, @picsoung, tagging you in for some additional troubleshooting here please?
The other company I work with gives us an embed code for their videos, as well as a script that is placed on all site pages to allow them the grab the variables from our backend database and pass them through to the typeform response.
Hi @KajabiChrystle Hm, shoot. Once @mathio is back in office (heβs out this week), hopefully heβll have some suggestions for you!
Hi @mathio hoping to get your eyes on this thread. Let me know if you need more information from me
Thanks @mathio, does this snippet above work in conjunction with the embed code? Iβm new to coding so want to make sure weβre on the same page.
Let me lay out what we currently do w/ our typeforms, and what I want to achieve.
current state:
typeform code is embedded on a page that only logged in members can access. They have the option to complete this typeform after they have finished a course.
we manually configure the code to pass the name of the course into the typeform (course_name = xxxxx)
future state:
Keep both steps above
Additionally, pass the {{contactId}} of the logged in member from the page code through to an new hidden field on the embedded typeform (contact_id = {{contactId}}
See image of what the script looks like for a logged in member on our site
With this in mind, are you saying that I add the snippet above to the typeform embed code?
Your suggestion is right and very beneficial for me.
KajabiChrystle wrote:
Thanks @mathio, does this snippet above work in conjunction with the embed code? Iβm new to coding so want to make sure weβre on the same page.
The snippet I provided is the embed code itself. There are 2 ways you can embed:
HTML code
You can use HTML code snippet. It is easier to use, however provides less flexibility, eg. you can not pass custom values from JavaScript. Eg you can only pass hardcoded values to the embedded typeform:
You can also build the embed using JavaScript. This requires some programming skills but provides more flexibility. For example you can pass dynamic variables to the typeform. In your case something like this could work:
<!-- this is where the form will be placed in your page --><divid="my-widget"></div><!-- this is the script to show the form --><scriptsrc="//embed.typeform.com/next/embed.js"></script><script>
window.tf.createWidget("<typeform-id>", {
hidden: {
contactId: whatever?.currentSiteUser?.contactId || "empty"
}
})
</script>
In your case I think you should use JS code to embed, as you have quite an advanced use case.
What I have above is just a modified version of the default html code typeform provides in the Share tab of your form. Note that in place of βmy-typeform-idβ and βmy-titleβ, you should put your actual typeform id and title. And thereβs some other styling code that typeform normally provides but I omitted it above for simplicity.
Also, make sure to actually add the hidden field to your form schema (and publish your changes!), as explained in Using Hidden Fields. And here is another article that adds some additional context to my code above: Use Hidden Fields in embedded typeforms