• Resolved rmmcclay

    (@rmmcclay)


    For example I want a custom link like: “mailto:[email protected]” to trigger a Google tracking bit like: ga(‘send’,’event’,’mailto’,’click’,’email clicked’);

    I’ve tried several ways using a bit of javascript, but can’t get it to work.

    Is there any way to do this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi rmmcclay,

    First, make sure the Mega Menu > General Settings > Unbind JavaScript Events is set to Disabled.

    Then you can use some jQuery like this (not tested or checked, but should give you the idea):

    $("#mega-menu-item-123 > a.mega-menu-link").on('click', function() {
        alert('clicked item 123');
    });

    Regards,
    Tom

    Thread Starter rmmcclay

    (@rmmcclay)

    Hi Tom!

    Really appreciate the reply. I set the Unbind JavaScript Event from Yes to No. Then tried this bit of code (put it in the footer, easily visible in the source):

    <script type='text/javascript'>
    $("#mega-menu-item-1744 > a.mega-menu-link").on('click', function() {
        alert('clicked item 1744');
    });
    </script>

    The site is: proqc.com, the link is the very top of the page, it’s “[email protected]”, a mailto link. Can’t trigger it with javascript for some reason.

    • This reply was modified 6 years, 5 months ago by rmmcclay.
    Plugin Author megamenu

    (@megamenu)

    Hi rm,

    You’re JS will need to go inside document.ready():

    https://digwp.com/2011/09/using-instead-of-jquery-in-wordpress/

    (check the console too for any errors, I just typed out that JavaScript – I did not check it in a browser)

    Regards,
    Tom

    Thread Starter rmmcclay

    (@rmmcclay)

    Hi Tom —

    That works! Thank you so much!

    -r

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to Add onclick event for Custom Menu Item’ is closed to new replies.