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>
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.