Hmm that is a tough one, I’m not sure if we process expressions in script blocks, you can try something like:
<script type=“text/javascript”>
var Tawk_API=Tawk_API||{};
Tawk_API.visitor = {
name : ‘{{serverconnect.data.visitor_name}}’,
email : '{{serverconnect.data.email}}’
};
var Tawk_LoadStart=new Date();
// rest of the tawk.to widget code
</script>
Just make sure your expression is valid and enclosed within {{ and }}
Script tags and Style tags are not processed by App Connect. App Connect replaces the content when the DOM is ready, the javascript in the Script tag is then already executed.
Depending on where the data is coming from, lets say it comes from a serverconnect component. You want to create a javascript function on your site first like
All data you access in expressions can also be accessed in JavaScript under dmx.app.data, so if your expression was {{serverconnect.data.visitor_name}} then you can access it as dmx.app.data.serverconnect.data.visitor_name in JavaScript.
You have to wait until App Connect has the data loaded, so on the serverconnect component listen to the load or success event and to trigger the function like
You can also parse expressions directly using dmx.parse("serverconnect.data.visitor_name"), that is perhaps easier then accessing the data directly under dmx.app.data. You can then also use the formatters in the expressions.
I’ve used the setAttribute of the Tawk API since I think the data will be available after the Tawk API finished loading, see documentation at https://www.tawk.to/javascript-api/. There could be a racing condition between the ajax call of the Server Connect and the Tawk API loading, if the Server Connect loaded before the Tawk API then the setAttribute will probably not work.
First of all a big thank to Patrick for this extra support.
About the question of t11: have to say that this things it is too complex for my knowledge !
I made some try but for sure I did something not right. The fact is that I have not experience at all with javascript to manage something like that.
Now I m studing what Patrick wrote and the tawk.to api… let’s see if I can do something. In case I will keep you updated!!