From 91352f9a30dea98f9b29a897b458faefcc35c5d7 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 14 Feb 2023 11:55:44 +0100 Subject: [PATCH] feat: track custom id usage --- src/lib/actions/analytics.ts | 10 +++++++++- src/routes/console/createOrganization.svelte | 7 +++++-- src/routes/console/onboarding/+page.svelte | 4 +++- .../organization-[organization]/createProject.svelte | 7 +++++-- .../console/project-[project]/auth/createTeam.svelte | 7 +++++-- .../console/project-[project]/auth/createUser.svelte | 7 +++++-- .../console/project-[project]/databases/create.svelte | 7 +++++-- .../collection-[collection]/createDocument.svelte | 7 +++++-- .../databases/database-[database]/create.svelte | 7 +++++-- .../project-[project]/functions/createFunction.svelte | 7 +++++-- .../storage/bucket-[bucket]/create.svelte | 7 +++++-- .../console/project-[project]/storage/create.svelte | 7 +++++-- src/routes/register/+page.svelte | 3 ++- 13 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index b20711936..e8bae0f30 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -22,7 +22,15 @@ export function trackEvent(name: string, data: object = null): void { return; } - const path = get(page).route.id; + const currentPage = get(page); + const path = currentPage.route.id; + + if (currentPage.params?.project) { + data = { + ...data, + project: currentPage.params.project + }; + } if (isDevelopment) { console.debug(`[Analytics] Event ${name} ${path}`, data); diff --git a/src/routes/console/createOrganization.svelte b/src/routes/console/createOrganization.svelte index da4c78317..6fc75f52b 100644 --- a/src/routes/console/createOrganization.svelte +++ b/src/routes/console/createOrganization.svelte @@ -8,6 +8,7 @@ import { goto, invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; + import { ID } from '@aw-labs/appwrite-console'; export let show = false; @@ -20,7 +21,7 @@ const create = async () => { try { - const org = await sdkForConsole.teams.create(id ?? 'unique()', name); + const org = await sdkForConsole.teams.create(id ?? ID.unique(), name); await invalidate(Dependencies.ACCOUNT); dispatch('created'); await goto(`/console/organization-${org.$id}`); @@ -28,7 +29,9 @@ type: 'success', message: `${name} has been created` }); - trackEvent(Submit.OrganizationCreate); + trackEvent(Submit.OrganizationCreate, { + customId: !!id + }); name = null; id = null; show = false; diff --git a/src/routes/console/onboarding/+page.svelte b/src/routes/console/onboarding/+page.svelte index ac1628491..5b1b5159e 100644 --- a/src/routes/console/onboarding/+page.svelte +++ b/src/routes/console/onboarding/+page.svelte @@ -29,7 +29,9 @@ ); await invalidate(Dependencies.ACCOUNT); goto(`/console/project-${project.$id}`); - trackEvent(Submit.ProjectCreate); + trackEvent(Submit.ProjectCreate, { + customId: !!id + }); } catch (error) { loading = false; addNotification({ diff --git a/src/routes/console/organization-[organization]/createProject.svelte b/src/routes/console/organization-[organization]/createProject.svelte index 5ad094dc7..b642e08fd 100644 --- a/src/routes/console/organization-[organization]/createProject.svelte +++ b/src/routes/console/organization-[organization]/createProject.svelte @@ -6,6 +6,7 @@ import { InputText, Button, FormList } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdkForConsole } from '$lib/stores/sdk'; + import { ID } from '@aw-labs/appwrite-console'; import { createEventDispatcher } from 'svelte'; export let show = false; @@ -23,13 +24,15 @@ try { isCreating = true; const project = await sdkForConsole.projects.create( - id ?? 'unique()', + id ?? ID.unique(), name, teamId, 'default' ); dispatch('created', project); - trackEvent(Submit.ProjectCreate); + trackEvent(Submit.ProjectCreate, { + customId: !!id + }); addNotification({ type: 'success', message: `${name} has been created` diff --git a/src/routes/console/project-[project]/auth/createTeam.svelte b/src/routes/console/project-[project]/auth/createTeam.svelte index 0901abc81..73a109d13 100644 --- a/src/routes/console/project-[project]/auth/createTeam.svelte +++ b/src/routes/console/project-[project]/auth/createTeam.svelte @@ -5,6 +5,7 @@ import { InputText, Button, FormList } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdkForProject } from '$lib/stores/sdk'; + import { ID } from '@aw-labs/appwrite-console'; import { createEventDispatcher } from 'svelte'; export let showCreate = false; @@ -16,7 +17,7 @@ const create = async () => { try { - const team = await sdkForProject.teams.create(id ?? 'unique()', name); + const team = await sdkForProject.teams.create(id ?? ID.unique(), name); name = ''; showCreate = false; showCustomId = false; @@ -24,7 +25,9 @@ type: 'success', message: `${team.name} has been created` }); - trackEvent(Submit.TeamCreate); + trackEvent(Submit.TeamCreate, { + customId: !!id + }); dispatch('created', team); } catch (e) { error = e.message; diff --git a/src/routes/console/project-[project]/auth/createUser.svelte b/src/routes/console/project-[project]/auth/createUser.svelte index 23601a143..13e4108a3 100644 --- a/src/routes/console/project-[project]/auth/createUser.svelte +++ b/src/routes/console/project-[project]/auth/createUser.svelte @@ -12,6 +12,7 @@ } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdkForProject } from '$lib/stores/sdk'; + import { ID } from '@aw-labs/appwrite-console'; import { createEventDispatcher } from 'svelte'; export let showCreate = false; @@ -25,7 +26,7 @@ const create = async () => { try { const user = await sdkForProject.users.create( - id ?? 'unique()', + id ?? ID.unique(), mail, phone, pass, @@ -38,7 +39,9 @@ type: 'success', message: `${user.name ? user.name : 'User'} has been created` }); - trackEvent(Submit.UserCreate); + trackEvent(Submit.UserCreate, { + customId: !!id + }); dispatch('created', user); } catch (e) { error = e.message; diff --git a/src/routes/console/project-[project]/databases/create.svelte b/src/routes/console/project-[project]/databases/create.svelte index 5ae47e569..237ed836a 100644 --- a/src/routes/console/project-[project]/databases/create.svelte +++ b/src/routes/console/project-[project]/databases/create.svelte @@ -5,6 +5,7 @@ import { Button, InputText, FormList } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdkForProject } from '$lib/stores/sdk'; + import { ID } from '@aw-labs/appwrite-console'; import { createEventDispatcher } from 'svelte'; export let showCreate = false; @@ -17,14 +18,16 @@ const create = async () => { try { - const database = await sdkForProject.databases.create(id ? id : 'unique()', name); + const database = await sdkForProject.databases.create(id ? id : ID.unique(), name); showCreate = false; dispatch('created', database); addNotification({ type: 'success', message: `${name} has been created` }); - trackEvent(Submit.DatabaseCreate); + trackEvent(Submit.DatabaseCreate, { + customId: !!id + }); name = id = null; } catch (error) { addNotification({ diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createDocument.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createDocument.svelte index b6c7cdce7..7819f11f4 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createDocument.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createDocument.svelte @@ -13,6 +13,7 @@ import type { WizardStepsType } from '$lib/layout/wizard.svelte'; import { Dependencies } from '$lib/constants'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; + import { ID } from '@aw-labs/appwrite-console'; const databaseId = $page.params.database; const collectionId = $page.params.collection; @@ -35,7 +36,7 @@ await sdkForProject.databases.createDocument( databaseId, collectionId, - $createDocument.id ?? 'unique()', + $createDocument.id ?? ID.unique(), $createDocument.document, $createDocument.permissions ); @@ -44,7 +45,9 @@ message: 'Document has been created', type: 'success' }); - trackEvent(Submit.DocumentCreate); + trackEvent(Submit.DocumentCreate, { + customId: !!$createDocument.id + }); invalidate(Dependencies.DOCUMENTS); createDocument.reset(); diff --git a/src/routes/console/project-[project]/databases/database-[database]/create.svelte b/src/routes/console/project-[project]/databases/database-[database]/create.svelte index 77003dec2..32c4bfa2c 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/create.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/create.svelte @@ -7,6 +7,7 @@ import { Button, InputText, FormList } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdkForProject } from '$lib/stores/sdk'; + import { ID } from '@aw-labs/appwrite-console'; import { createEventDispatcher } from 'svelte'; export let showCreate = false; @@ -22,7 +23,7 @@ try { const collection = await sdkForProject.databases.createCollection( databaseId, - id ? id : 'unique()', + id ? id : ID.unique(), name ); showCreate = false; @@ -32,7 +33,9 @@ message: `${name} has been created` }); name = id = null; - trackEvent(Submit.CollectionCreate); + trackEvent(Submit.CollectionCreate, { + customId: !!id + }); } catch (error) { addNotification({ type: 'error', diff --git a/src/routes/console/project-[project]/functions/createFunction.svelte b/src/routes/console/project-[project]/functions/createFunction.svelte index 335cb807a..17b88d4cd 100644 --- a/src/routes/console/project-[project]/functions/createFunction.svelte +++ b/src/routes/console/project-[project]/functions/createFunction.svelte @@ -16,6 +16,7 @@ import { base } from '$app/paths'; import { page } from '$app/stores'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; + import { ID } from '@aw-labs/appwrite-console'; const projectId = $page.params.project; @@ -25,7 +26,7 @@ async function create() { try { const response = await sdkForProject.functions.create( - $createFunction.id ?? 'unique()', + $createFunction.id ?? ID.unique(), $createFunction.name, $createFunction.execute, $createFunction.runtime, @@ -43,7 +44,9 @@ message: `${$createFunction.name} has been created`, type: 'success' }); - trackEvent(Submit.FunctionCreate); + trackEvent(Submit.FunctionCreate, { + customId: !!$createFunction.id + }); wizard.hide(); } catch (error) { addNotification({ diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/create.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/create.svelte index 8b5ad9801..5bdc48bf3 100644 --- a/src/routes/console/project-[project]/storage/bucket-[bucket]/create.svelte +++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/create.svelte @@ -9,6 +9,7 @@ import { Permissions } from '$lib/components/permissions'; import { addNotification } from '$lib/stores/notifications'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; + import { ID } from '@aw-labs/appwrite-console'; export let showCreate = false; @@ -24,7 +25,7 @@ async function create() { try { showCreate = false; - await uploader.uploadFile(bucketId, id, files[0], permissions); + await uploader.uploadFile(bucketId, id ?? ID.unique(), files[0], permissions); files = null; showCustomId = false; dispatch('created'); @@ -32,7 +33,9 @@ type: 'success', message: `File has been uploaded` }); - trackEvent(Submit.FileCreate); + trackEvent(Submit.FileCreate, { + customId: !!id + }); } catch (e) { error = e.message; trackError(e, Submit.FileCreate); diff --git a/src/routes/console/project-[project]/storage/create.svelte b/src/routes/console/project-[project]/storage/create.svelte index 304997c0f..586b90e2c 100644 --- a/src/routes/console/project-[project]/storage/create.svelte +++ b/src/routes/console/project-[project]/storage/create.svelte @@ -5,6 +5,7 @@ import { Button, InputText, FormList } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdkForProject } from '$lib/stores/sdk'; + import { ID } from '@aw-labs/appwrite-console'; import { createEventDispatcher } from 'svelte'; export let showCreate = false; @@ -18,7 +19,7 @@ const create = async () => { try { - const bucket = await sdkForProject.storage.createBucket(id ? id : 'unique()', name); + const bucket = await sdkForProject.storage.createBucket(id ? id : ID.unique(), name); showCreate = false; dispatch('created', bucket); addNotification({ @@ -26,7 +27,9 @@ message: `${name} has been created` }); name = null; - trackEvent(Submit.BucketCreate); + trackEvent(Submit.BucketCreate, { + customId: !!id + }); } catch (e) { error = e.message; trackError(e, Submit.BucketCreate); diff --git a/src/routes/register/+page.svelte b/src/routes/register/+page.svelte index 68a96de35..03657a94b 100644 --- a/src/routes/register/+page.svelte +++ b/src/routes/register/+page.svelte @@ -16,6 +16,7 @@ import FormList from '$lib/elements/forms/formList.svelte'; import { Dependencies } from '$lib/constants'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; + import { ID } from '@aw-labs/appwrite-console'; let name: string, mail: string, pass: string, disabled: boolean; let terms = false; @@ -23,7 +24,7 @@ async function register() { try { disabled = true; - await sdkForConsole.account.create('unique()', mail, pass, name ?? ''); + await sdkForConsole.account.create(ID.unique(), mail, pass, name ?? ''); await sdkForConsole.account.createEmailSession(mail, pass); await invalidate(Dependencies.ACCOUNT); await goto(`${base}/console`);