can not tract forms event
-
Thank you to the creator for developing this plugin. Overall, it works great and has also sped up the website. However, a few days ago, after upgrading to the latest version of the plugin and WordPress, the forms are no longer being tracked. The website is using WPForms. It was working fine before the update a week ago.
Additionally, I would like to ask the creator how to set up tracking for forms. For example, I am using WPForms with two forms, each having a different form ID. One form is on the “Contact Us” page, and the other is on the product page. How can I set up tracking for these two different forms to trigger tracking when the form is opened and submitted?
The page I need help with: [log in to see the link]
-
Great to hear that the plugin and Zaraz in general have helped your site speed. Meta, Google and other tracking scripts are just getting larger and larger, so we also really like the approach Zaraz have taken on tracking which benefits a lot of users.
I dont know which version you had before the upgrade, but when it comes to tracking forms we have not change any behaviour on how forms at tracked. I did however do a test you your page and noticed that WPForms is submitting the form via ajax, which of cause is common practice.
We are however listening for a submit event which WPForms might also do, but if they “steal” that event and is it not propagated to our plugin is never going to receive this, so the missing event might also be because of a WPForms update.
We are however planing to incorporate the most used form plugins into our tracking, and here WPForm definitely is one of them.
But for now a way to fix it, is by using similar approach in their documentation here:
https://wpforms.com/developers/how-to-open-a-new-link-on-form-submission/
The the code should look like this:/** * WPForms: Track form submissions with Beetle Tracking * * @link https://www.ads-software.com/support/topic/can-not-tract-forms-event/ */ function wpf_dev_event_after_submit() { ?> <script type="text/javascript"> ( function() { jQuery( window ).on( 'load', function() { // Change your form ID or replace it to the .wpforms-form container. jQuery( '.wpforms-ajax-form' ).on( 'wpformsAjaxSubmitSuccess', function( e, response ) { beetle_tracking.track('Form', { window.form_id: $(this).attr('data-formid') }); } ); } ) }() ); </script> <?php } add_action('wpforms_wp_footer_end', 'wpf_dev_event_after_submit', 10);
What happens here is it will Submit a “Form” event to Zaraz which is the one we have in our configuration and then it will add the parameter of form_id which is the id of the form submitted.
I hope this helps you until we have an official integration with WPFormsthank for the reply. I had tried that code, but it seem not working.
function wpf_dev_event_after_submit() { ?> <script type="text/javascript"> (function() { jQuery(window).on('load', function() { // Bind to the form submission success event for WPForms forms submitted via AJAX. jQuery('.wpforms-ajax-form').on('wpformsAjaxSubmitSuccess', function(e, response) { // Retrieve the form ID attribute. var formId = jQuery(this).attr('data-formid'); // Check if the form ID matches one of the targeted forms. if (formId === '7729' || formId === '7705') { // Track the event with Beetle Tracking, including the form ID. beetle_tracking.track('Form Submission', { 'form_id': formId }); } }); }); })(); </script> <?php } add_action('wp_footer', 'wpf_dev_event_after_submit', 10);
I just tested without WP Rocket enabled, because there is a lot of js errors when it is enabled, and then I can see that this event is fired: “Form Submission” I dont know if you have configurated that yourself in Zaraz. Our configuration is including the event called “Form”
https://drive.google.com/file/d/177ZGgi89310VKuFVQzComLsQoJ1DagMT/view
- This reply was modified 8 months, 2 weeks ago by Rocket Beetle.
It’s very strange; I did receive the form submissions you mentioned from [email protected] and [email protected] 2 testing submit email. I just checked the GA4 dashboard and the Cloudflare backend, and from the 5th until now, there hasn’t been a single form trigger. Before the 5th, I tested it and there were three triggers can make.
By the way, I configured Zaraz in Cloudflare following your plugin’s instruction video guide, and I have reset it again and reinstalled it one more time.
It just simple export config and import to cloudflare, this should cannot be mistake. the thing is, the other event, like visit site, add cart, view list this be seen on GA$, except the form not trigger at all.
- This reply was modified 8 months, 2 weeks ago by syberpunk2027.
I think I have a rough idea of what might be causing this. Please take a look at the two images below to understand. Zaraz backend does track it, but it’s not being passed to GA4. It seems to be an issue with parameter settings, but I’m unsure how to adjust them. I imported it as per the default tutorial. I hope the creator can provide guidance on how to set up tracking for two different forms with separate form IDs (WPForms) to trigger tracking when the form is opened and submitted.
https://drive.google.com/file/d/1D3xBlSUJfik7B1RudNSXjDc3AYhVH8CQ/view?usp=drive_link
https://drive.google.com/file/d/1zoHpbbq8jvtNIfKOgVwQMemaWdiUb6WJ/view?usp=drive_link
I have altered your code, please try with that:
function wpf_dev_event_after_submit() { ?> <script type="text/javascript"> (function() { jQuery(window).on('load', function() { // Bind to the form submission success event for WPForms forms submitted via AJAX. jQuery('.wpforms-ajax-form').on('wpformsAjaxSubmitSuccess', function(e, response) { // Retrieve the form ID attribute. var formId = jQuery(this).attr('data-formid'); // Check if the form ID matches one of the targeted forms. if (formId === '7729' || formId === '7705') { // Track the event with Beetle Tracking, including the form ID. beetle_tracking.track('Form', { 'form_id': formId }); } }); }); })(); </script> <?php } add_action('wp_footer', 'wpf_dev_event_after_submit', 10);
thank, now this code works. it make GA4 show a”Forms” event.
By the way, one more question: 2 forms, One form is on the “Contact Us” page, and the other is on the product page. How can I set up tracking for these two different forms sepereted to trigger , such as “Form-product” and “form-containe” on GA4, when the form is opened and submitted?
They are going to have two different form_id which also should be submitted to GA4, but both event will be the event called “Form”, but try to see if you can show the attributes which form_id will be an attribute.
We are considering when make our integration to form plugins that it will actually use the Form Title which would be a better attribute, but for now form_id was the easy part to include.Hi, same issue here but different scenario:
– Contact Form 7 Version 5.9.6
– Beetle Tracking Version 1.5.8
– Simple Cloudflare Turnstile Version 1.26.2
– Chrome 126.0.6478.127 (Build oficial) (64 bits)
test form here: https://khaledat.com/under-construction/email is sent by CF7 ajax but no form event is tracked in Zaraz / GA4
I’m also receiving this console error:
TypeError: Cannot read properties of null (reading ‘tagName’)
at HTMLDocument. (public.js?ver=8ee7bff1516f64240ca5:1:2343)text: "INPUT" === t.querySelector('[type="submit"]').tagName ? t.querySelector('[type="submit"]').value : t.querySelector('[type="submit"]').textContent
As it is right now, the plugin only support standard form event, and seams like Contact Form 7, does not have a Normal “submit” button, so that the reason for the error.
We are however working on upgrades, and as I said before form plugins is a focus of ours, but it seamed like your did find a good way to track the form anyway here:
https://www.ads-software.com/support/topic/workaround-for-tracking-contact-form-7/
- You must be logged in to reply to this topic.