Skip to content

Commit

Permalink
Drop scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbrasileiro committed Jan 31, 2024
1 parent 23bb436 commit 47ccc84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 53 deletions.
53 changes: 2 additions & 51 deletions components/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,8 @@ import { scriptAsDataURI } from "apps/utils/dataURI.ts";
export const SendEventOnClick = <E extends AnalyticsEvent>({ event, id }: {
event: E;
id: string;
}) => (
<script
defer
src={scriptAsDataURI(
(id: string, event: AnalyticsEvent) => {
const elem = document.getElementById(id);

if (!elem) {
return console.warn(
`Could not find element ${id}. Click event will not be send. This will cause loss in analytics`,
);
}

elem.addEventListener("click", () => {
globalThis.window.DECO.events.dispatch(event);
});
},
id,
event,
)}
/>
);
}) => null;

export const SendEventOnView = <E extends AnalyticsEvent>(
{ event, id }: { event: E; id: string },
) => (
<script
defer
src={scriptAsDataURI(
(id: string, event: E) => {
const elem = document.getElementById(id);

if (!elem) {
return console.warn(
`Could not find element ${id}. Click event will not be send. This will cause loss in analytics`,
);
}

const observer = new IntersectionObserver((items) => {
for (const item of items) {
if (!item.isIntersecting) continue;

globalThis.window.DECO.events.dispatch(event);
observer.unobserve(elem);
}
});

observer.observe(elem);
},
id,
event,
)}
/>
);
) => null;
6 changes: 4 additions & 2 deletions sections/Miscellaneous/CampaignTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ function CampaignTimer({
</div>
</div>
</div>
<script
{
/* <script
type="module"
dangerouslySetInnerHTML={{
__html: `(${snippet})("${expiresAt}", "${id}");`,
}}
/>
/> */
}
</>
);
}
Expand Down

0 comments on commit 47ccc84

Please sign in to comment.