简体   繁体   English

如何将 Smartsupp 聊天集成到 React 站点 (Gatsby)

[英]How integrate Smartsupp chat to a React Site (Gatsby)

I want to integrate the smartsupp chat in my Gatsby site (React), but the site only give you the following code... For a better performance would add some 5sec wait before loading.我想在我的 Gatsby 站点 (React) 中集成 smartsupp 聊天,但该站点只为您提供以下代码......为了获得更好的性能,加载前会增加 5 秒的等待时间。

<script type="text/javascript">
  var _smartsupp = _smartsupp || {};
  _smartsupp.key = "YOUR_SMARTSUPP_CODE";
  // ...
  // your configuration
  // ...
  window.smartsupp||(function(d) {
    var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
    s=d.getElementsByTagName('script')[0];c=d.createElement('script');
    c.type='text/javascript';c.charset='utf-8';c.async=true;
    c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
  })(document);
</script>

I could hardcode a <script dangerouslySetInnerHTML={{__html: ... /> or put it inside the tag and make this thing done but I think there's a better way to having as a component我可以对 <script dangerouslySetInnerHTML={{__html: ... /> 进行硬编码或将其放入标签内并完成这件事,但我认为有更好的方法将其作为组件

Copy .cache/default-html.js to src/html.js ..cache/default-html.js复制到src/html.js
You can customise it code in....您可以自定义它的代码......

Inserting HTML into the <head>将 HTML 插入 <head>
Anything you render in the html.js component will not be made “live” in the client like other components.您在 html.js 组件中呈现的任何内容都不会像其他组件一样在客户端中“生效”。 If you want to dynamically update your <head> we recommend using React Helmet如果你想动态更新你的 <head> 我们推荐使用React Helmet
- Gatsby Docs - 盖茨比文档

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM