The problem
The widget is not aware of any data that your website might hold about the current user or page. For example, if the user is logged in it does not know her username. If we are in a product page, the widget does not know the current product id.
The solution
This data can be injection into the widget and into the relevant form. From the form it can then be saved as a lead, or in your favourite supported CRM.
Step 1
You must inject a stringified JSON object into into the widget’s data-inject-object attribute.
For example:
{
“Agent_id”: {
“hidden_feld_id”: “hidden_field_value”
…
},
“Agent_id2”: {
“hidden_feld_id2”: “hidden_field_value2”
…
},
}
A real example might be:
{
“2342f4a26ed1428b2f4a26ed”: {
“x_field_id”: “John”
}
}
In order to use this code this would than have to be stringified and added to the data-inject-object of you widget:
<script>
const data = {
“871b6056-32c6-4016-81d2-36f83f157120”: {
“x_field_id”: “John”
}
}
jsonString = JSON.stringify(data)
</script>
<script defer data-inject-object=”jsonString” src=”https://widget.tochat.be/bundle.js?key=2c055a74-452f-4409-b0d0-51febc675801″></script>
Step 2
You would then have to make the form, and create a hidden filed with the value you used above. Note, we can also get the agent ide from the url