Does anyone know how to see WHICH cms page the user came from in Typeform?
We made a hidden field and tried to include the following code in the CMS page:
<script>
// Get the current CMS Page slug
var cmsPage = '{{slug}}';
// Update the Typeform link
var typeformLink = 'https://ym6byblmvcg.typeform.com/to/f3T8EVT8#stellendescription=cms_page_placeholder';
typeformLink = typeformLink.replace('cms_page_placeholder', cmsPage);
// Update the link on your webpage
document.getElementById('typeformLink').setAttribute('href', typeformLink);
</script>
But somehow it doesn’t work - does anyone have a solution?
Hello @head, your script does not work since you’ve placed it in the head section, meaning it loads before elements with the id typeformLink have loaded yet.
You can solve this by moving the script to before closing </body> tag or wrapping your code with this
document.addEventListener('DOMContentLoaded', () => {
//Add your code here
})
Also, I have noted that you do have 2 elements with the id typeformLink on the CMS page. Ensure only the specific link that you need to update the link has this id otherwise, the script will only work on the 1st instance element with the id
<script>
document.addEventListener('DOMContentLoaded', () => {
// Get the current CMS Page slug
var cmsPage = '{{slug}}';
// Update the Typeform link
var typeformLink = 'https://ym6byblmvcg.typeform.com/to/f3T8EVT8#stellendescription=cms_page_placeholder';
typeformLink = typeformLink.replace('cms_page_placeholder', cmsPage);
// Update the link on your webpage
document.getElementById('typeformLink').setAttribute('href', typeformLink);
})
</script>
How would I have to change the code if we want to have the following URL? https://ym6byblmvcg.typeform.com/to/f3T8EVT8#stellenbeschrieb=xxxxx&firma=xxxxx
“Firma” Also beeing dynamically added from the CMS?
<script>
document.addEventListener('DOMContentLoaded', () => {
// Get the current CMS Page slug
var slug = '{{slug}}';
var firma = '{{firma}}';
// Update the Typeform link
var typeformLink = `https://ym6byblmvcg.typeform.com/to/f3T8EVT8#stellenbeschrieb=${slug}&firma=${firma}`;
// Update the link on your webpage
document.getElementById('typeformLink').setAttribute('href', typeformLink);
})
</script>