Title: Javascript when submitting Topbar
Last modified: July 8, 2020

---

# Javascript when submitting Topbar

 *  Resolved [garfula43](https://wordpress.org/support/users/garfula43/)
 * (@garfula43)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/javascript-when-submitting-topbar/)
 * 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](https://wordpress.org/support/users/lapzor/)
 * (@lapzor)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/javascript-when-submitting-topbar/#post-13093744)
 * 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](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](https://wordpress.org/support/users/dvankooten/)
 * (@dvankooten)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/javascript-when-submitting-topbar/#post-13124901)
 * Hello [@garfula43](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/mailchimp-top-bar/assets/icon-256x256.png?rev=1224622)
 * [MC4WP: Mailchimp Top Bar – Email Subscribe Notification Bar](https://wordpress.org/plugins/mailchimp-top-bar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailchimp-top-bar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailchimp-top-bar/)
 * [Active Topics](https://wordpress.org/support/plugin/mailchimp-top-bar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailchimp-top-bar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailchimp-top-bar/reviews/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [submit](https://wordpress.org/support/topic-tag/submit/)

 * 2 replies
 * 3 participants
 * Last reply from: [Danny van Kooten](https://wordpress.org/support/users/dvankooten/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/javascript-when-submitting-topbar/#post-13124901)
 * Status: resolved