Hi everyone,
I’m running a wordpress landingpage with contact form 7. Matomo should track the submission of the form as a manual defined conversion goal. Here is the code
function mycustom_wp_footer() {
?>
var wpcf7Elm = document.querySelector( ‘.wpcf7’ );
The contact form is working and my test submissions are beeing tracked. But somehow I get conversions without the form beeing submitted. Is anything wrong with my code?
It looks like the code you provided is generally correct, but there may be an issue with how the event listener is being triggered. One possible reason for false conversions could be that the form submission is triggering the conversion tracking event more than once, or it’s being fired before the actual submission happens.
Here are a few things you might want to try:
Ensure the Event Listener Is Only Triggered Once:
It’s possible that the listener is getting triggered multiple times if wpcf7Elm isn’t properly initialized. You could try adding a condition to ensure that the trackGoal function is only called after the form submission is fully completed.
var wpcf7Elm = document.querySelector('.wpcf7');
if (wpcf7Elm) {
wpcf7Elm.addEventListener('wpcf7submit', function (event) {
if (!event.detail.status) return; // Check if submission was successful
window._paq = window._paq || [];
window._paq.push(['trackGoal', 1]);
}, false);
}
Check If Any Other Scripts Are Interfering:
Sometimes other plugins or scripts might trigger form submissions or events that could be mistaken for actual submissions. Make sure no other scripts are submitting the form or triggering a false event.