- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Setting up GTM tracking for form submissions where the checkbox has been checked
‎Sep 27, 2019 9:59 AM - edited ‎Sep 27, 2019 10:28 AM
Hi there,
I've set up form tracking on GTM, but I'm now having issues with tracking specifically form submissions where the opt-in checkbox has also been checked. I've discovered that the ID
attribute of the checkbox is dynamic, which is why my custom javascript variable no longer works. This is what I have currently (which worked before the last four digits of the ID changed):
function() {
var checkbox = document.getElementById("LEGAL_CONSENT.subscription_type_6337149-8b3f66b8-292e-411d-a20e-f08f28554e60_7739");
return checkbox.checked || false;
}
Is there an easy workaround for this, such as selecting the element by an ID that starts with the portion that doesn't change?
EDIT:
I've replaced it with the following, but it's still not firing:
function() {
var checkbox = document.querySelector('[id^="LEGAL_CONSENT.subscription_type_6337149-8b3f66b8-292e-411d-a20e-f08f28554e60_"]');
return checkbox.checked || false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content