feat: add posthog student signup

This commit is contained in:
Rotimi Best
2024-04-07 22:01:36 +01:00
parent d01c1a1ba3
commit 9311a21de8
6 changed files with 43 additions and 15 deletions
@@ -63,7 +63,7 @@ export async function getOrgTeam(orgId: string) {
};
}
export async function getOrganizations(userId: string) {
export async function getOrganizations(userId: string, isOrgSite?: boolean, orgSiteName?: string) {
const { data, error } = await supabase
.from('organizationmember')
.select(
@@ -120,19 +120,30 @@ export async function getOrganizations(userId: string) {
orgs.set(orgsArray);
if (localStorage) {
const lastOrgSiteName = localStorage.getItem('classroomio_org_sitename');
// If this is a student dashboard
if (isOrgSite && orgSiteName) {
const orgData = orgsArray.find((org) => org.siteName === orgSiteName);
const lastOrg = orgsArray.find((org) => org.siteName === lastOrgSiteName);
if (lastOrg) {
currentOrg.set(lastOrg);
if (orgData) {
currentOrg.set(orgData);
}
}
} else {
// Check if org was last visited in localhost
if (localStorage) {
const lastOrgSiteName = localStorage.getItem('classroomio_org_sitename');
const _currentOrg = get(currentOrg);
if (!_currentOrg.siteName) {
currentOrg.set(orgsArray[0]);
const lastOrg = orgsArray.find((org) => org.siteName === lastOrgSiteName);
if (lastOrg) {
currentOrg.set(lastOrg);
}
}
// Default to setting the first org in the array of orgs
const _currentOrg = get(currentOrg);
if (!_currentOrg.siteName) {
currentOrg.set(orgsArray[0]);
}
}
}
@@ -1,13 +1,13 @@
import { dev } from '$app/environment';
import posthog from 'posthog-js';
export const capturePosthogEvent = (event: string, properties?: Record<string, any>): void => {
export const capturePosthogEvent = (event: string, properties?: Record<string, unknown>): void => {
if (dev) return;
posthog.capture(event, properties);
};
export const identifyPosthogUser = (id: string, properties?: Record<string, any>): void => {
export const identifyPosthogUser = (id: string, properties?: Record<string, unknown>): void => {
if (dev) return;
posthog.identify(id, properties);