From 9acd595bfd9fcdbe1cb0a4b0b003e846036b52cd Mon Sep 17 00:00:00 2001 From: Clark Sell Date: Mon, 18 Sep 2023 12:59:00 -0500 Subject: [PATCH] feat: adds some analytics --- src/_components/newsletter/HubspotForm.svelte | 4 ++++ src/lib/cart/cartMachine.js | 2 ++ .../emergency-contact/emergencyContactForm.svelte | 6 ++++++ .../(admin my)/my/profiles/primary/profileForm.svelte | 2 +- .../my/profiles/public/PublicProfileForm.svelte | 2 ++ .../my/profiles/shared/sharedProfileForm.svelte | 8 ++++++++ src/routes/(root)/orders/_components/_Cart.svelte | 3 +++ 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/_components/newsletter/HubspotForm.svelte b/src/_components/newsletter/HubspotForm.svelte index 12ea15e..cfbd58c 100644 --- a/src/_components/newsletter/HubspotForm.svelte +++ b/src/_components/newsletter/HubspotForm.svelte @@ -6,6 +6,7 @@ import { superForm, superValidateSync } from 'sveltekit-superforms/client'; import Icon from 'svelte-awesome'; import * as flashModule from 'sveltekit-flash-message/client'; + import va from '@vercel/analytics'; import { envelope } from '$components/svelte-awesome-icons'; import newsletterSchema from '$lib/formSchemas/newsletter'; @@ -28,6 +29,9 @@ syncFlashMessage: false, flashMessage: { module: flashModule + }, + onResult: () => { + va.track('form:newsletter:submitted'); } } ); diff --git a/src/lib/cart/cartMachine.js b/src/lib/cart/cartMachine.js index 2a9b188..92d3b5e 100644 --- a/src/lib/cart/cartMachine.js +++ b/src/lib/cart/cartMachine.js @@ -3,6 +3,7 @@ import { createMachine, assign } from 'xstate'; import lodash from 'lodash'; import dayjs from 'dayjs'; import isBetween from 'dayjs/plugin/isBetween.js'; +import va from '@vercel/analytics'; import { log } from '../error'; import createConfig from './cartConfig'; @@ -148,6 +149,7 @@ function createServices() { } const { id, quantity = 1, price, name, description, productType } = event; + va.track('cart:add-item', { name, price, productType }); const currentCart = context.cart; diff --git a/src/routes/(admin my)/my/profiles/emergency-contact/emergencyContactForm.svelte b/src/routes/(admin my)/my/profiles/emergency-contact/emergencyContactForm.svelte index a21450f..58b7e13 100644 --- a/src/routes/(admin my)/my/profiles/emergency-contact/emergencyContactForm.svelte +++ b/src/routes/(admin my)/my/profiles/emergency-contact/emergencyContactForm.svelte @@ -5,6 +5,7 @@ import * as flashModule from 'sveltekit-flash-message/client'; import { AlertOctagon } from 'lucide-svelte'; import Select from 'svelte-select'; + import va from '@vercel/analytics'; import { DisabledShell, Shell } from '$elements/buttons'; @@ -20,6 +21,11 @@ taintedMessage: null, // todo - @csell phone number formatting taints the form. flashMessage: { module: flashModule + }, + onUpdated: ({ form }) => { + if (form.valid) { + va.track('form:emergency-contact:submitted'); + } } }); diff --git a/src/routes/(admin my)/my/profiles/primary/profileForm.svelte b/src/routes/(admin my)/my/profiles/primary/profileForm.svelte index fab2a72..eb699ed 100644 --- a/src/routes/(admin my)/my/profiles/primary/profileForm.svelte +++ b/src/routes/(admin my)/my/profiles/primary/profileForm.svelte @@ -21,7 +21,7 @@ }, onResult: ({ result }) => { if (result.status === 303) { - va.track('Profile Updated'); + va.track('form:system-profile:submitted'); invalidateAll(); } } diff --git a/src/routes/(admin my)/my/profiles/public/PublicProfileForm.svelte b/src/routes/(admin my)/my/profiles/public/PublicProfileForm.svelte index 75b5633..b039a7d 100644 --- a/src/routes/(admin my)/my/profiles/public/PublicProfileForm.svelte +++ b/src/routes/(admin my)/my/profiles/public/PublicProfileForm.svelte @@ -12,6 +12,7 @@ import Checkbox from 'svelte-checkbox'; import lodash from 'lodash'; import { AlertOctagon } from 'lucide-svelte'; + import va from '@vercel/analytics'; import config from '$lib/config.public'; import publicProfileSchema from '$lib/formSchemas/publicProfile'; @@ -33,6 +34,7 @@ onUpdated: ({ form }) => { if (form.valid) { invalidateAll(); + va.track('form:public-profile:submitted'); } } }); diff --git a/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte b/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte index 393851e..14f10fe 100644 --- a/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte +++ b/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte @@ -2,11 +2,13 @@ export let sForm; import { getContext } from 'svelte'; + import { invalidateAll } from '$app/navigation'; import { superForm } from 'sveltekit-superforms/client'; import * as flashModule from 'sveltekit-flash-message/client'; import { AlertOctagon } from 'lucide-svelte'; import Select from 'svelte-select'; + import va from '@vercel/analytics'; import { DisabledShell, Shell } from '$elements/buttons'; import sharedProfileFormSchema from '$lib/formSchemas/sharedProfile'; @@ -20,6 +22,12 @@ taintedMessage: null, // todo - @csell phone number formatting taints the form. flashMessage: { module: flashModule + }, + onUpdated: ({ form }) => { + if (form.valid) { + invalidateAll(); + va.track('form:public-profile:submitted'); + } } }); diff --git a/src/routes/(root)/orders/_components/_Cart.svelte b/src/routes/(root)/orders/_components/_Cart.svelte index 0ab5e24..c7daa51 100644 --- a/src/routes/(root)/orders/_components/_Cart.svelte +++ b/src/routes/(root)/orders/_components/_Cart.svelte @@ -12,6 +12,7 @@ import orderMutations from '$dataSources/api.that.tech/orders/mutations'; import CartItem from './_CartItem.svelte'; import { tagEvent } from '$lib/tagEvent'; + import va from '@vercel/analytics'; const { state, send } = getContext('cart'); let apiErrorMessage = ''; @@ -23,6 +24,7 @@ level: 'info' }); + va.track('cart:handle-checkout'); Sentry.configureScope((scope) => scope.setTransactionName('Handle Checkout')); const { eventId, cart } = $state.context; @@ -47,6 +49,7 @@ ); if (checkoutSessionResults.success) { + va.track('cart:handle-checkout:redirect'); stripe.redirectToCheckout({ sessionId: checkoutSessionResults.stripeCheckoutId }); } else { Sentry.captureException(checkoutSessionResults.message);