Microsoft Clarity script throwing error in React js

Harshal Sharma 1 Reputation point
2021-07-02T07:37:32.147+00:00

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)`
Community Center Not monitored
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hossain Azad 1 Reputation point
    2021-07-10T14:31:57.547+00:00

    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");`,
      }}
    />;
    

  2. Mr.Taimoor 0 Reputation points
    2023-10-28T21:11:09.3366667+00:00

    its good and most useful software fro ever i used in my life, Best tool.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.