diff --git a/components/Analytics.tsx b/components/Analytics.tsx index 6736b664..1b2a4854 100644 --- a/components/Analytics.tsx +++ b/components/Analytics.tsx @@ -1,5 +1,21 @@ import { sendEvent } from "$store/sdk/analytics.tsx"; import type { AnalyticsEvent } from "apps/commerce/types.ts"; +import { scriptAsDataURI } from "apps/utils/dataURI.ts"; + +const snippet = (id: string, event: AnalyticsEvent) => { + const element = document.getElementById(id); + + if (!element) { + console.warn( + `Could not find element ${id}. Click event will not be send. This will cause loss in analytics`, + ); + } else { + element.addEventListener( + "click", + () => window.DECO.events.dispatch(event), + ); + } +}; /** * This function is usefull for sending events on click. Works with both Server and Islands components @@ -7,17 +23,7 @@ import type { AnalyticsEvent } from "apps/commerce/types.ts"; export const SendEventOnClick = ({ event, id }: { event: E; id: string; -}) => ( -