Last active
June 3, 2025 16:48
-
-
Save bobbydank/864385714fb7a5532b6ac2e22c4a1f5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
// add data to data layer | |
function cl_wpforms_datalayer_footer_script() { | |
?> | |
<script> | |
jQuery(document).on('wpformsAjaxSubmitSuccess', function (event, response, form) { | |
var userData = {}; | |
var $form = jQuery(jQuery('form#***')); // Ensure form ID Correct | |
if ($form.length) { | |
// First Name | |
$form.find('input[name="***"]').each(function () { | |
userData.first_name = jQuery(this).val(); | |
}); | |
// Last Name | |
$form.find('input[name="***"]').each(function () { | |
userData.last_name = jQuery(this).val(); | |
}); | |
$form.find('input[name="***"]').each(function () { | |
userData.email = jQuery(this).val(); | |
}); | |
// Phone | |
$form.find('input[name="***"]').each(function () { | |
userData.phone = jQuery(this).val(); | |
}); | |
// Comment | |
$form.find('textarea[name="***"]').each(function () { | |
userData.comment = jQuery(this).val(); | |
}); | |
// Zip | |
$form.find('input[name="***"]').each(function () { | |
userData.zip = jQuery(this).val(); | |
}); | |
userData.country = "US"; | |
// Push to data layer | |
window.dataLayer = window.dataLayer || []; | |
window.dataLayer.push({ | |
'event': 'gtm.click', | |
'gtm.conversion_id': 'wpforms-submission-success-1231', // Match Click ID | |
'gtm.user_data': userData, | |
}); | |
} | |
}); | |
</script> | |
<?php | |
} | |
add_action('wp_footer', 'cl_wpforms_datalayer_footer_script'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment