chore: collect org analytics
This commit is contained in:
@@ -20,3 +20,24 @@ export const initPosthog = (): void => {
|
|||||||
api_host: 'https://eu.posthog.com'
|
api_host: 'https://eu.posthog.com'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const initOrgAnalytics = (siteId: string) => {
|
||||||
|
if (dev) return;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
const script2 = document.createElement('script');
|
||||||
|
script2.id = 'counterscale-script';
|
||||||
|
script2.src = 'https://be13a4b3.counterscale-5jn.pages.dev/tracker.js';
|
||||||
|
script2.defer = true;
|
||||||
|
document.head.appendChild(script2);
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
import { setTheme } from '$lib/utils/functions/theme';
|
import { setTheme } from '$lib/utils/functions/theme';
|
||||||
import hideNavByRoute from '$lib/utils/functions/routes/hideNavByRoute';
|
import hideNavByRoute from '$lib/utils/functions/routes/hideNavByRoute';
|
||||||
import shouldRedirectOnAuth from '$lib/utils/functions/routes/shouldRedirectOnAuth';
|
import shouldRedirectOnAuth from '$lib/utils/functions/routes/shouldRedirectOnAuth';
|
||||||
import { identifyPosthogUser, initPosthog } from '$lib/utils/services/posthog';
|
import { identifyPosthogUser, initPosthog, initOrgAnalytics } from '$lib/utils/services/posthog';
|
||||||
import { initSentry, setSentryUser } from '$lib/utils/services/sentry';
|
import { initSentry, setSentryUser } from '$lib/utils/services/sentry';
|
||||||
import UpgradeModal from '$lib/components/Upgrade/Modal.svelte';
|
import UpgradeModal from '$lib/components/Upgrade/Modal.svelte';
|
||||||
import { handleLocaleChange } from '$lib/utils/functions/translations';
|
import { handleLocaleChange } from '$lib/utils/functions/translations';
|
||||||
@@ -234,7 +234,6 @@
|
|||||||
setTheme(data.org?.theme);
|
setTheme(data.org?.theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupAnalytics();
|
setupAnalytics();
|
||||||
|
|
||||||
handleResize();
|
handleResize();
|
||||||
@@ -269,11 +268,14 @@
|
|||||||
// }
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.isOrgSite && data.org) {
|
if (data.isOrgSite && data.org && !$currentOrg.siteName) {
|
||||||
$globalStore.orgSiteName = data.orgSiteName;
|
$globalStore.orgSiteName = data.orgSiteName;
|
||||||
$globalStore.isOrgSite = data.isOrgSite;
|
$globalStore.isOrgSite = data.isOrgSite;
|
||||||
|
|
||||||
currentOrg.set(data.org);
|
currentOrg.set(data.org);
|
||||||
|
|
||||||
|
// Setup internal analytics
|
||||||
|
initOrgAnalytics(data.orgSiteName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user