Skip to content

Commit

Permalink
Use Clarity NPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
hulloitskai committed Dec 6, 2024
1 parent d7a5c3e commit 8b9493d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
6 changes: 4 additions & 2 deletions app/components/ClarityTracking.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Clarity from "@microsoft/clarity";

const ClarityTracking: FC = () => {
const {
component,
Expand All @@ -6,9 +8,9 @@ const ClarityTracking: FC = () => {

// == Current user tracking
useShallowEffect(() => {
if (typeof clarity !== "undefined" && currentUser) {
if (currentUser) {
const { id, name } = currentUser;
clarity("identify", id, undefined, component, name);
Clarity.identify(id, undefined, component, name);
}
}, [currentUser, component]);

Expand Down
13 changes: 13 additions & 0 deletions app/helpers/clarity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Clarity from "@microsoft/clarity";

import { getMeta } from "~/helpers/meta";

export const setupClarity = () => {
const projectId = getMeta("clarity-project-id");
if (projectId) {
Clarity.init(projectId);
console.info("Initialized Clarity", projectId);
} else {
console.warn("Missing Clarity project ID; skipping initialization");
}
};
10 changes: 2 additions & 8 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@
<% end %>

<%# == Clarity %>
<% if Rails.env.production? && (settings = Clarity.settings) %>
<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", "<%= settings.project_id %>");
</script>
<% if (settings = Clarity.settings) %>
<meta name="clarity-project-id" content="<%= settings.project_id %>">
<% end %>

<%# == Vite %>
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@mantine/modals": "^7.12.1",
"@mantine/notifications": "^7.12.1",
"@mantine/nprogress": "^7.12.1",
"@microsoft/clarity": "^1.0.0",
"@rails/actioncable": "^7.1.3-2",
"@rails/activestorage": "^7.1.3-2",
"@react-email/components": "^0.0.25",
Expand Down
6 changes: 6 additions & 0 deletions sorbet/rbi/shims/lib/frozen_record.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# typed: true

class FrozenRecord::Base
sig { params(id: T.untyped).returns(T.attached_class) }
def self.find(id); end
end
11 changes: 0 additions & 11 deletions typings/clarity.d.ts

This file was deleted.

0 comments on commit 8b9493d

Please sign in to comment.