'How to implement FreshworksWidget into next.js project?

In Freshdesk docs they provide this script:

<script>
  window.fwSettings={
    'widget_id':12000000025,
    'locale': 'en'
  };
  !function(){if("function"!=typeof window.FreshworksWidget){var n=function(){n.q.push(arguments)};n.q=[],window.FreshworksWidget=n}}()
</script>
<script type='text/javascript' src='https://widget.freshworks.com/widgets/12000000025.js' async defer />
<script type='text/javascript'>
  //insert API here
</script>

But I have no idea how to implement it into react.js app.



Solution 1:[1]

You can directly insert the <script> tags in the index.html file.

Check out this sample react program -> https://playcode.io/708622/

Solution 2:[2]

There is a thing called next/scripts that enables you to use scripts inside of next js. See the snippet below:

import Script from 'next/script'

// ... rest of the code here //

return(
  <>
  <Script>{`
    window.fwSettings={
      'widget_id':12000000025,
      'locale': 'en'
    };
    !function(){if("function"!=typeof window.FreshworksWidget){var n=function(){n.q.push(arguments)};n.q=     [],window.FreshworksWidget=n}}()`}
  </Script>
  <Script type='text/javascript' src='https://widget.freshworks.com/widgets/12000000025.js' async defer />
  <Script type='text/javascript'>
    //insert API here
  </Script>
  </>)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kannan
Solution 2 Mika