Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • #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,
    Chris

    #1487219

    Hey 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=QmEOPuJr05w

    Let us know if you need more info.

    Best regards,
    Ismael

    #1487221

    Hi,

    yes. I have created a Form-Submission GA4 Event in GTM.

    Trigger Config

    GA4 Event

    B.r.
    Chrirs

    #1487256

    Hello,
    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,
    Chris

    #1487264

    Still have the problem.
    b.r.
    Chris

    #1487274

    Hi,

    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,
    Ismael

    #1487276
    #1487278

    Hi,

    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,
    Ismael

    #1487279

    OK I’ll change this and will try again.

    Link to form: thinkiq.ch

    b.r.
    Chris

    #1487281

    Still 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;
    }

    #1487282

    If I modify functions.php and test gtm, should it be applied immediately and work, or does it always take some time?

    #1487308

    Any other solutions? Or do you need any more informations?

    #1487322

    Hi,

    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,
    Ismael

    #1487324

    Hi,

    I have created a testpage. see in private content.

    b.r.

    Chris

    #1487326

    Hi,

    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.

    View post on imgur.com

    Again, make sure to configure the event trigger as shown here: https://youtu.be/QmEOPuJr05w?t=246

    Let us know the result.

    Best regards,
    Ismael

    #1487327

    Hi,

    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,
    Chris

    #1487374

    Hi,

    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

Viewing 17 posts - 1 through 17 (of 17 total)
  • You must be logged in to reply to this topic.