Skip to content

Commit

Permalink
feat: add Microsoft Clarity and fix websiteId typo
Browse files Browse the repository at this point in the history
- Added Microsoft Clarity analytics integration in the WebAnalytics
component.
- Fixed a typo in the UmamiAnalytics component: changed 'websitId'
variable to 'websiteId'.
  • Loading branch information
FYLSen authored and lxchapu committed May 28, 2024
1 parent 19dfa58 commit bd9d4e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
30 changes: 26 additions & 4 deletions src/components/head/WebAnalytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ export function WebAnalytics() {

return <>
{
analytics.umami.websitId && <UmamiAnalytics {...analytics.umami} />
analytics.umami.websiteId && <UmamiAnalytics {...analytics.umami} />
}
{
analytics.google.measurementId && <GoogleAnalytics {...analytics.google} />
}
{
analytics.microsoftClarity.projectId && <MicrosoftClarity {...analytics.microsoftClarity} />
}
</>
}

function UmamiAnalytics({
serverUrl,
websitId,
websiteId,
}: {
serverUrl?: string,
websitId: string,
websiteId: string,
}) {
const src = `${serverUrl || 'https://cloud.umami.is'}/script.js`

return <script defer src={src} data-website-id={websitId} />
return <script defer src={src} data-website-id={websiteId} />
}


Expand All @@ -43,4 +46,23 @@ gtag('config', '${measurementId}');`,
}}></script>
</>
)
}


function MicrosoftClarity({
projectId,
}: {
projectId: string,
}) {
return (
<>
<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", "${projectId}");`
}}></script>
</>
)
}
5 changes: 4 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@
},
"umami": {
"serverUrl": "",
"websitId": ""
"websiteId": ""
},
"microsoftClarity": {
"projectId": ""
}
}
}

0 comments on commit bd9d4e3

Please sign in to comment.