Answer the question
In order to leave comments, you need to log in
How to pass cookie value to Bitrix24 CRM form?
The site contains an online chat widget and a CRM form.
The documentation has an example of how to pass a parameter to the Bitrix24 form by modifying the open lines widget code:
<script data-skip-moving="true"> (function(w,d,u,b){ s=d.createElement('script');
r=1*new Date();s.async=1;s.src=u+'?'+r; h=d.getElementsByTagName('script')[0];h.parentNode.insertBefore(s,h); })
(window,document,'http://cp.bx/upload/crm/site_button/loader_14_i4bdl2.js');
window.Bitrix24WidgetObject = window.Bitrix24WidgetObject || {};
window.Bitrix24WidgetObject.handlers = { 'form-init': function(form){ form.presets = { 'my_cookie1': 'test_value', }; } };
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
Answer the question
In order to leave comments, you need to log in
Figured it out myself. The widget is not particularly needed here, it is enough to modify the form code. Works for old forms (not 2.0)
add the function code at the beginning of the page, then add a request for this function in the form code.
<script>function getCookie(name){const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();}
</script>
b24form({"id": "4",
"lang": "ru",
"sec": "d143a7",
"type": "inline",
"presets":{"mycookie": getCookie('_ym_uid')}});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question