Javascript 有没有办法在盖茨比的网站上添加Freshworks聊天工具?

Javascript 有没有办法在盖茨比的网站上添加Freshworks聊天工具?,javascript,reactjs,chat,gatsby,react-helmet,Javascript,Reactjs,Chat,Gatsby,React Helmet,一些聊天软件提供商提供了Gatsby插件,或者他们提供的脚本在使用React.js包含在html.js中时不会出现问题。但是,有些(例如Freshworks)提供了一个脚本,该脚本会给出“意外标记”和“表达式除外”错误。 我的问题是,是否有一种简单的方法来修改代码以使其正常工作 下面的代码包括Freshworks提供的聊天小部件脚本,该脚本包含在关闭body标记之前的Helet中 <Helmet> <script> function initFres

一些聊天软件提供商提供了Gatsby插件,或者他们提供的脚本在使用React.js包含在html.js中时不会出现问题。但是,有些(例如Freshworks)提供了一个脚本,该脚本会给出“意外标记”和“表达式除外”错误。 我的问题是,是否有一种简单的方法来修改代码以使其正常工作

下面的代码包括Freshworks提供的聊天小部件脚本,该脚本包含在关闭body标记之前的Helet中

 <Helmet>
        <script>
  function initFreshChat() {
    window.fcWidget.init({
      token: "5df26417-e127-480b-a0ff-d21908f5030f",
      host: "https://wchat.eu.freshchat.com"
    });
  }
  function initialize(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,e.src="https://wchat.eu.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>
        </Helmet>
      </body>

函数initFreshChat(){
window.fcWidget.init({
令牌:“5df26417-e127-480b-a0ff-d21908f5030f”,
主机:“https://wchat.eu.freshchat.com"
});
}
函数初始化(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement(“脚本”)。id=t,e.async=!0,e.src=”https://wchat.eu.freshchat.com/js/widget.js“,e.onload=initFreshChat,i.head.appendChild(e))}函数初始化调用(){初始化(文档,“freshchat js sdk”)}窗口。addEventListener?窗口。addEventListener(“加载”,初始化调用,!1):window.attachEvent(“加载”,初始化调用,!1);
以下是在构建站点后给出的错误


Building static HTML failed

See our docs page for more info on this error: https://gatsby.dev/debug-html


  133 | //
  134 | // But on the command line of a file system, it's not as complicated, you can't
> 135 | // `cd` from a file, only directories.  This way, links have to know less about
      | ^
  136 | // their current path. To go deeper you can do this:
  137 | //
  138 | //     <Link to="deeper"/>


  WebpackError: Module build failed (from ./node_modules/gatsby/dist/utils/babel-loader.js):

  - utils.js:135 
    node_modules/@reach/router/lib/utils.js:135:1

  - typeof.js:11
    node_modules/@babel/runtime/helpers/typeof.js:11:1

  - utils.js:23
    node_modules/@reach/router/lib/utils.js:23:1

生成静态HTML失败
有关此错误的更多信息,请参阅我们的文档页面:https://gatsby.dev/debug-html
133 | //
134 |//但是在文件系统的命令行上,它没有那么复杂,您不能
>135 |/`cd`来自文件,仅来自目录。这样的话,链接就不需要了解太多
| ^
136 |//他们当前的路径。要深入了解,您可以执行以下操作:
137 | //
138 | //     
WebPackageError:模块构建失败(来自./node_modules/gatsby/dist/utils/babel loader.js):
-utils.js:135
node_modules/@reach/router/lib/utils.js:135:1
-typeof.js:11
node_modules/@babel/runtime/helpers/typeof.js:11:1
-utils.js:23
node_modules/@reach/router/lib/utils.js:23:1
您需要在组件内使用反勾号(
`
),并将其包装在大括号内(
{}
):


{`函数initFreshChat(){
window.fcWidget.init({
令牌:“5df26417-e127-480b-a0ff-d21908f5030f”,
主机:“https://wchat.eu.freshchat.com"
});
}
函数初始化(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement(“脚本”)。id=t,e.async=!0,e.src=”https://wchat.eu.freshchat.com/js/widget.js“,e.onload=initFreshChat,i.head.appendChild(e))}函数初始化调用(){初始化(文档,“freshchat js sdk”)}窗口。addEventListener?窗口。addEventListener(“加载”,初始化调用,!1):window.attachEvent(“加载”,初始化调用,!1);
`}

谢谢你,费兰,你的快速而中肯的回答。现在一切都好了。
<Helmet>
      <script type='text/javascript'>
        {`  function initFreshChat() {
    window.fcWidget.init({
      token: "5df26417-e127-480b-a0ff-d21908f5030f",
      host: "https://wchat.eu.freshchat.com"
    });
  }
  function initialize(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,e.src="https://wchat.eu.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>
</Helmet>