• Resolved garfula43

    (@garfula43)


    Hello
    I’m using the Topbar together with the MC4WP WP plugin. We use Matomo for analytics and I’d like to trigger an event whenever a user submits the newsletter signup form. That works fine for the MC4WP form (just added the script). However if the user signs up with the topbar the event isn’t triggered. Is there a way to run the javascript also with the topbar? Thanks for your help.

    Infos:
    MC4WP: Mailchimp for WordPress: Version 4.7.8
    MC4WP: Mailchimp Top Bar: Version 1.5.2
    Wordpress Theme: Twentyseventeen (Version: 2.3)
    Wordpress: Version 5.4.2

    Help is much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Lap

    (@lapzor)

    As far as I know the TopBar indeed doesn’t trigger any JS events.
    I put in a feature request for you here: https://github.com/ibericode/mailchimp-top-bar/issues/85

    If/when this will actually be added I can’t say yet.

    Hope that helps. If you have any questions, please let me know!

    Plugin Author Danny van Kooten

    (@dvankooten)

    Hello @garfula43,

    You can use the following piece of JavaScript for hooking into Top Bar submits:

    
    document.querySelector('#mailchimp-top-bar form').addEventListener('submit', function() {
    	// your code goes here
    });
    

    If you’re adding code to your website through a functions.php file then you can use the following:

    
    add_action('wp_footer', function() {
    	?>
    	<script>
    		document.querySelector('#mailchimp-top-bar form').addEventListener('submit', function() {
    			// your code goes here
    		});
    	</script>
    	<?php
    }, 20 );
    

    Hope that helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Javascript when submitting Topbar’ is closed to new replies.