简体   繁体   English

有没有办法将 Freshworks 聊天小部件添加到基于 Gatsby 构建的网站?

[英]Is there a way adding Freshworks chat widget to a website built on Gatsby?

Some chat software providers have Gatsby plugin available, or their provided script works without issues when included in html.js using React Helmet.一些聊天软件提供商提供 Gatsby 插件,或者他们提供的脚本在使用 React Helmet 包含在 html.js 中时没有问题。 However, some (Freshworks, for example) provide a script that gives 'unexpected token' and 'expression excepted' errors.但是,有些(例如,Freshworks)提供的脚本会出现“意外标记”和“表达式除外”错误。 My question is whether there is a simple way to alter the code to make it work or not?我的问题是是否有一种简单的方法可以更改代码以使其正常工作?

The code below includes a chat widget script provided by Freshworks that is included in Helmet before closing body tag.下面的代码包括一个由 Freshworks 提供的聊天小部件脚本,该脚本在关闭 body 标签之前包含在 Helmet 中。

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

Here's the error that was given after building the site.这是构建站点后给出的错误。


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

You need to use backticks ( ` ) inside your component and wrap it inside curly braces ( {} ):您需要在组件内使用反引号 ( ` ) 并将其包裹在花括号 ( {} ) 中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于Gatsby构建的网站,您如何将样式应用于Markdown文件中的数组? - How do you apply styling to array from a markdown file for Gatsby built website? 在我的游戏网站上为 2 个客户添加视频聊天的最简单方法? - Easiest method of adding video chat for 2 clients on my game website? 使用 Netlify 在 Gatsby 网站上使用 prerenderReady - prerenderReady on a Gatsby website with Netlify 以正确的方式添加javascript小部件代码 - adding javascript widget code the right way 为您的网站异步加载Google Translate小部件的方法? - Way to asynchronously load Google Translate widget for your website? 有没有办法编辑这个小部件在我的网站上的加载方式,以做出响应 - Is there a way to edit how this widget loads on my website, to be responsive 在 Gatsby 网站中集成 Drift 聊天服务 - Integrating Drift chat service within a Gatsby site 如何将 Smartsupp 聊天集成到 React 站点 (Gatsby) - How integrate Smartsupp chat to a React Site (Gatsby) HTML 元素未在 Gatsby 网站上呈现 - HTML elements not rendering on Gatsby website 在合作伙伴网站上添加JavaScript以提供客户聊天支持和销售跟踪,而无需知道其FTP凭据? - Adding javascript on a partner website for providing customer chat support and sales tracking without knowing their FTP Credentials?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM