Passing Variables in Javascript Body

I’m trying to integrate FreshChat into my application. I have FreshChat itself working, but simply installing the Javascript code below into the Body. What isn’t working is passing variables from WW to FreshChat, any idea what I may be doing wrong here?

 <script>
 
 function initFreshChat() 
 {
    window.fcWidget.init({token: "91233, host: "https://name.freshchat.com"});
	window.fcWidget.setExternalId(pluginVariables[/* xanoAuth user */ 'f5856798-485d-47be-b433-d43d771c64e1']['user']['email']);
	window.fcWidget.user.setFirstName(pluginVariables[/* xanoAuth user */ 'f5856798-485d-47be-b433-d43d771c64e1']['user']['name']);
	window.fcWidget.user.setEmail(pluginVariables[/* xanoAuth user */ 'f5856798-485d-47be-b433-d43d771c64e1']['user']['email']);
 }
  function initialize(i,t){var e;i.getElementById(t)?
  initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,
  e.src="https://patchoptics.freshchat.com/js/widget.js",e.onload=initFreshChat,i.head.appendChild(e))}
  function initiateCall(){initialize(document,"Freshchat-js-sdk")}
  window.addEventListener?window.addEventListener("load",initiateCall,!1):
  window.attachEvent("load",initiateCall,!1);
 
 </script>

Try removing all the newlines from the script.

It goes without saying that a custom component is a better approach. :person_shrugging:

I made some mods to the script, but I’m receiving this error:

Here is the latest script, any idea on what might be going on?

<script>
  
 function initFreshChat() 
 {
    window.fcWidget.init({token: "9ffd03db-0e1b-47af-8514-6cad0e3e7eba", host:"https://patchoptics.freshchat.com"});
  	window.fcWidget.setExternalId(pluginVariables["f5856798-485d-47be-b433-d43d771c64e1"]["user"]["email"]);
	  window.fcWidget.user.setFirstName(pluginVariables["f5856798-485d-47be-b433-d43d771c64e1"]["user"]["name"]);
	  window.fcWidget.user.setEmail(pluginVariables["f5856798-485d-47be-b433-d43d771c64e1"]["user"]["email"]);
 }

  function initialize(i,t){var e;i.getElementById(t)?
  initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,
  e.src="https://patchoptics.freshchat.com/js/widget.js",e.onload=initFreshChat,i.head.appendChild(e))}
  function initiateCall(){initialize(document,"Freshchat-js-sdk")}
  window.addEventListener?window.addEventListener("load",initiateCall,!1):
  window.attachEvent("load",initiateCall,!1);
 
</script>

On the custom component, yes, but big learning curve for me… These Javascript integrations are pretty simple once you work through their nuances.

I think pluginVariables is available only if you bind the value of the html component

Do you know how to go about doing that?

Just the same as binding the text of a button or a paragraph.

Something like this?

image

something like this:

Of course pluginVariables is not globally exposed so this way you get the value as string, therefore you need to surround the value with quotation marks.
It gets very ugly very quickly.

An alternative can be to dig into wwLib (that is exposed globally) and get the plugin data from there, but you need to be careful because that can change.

I also don’t like the way the code is executed in the html element, so I think a custom component is just the best way for integrations in weweb.