diff --git a/package.json b/package.json index 3b8091b..95b4cad 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "prettier": "^3.2.2", "tailwindcss": "^3.4.1", "typescript": "^5.2.2", - "vite": "^5.0.8" + "vite": "^5.0.8", + "vite-plugin-radar": "^0.9.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47cac8a..555e685 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -109,6 +109,9 @@ devDependencies: vite: specifier: ^5.0.8 version: 5.0.8(@types/node@20.11.2) + vite-plugin-radar: + specifier: ^0.9.2 + version: 0.9.2(vite@5.0.8) packages: @@ -4523,6 +4526,14 @@ packages: /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + /vite-plugin-radar@0.9.2(vite@5.0.8): + resolution: {integrity: sha512-cIwA7EU/6kqIPjSAFIjpnleJBtDVxw0lBwMyWIp8kit/O3XehHly+B6jCN7FbfQjniRxEtBarEzrLB+FmKSnAg==} + peerDependencies: + vite: ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 + dependencies: + vite: 5.0.8(@types/node@20.11.2) + dev: true + /vite@5.0.8(@types/node@20.11.2): resolution: {integrity: sha512-jYMALd8aeqR3yS9xlHd0OzQJndS9fH5ylVgWdB+pxTwxLKdO1pgC5Dlb398BUxpfaBxa4M9oT7j1g503Gaj5IQ==} engines: {node: ^18.0.0 || >=20.0.0} diff --git a/src/components/petition.tsx b/src/components/petition.tsx index 0595937..a7adce0 100644 --- a/src/components/petition.tsx +++ b/src/components/petition.tsx @@ -34,6 +34,12 @@ const PETITION_API_URL = "https://petitions-229503.appspot.com/api/sign"; const CAMPAIGN_MAILER_API_URL = "https://helptheducks.dxe.io/message/create"; +declare global { + interface Window { + dataLayer?: any[]; + } +} + export const Petition = () => { const form = useForm({ resolver: zodResolver(PetitionFormSchema), @@ -59,6 +65,9 @@ export const Petition = () => { const onSubmit = useMemo( () => handleSubmit(async (data) => { + window.dataLayer?.push({ + event: "form_submitted", + }); // We purposefully do these one at a time. If the first one fails, // we don't want to submit the second one. This allows the user to // resubmit the form without causing duplicate emails to be sent. diff --git a/src/data/petition.ts b/src/data/petition.ts index d0e87f5..af8aeb9 100644 --- a/src/data/petition.ts +++ b/src/data/petition.ts @@ -40,6 +40,15 @@ export const PetitionFormSchema = z // If outside of US, throw away the zip code. if (data.outsideUS) { data.zip = undefined; + } else { + // If inside US, zip code is required. + if (!data.zip) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: "Zip code is required", + path: ["zip"], + }); + } } const isInSonoma = !!( data.zip && diff --git a/vite.config.ts b/vite.config.ts index d18ad2f..5258884 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,10 +2,38 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import { TanStackRouterVite } from "@tanstack/router-vite-plugin"; import path from "path"; +import { VitePluginRadar } from "vite-plugin-radar"; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react(), TanStackRouterVite()], + plugins: [ + react(), + TanStackRouterVite(), + VitePluginRadar({ + /** + * enable or disable scripts injection in development + * default: false + */ + enableDev: true, + // Google Analytics (multiple tag can be set with an array) + analytics: [ + { + id: "G-2WJVQ0EX4G", + disable: false, + config: { + cookie_domain: "auto", + cookie_expires: 63072000, + cookie_prefix: "none", + cookie_update: true, + cookie_flags: "", + send_page_view: true, + allow_google_signals: true, + allow_ad_personalization_signals: true, + }, + }, + ], + }), + ], resolve: { alias: { "~": path.resolve(__dirname, "./src"),