question

HarshalSharma-2231 avatar image
0 Votes"
HarshalSharma-2231 asked MaksymMalynovskyi-8010 commented

Microsoft Clarity script throwing error in React js

I tried integrating clarity script in my website but it is throwing an error in VS Code.

 `<script type="text/javascript">    

 (function(c,l,a,r,i,t,y){
     c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
     t=l.createElement(r);
     t.async=1;
     t.src="https://www.clarity.ms/tag/"+i;
     y=l.getElementsByTagName(r)[0];
     y.parentNode.insertBefore(t,y);
 })(window, document, "clarity", "script", "7ds6fq93fz");

</script>`


 `Parsing error: Unexpected token, expected "}"
    9 |                 <script type="text/javascript">
   10 |     (function(c,l,a,r,i,t,y){
 11 | c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
 | ^
 12 | t=l.createElement(r);
 13 | t.async=1;
 14 | t.src="https://www.clarity.ms/tag/"+i;eslint
 '}' expected.ts(1005)`
not-supported
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

HossainAzad-6781 avatar image
0 Votes"
HossainAzad-6781 answered MaksymMalynovskyi-8010 commented

You can't write js code into script tag ... You need to set the code by following way:

 <script
   dangerouslySetInnerHTML={
                 {
     __html: `
         (function(c,l,a,r,i,t,y){
             c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };
             t=l.createElement(r);
             t.async=1;
             t.src="https://www.clarity.ms/tag/"+i;
             y=l.getElementsByTagName(r)[0];
             y.parentNode.insertBefore(t,y);
         })(window, document, "clarity", "script", "XXXXXXXXX");`,
   }}
 />;



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, would you mind sharing in which file and which part of the react component this script should be added?

1 Vote 1 ·