I am currently working on integrating a chat widget from Tawk into a next.js react app.
In my _app.js file, I have added the script import tag and attempted to set up the widget like this:
import Script from 'next/script'
{/* <!--Start of Tawk.to Script--> */}
<Script id="tawk" strategy="lazyOnload">
dangerouslySetInnerHTML={{
__html: `
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/[]/[]';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
`,
}}
</Script>
Unfortunately, when attempting this setup, I encountered an error message stating:
Unhandled Runtime Error SyntaxError: Unexpected identifier
Call Stack loadScript ../../node_modules/next/dist/client/script.js (148:18) eval ../../node_modules/next/dist/client/script.js (167:62)
I reached out to the Tawk developer support team, who acknowledged a compatibility issue with React. They mentioned that a fix has been implemented in version 2.0.1 which can be found here: https://www.npmjs.com/package/@tawk.to/tawk-messenger-react
After trying to implement the suggested solution in both _app.tsx and _document.tsx files, I encountered more than 10 errors related to that package.
I am wondering if anyone has successfully integrated Tawk into a next.js react app?