-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EL-1751:
form_submission
event not firing in GA4 (#356)
- amend `id` for one of the questions - remove `novalidate` in form - adjust the JS and run only when cookies are allowed - remove other redundant inline JS
- Loading branch information
1 parent
c161882
commit 434aaae
Showing
5 changed files
with
44 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fala_form = document.querySelector('#fala_questions'); | ||
|
||
function getCookie(name) { | ||
const value = `; ${document.cookie}`; | ||
const parts = value.split(`; ${name}=`); | ||
if (parts.length === 2) return parts.pop().split(';').shift(); | ||
return null; | ||
} | ||
|
||
const cookie_value = getCookie('cookiePermission') === 'Allowed'; | ||
|
||
if (fala_form && cookie_value) { | ||
fala_form.addEventListener('submit', function(e){ | ||
|
||
// variables for postcode and organisation name | ||
const postcode = document.querySelector("#id_postcode").value; | ||
const organisation = document.querySelector("#id_name").value; | ||
|
||
// variables for checkbox | ||
const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked'); | ||
const selected = Array.from(checkboxes).map(x => x.value); | ||
|
||
window.dataLayer.push({ | ||
'event': "formSubmission", | ||
'postcode': postcode, | ||
'organisation': organisation, | ||
'checkbox': selected, | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters