
Tagged: CONTACT FORM, enfold, google tag manager, GTM
-
AuthorPosts
-
July 24, 2025 at 3:10 pm #1487186
Hi everyone,
I need your help and I’m a bit lost. I’m trying to track form submissions from the Enfold contact form using Google Tag Manager.
I’ve already added the following code to the functions.php file, as recommended in this thread: https://kriesi.at/support/topic/contact-form-tracking-with-gtm/
add_filter(‘avf_contact_form_submit_button_attr’,’avia_add_submit_attributes_to_cf’, 10, 3);
function avia_add_submit_attributes_to_cf($att, $formID, $form_params){
$att = “onsubmit =\” dataLayer.push({‘event’: ‘form-submission’}); \””;
return $att;
}
Everything in GTM seems to be set up correctly, but for some reason, the event isn’t firing. Does anyone have an idea what I might be missing?Best regards,
ChrisJuly 25, 2025 at 7:26 am #1487219Hey christianh150,
Thank you for the inquiry.
Did you create a custom GTM event for the form-submission? Please check this article and watch the video for more info.
— https://support.google.com/analytics/answer/12229021?sjid=3714059059832338320-NC
— https://www.youtube.com/watch?v=QmEOPuJr05wLet us know if you need more info.
Best regards,
IsmaelJuly 25, 2025 at 8:00 am #1487221Hi,
yes. I have created a Form-Submission GA4 Event in GTM.
B.r.
ChrirsJuly 26, 2025 at 7:21 am #1487256Hello,
I looked at the documentation and the video again. I implemented everything exactly as described.
Other tags are fired. It’s really only about the GA4 event form submission with the Enfold contact form. That is not fired.
Best regards,
ChrisJuly 27, 2025 at 11:16 am #1487264Still have the problem.
b.r.
ChrisJuly 28, 2025 at 7:15 am #1487274Hi,
Thank you for the update.
The screenshots above are not available. Please create a test page and provide the link so we can check the issue further. You can use platforms like Savvyify, Imgur, or Dropbox for the screenshots.
Best regards,
IsmaelJuly 28, 2025 at 7:35 am #1487276Hi,
here the Screenshots.
Hope this helps.https://img.savvyify.com/image/Bildschirmfoto-2025-07-28-um-07.33.52.y92mX
https://img.savvyify.com/image/Bildschirmfoto-2025-07-28-um-07.33.48.y9AtM
https://img.savvyify.com/image/Bildschirmfoto-2025-07-28-um-07.33.06.y9jMA
https://img.savvyify.com/image/Bildschirmfoto-2025-07-28-um-07.32.57.y9qI3b.r.
ChrisJuly 28, 2025 at 7:45 am #1487278Hi,
Thank you for the update.
The name of the event is form_submission (with underscore, not hyphen), so you’ll have to update this in the avf_contact_form_submit_button_attr filter.
add_filter('avf_contact_form_submit_button_attr', 'avia_add_submit_attributes_to_cf', 10, 3); function avia_add_submit_attributes_to_cf($att, $formID, $form_params) { $att = 'onsubmit="dataLayer.push({\'event\': \'form_submission\'});"'; return $att; }
Provide the link to the page with the contact form so we can check it.
Best regards,
IsmaelJuly 28, 2025 at 7:52 am #1487279OK I’ll change this and will try again.
Link to form: thinkiq.ch
b.r.
ChrisJuly 28, 2025 at 8:31 am #1487281Still no change.
Actually the eventname is “lead_form_submission”, isn’t it?
add_filter(‘avf_contact_form_submit_button_attr’, ‘avia_add_submit_attributes_to_cf’, 10, 3);
Maybe try this?
function avia_add_submit_attributes_to_cf($att, $formID, $form_params) {
$att = ‘onsubmit=”dataLayer.push({\’event\’: \’lead_form_submission\’});”‘;
return $att;
}July 28, 2025 at 9:03 am #1487282If I modify functions.php and test gtm, should it be applied immediately and work, or does it always take some time?
July 28, 2025 at 9:20 pm #1487308Any other solutions? Or do you need any more informations?
July 29, 2025 at 6:46 am #1487322Hi,
Is there a test page we can check? We would like to verify if the dataLayer.push is actually triggered when the submit button is clicked. Please create a test page and provide the site URL in the private field.
Best regards,
IsmaelJuly 29, 2025 at 7:11 am #1487324Hi,
I have created a testpage. see in private content.
b.r.
Chris
July 29, 2025 at 7:38 am #1487326Hi,
The function is not triggered when the submit button is clicked, probably because the contact form does not have a unique ID (form_id) and the form_url is not properly set in the trigger. Please review the video around the 4-minute mark and make sure that a custom trigger is created for the event.
— https://youtu.be/QmEOPuJr05w?t=246
To apply an ID to the contact form, edit the contact form element, go to the Advanced > Developer Settings, and look for the Custom ID Attribute field.
Again, make sure to configure the event trigger as shown here: https://youtu.be/QmEOPuJr05w?t=246
Let us know the result.
Best regards,
IsmaelJuly 29, 2025 at 9:24 am #1487327Hi,
I have now watched the video and assigned an ID to the form as described. The tag/trigger still did not fire.
I have now taken a screenshot of everything for you. See Private Content.
This isn’t the first time I’ve used GTM. On another website where I use Enfold, it was enough to just edit the functions.php.
I hope the screenshots help.
Best regards,
ChrisJuly 30, 2025 at 7:34 am #1487374Hi,
Thank you for the update.
We may need to log in to the site to properly check this, and we recommend hiring a developer or specialist to help you correctly set up your GTM events and integrate them with the contact form.
In the meantime, try to remove the submit button filter and replace it with this code.
// trigger gtm event when the form is submitted add_action( 'wp_footer', function () { ?> <script> document.addEventListener('DOMContentLoaded', function () { if (typeof window.dataLayer === 'undefined' || !Array.isArray(window.dataLayer)) { console.warn('dataLayer is not available. Skipping form submission tracking.'); return; } const responseEl = document.getElementById('ajaxresponse_1'); if (!responseEl) return; const observer = new MutationObserver(function (mutationsList) { for (const mutation of mutationsList) { if ( mutation.type === 'attributes' && (mutation.attributeName === 'class' || mutation.attributeName === 'style') ) { const isVisible = !responseEl.classList.contains('hidden') && responseEl.style.display !== 'none'; if (isVisible) { window.dataLayer.push({ event: 'form_submission' }); console.log('dataLayer push: form_submission'); observer.disconnect(); break; } } } }); observer.observe(responseEl, { attributes: true, attributeFilter: ['class', 'style'] }); }); </script> <?php }, 9999 );
Let us know the result.
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.