Skip to content

Commit

Permalink
Merge pull request #196 from dump-hr/Andrea/analitika
Browse files Browse the repository at this point in the history
GTM submission tracking
  • Loading branch information
bdeak4 authored Oct 2, 2024
2 parents ac53870 + f452ba6 commit 82cbf7a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
15 changes: 15 additions & 0 deletions apps/web/analytics.ts
Original file line number Diff line number Diff line change
@@ -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,
});
};
26 changes: 26 additions & 0 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,34 @@
/>
<link rel="icon" href="./src/assets/favicon.ico" />
<title>DUMP Udruga mladih programera</title>

<!-- Google Tag Manager -->
<script>
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-WRPZN2L');
</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript
><iframe
src="https://www.googletagmanager.com/ns.html?id=GTM-WRPZN2L"
height="0"
width="0"
style="display: none; visibility: hidden"
></iframe
></noscript>
<!-- End Google Tag Manager (noscript) -->

<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
Expand Down
14 changes: 10 additions & 4 deletions apps/web/src/pages/ApplicationFormPage/ApplicationFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
};

Expand Down

0 comments on commit 82cbf7a

Please sign in to comment.