Files
classroomio/apps/dashboard/src/lib/utils/services/posthog/index.ts
T

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-10-30 06:04:53 +00:00
import { dev } from '$app/environment';
import posthog from 'posthog-js';
2024-04-07 22:01:36 +01:00
export const capturePosthogEvent = (event: string, properties?: Record<string, unknown>): void => {
2023-10-30 06:04:53 +00:00
if (dev) return;
posthog.capture(event, properties);
};
2024-04-07 22:01:36 +01:00
export const identifyPosthogUser = (id: string, properties?: Record<string, unknown>): void => {
2023-10-30 06:04:53 +00:00
if (dev) return;
posthog.identify(id, properties);
};
export const initPosthog = (): void => {
if (dev) return;
posthog.init('phc_JfdHOZ6v0cVlGELBYx1Tmoen2nxNOrAzvgvrPA6Ksov', {
api_host: 'https://eu.posthog.com'
});
};
2024-11-28 16:02:34 +01:00
export const initOrgAnalytics = (siteId: string) => {
if (dev) return;
2025-11-01 15:49:29 +01:00
2024-11-28 16:02:34 +01:00
// add js to head of page
const script1 = document.createElement('script');
script1.textContent = `
(function () {
window.counterscale = {
q: [["set", "siteId", "${siteId}"], ["trackPageview"]],
};
})();
`;
document.head.appendChild(script1);
2025-11-01 15:49:29 +01:00
const script2 = document.createElement('script');
2024-11-28 16:02:34 +01:00
script2.id = 'counterscale-script';
script2.src = 'https://be13a4b3.counterscale-5jn.pages.dev/tracker.js';
script2.defer = true;
document.head.appendChild(script2);
2025-11-01 15:49:29 +01:00
};