diff --git a/apps/web/analytics.ts b/apps/web/analytics.ts new file mode 100644 index 0000000..982c522 --- /dev/null +++ b/apps/web/analytics.ts @@ -0,0 +1,15 @@ +declare global { + interface Window { + dataLayer: any[]; + } +} + +export const initDataLayer = () => { + window.dataLayer = window.dataLayer || []; +}; + +export const pushToDataLayer = (event: string) => { + window.dataLayer.push({ + event, + }); +}; diff --git a/apps/web/index.html b/apps/web/index.html index 2bb2b3d..d4c4a81 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -12,8 +12,34 @@ /> DUMP Udruga mladih programera + + + + + + + +
diff --git a/apps/web/src/pages/ApplicationFormPage/ApplicationFormPage.tsx b/apps/web/src/pages/ApplicationFormPage/ApplicationFormPage.tsx index cc4b0f1..c2eecbf 100644 --- a/apps/web/src/pages/ApplicationFormPage/ApplicationFormPage.tsx +++ b/apps/web/src/pages/ApplicationFormPage/ApplicationFormPage.tsx @@ -6,9 +6,10 @@ import { import { Checkbox } from '@mui/joy'; import { Button, Input } from '@mui/material'; import clsx from 'clsx'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; +import { initDataLayer, pushToDataLayer } from '../../../analytics.ts'; import { usePostIntern } from '../../api/usePostIntern'; import formWelcomeImage from '../../assets/form-welcome-image.png'; import { ApplicationFormInputHandler } from '../../components/ApplicationFormInputHandler/ApplicationFormInputHandler'; @@ -60,7 +61,11 @@ export const ApplicationFormPage = () => { const { errors } = formState; - const onSubmit = (data: FormValues) => { + useEffect(() => { + initDataLayer(); + }, []); + + const onSubmit = async (data: FormValues) => { const internToSend = { firstName: data.firstName, lastName: data.lastName, @@ -78,9 +83,10 @@ export const ApplicationFormPage = () => { }; try { - createIntern.mutate(internToSend); + await createIntern.mutateAsync(internToSend); + pushToDataLayer('internship_prijava'); } catch (err) { - console.log(err); + console.log('Error', err); } };