Event triggers when popup opens and closes

Hi,

I'm using mouseflow to record what users are doing on the site and for how long they for example preview content I have on a popup.
Is there an easy way to add two triggers onto those popups? One would be when the popup is shown (all popups are shown straight away after opening a page) the other one is when they close it.

Here's what I got from Mouseflow support:

// When popup is opened, set the variable to the current time
var mf_timer = Date.now();

// When popup is closed, get the difference, send to Mouseflow and reset timer
var mf_timer = Date.now() - timer;
_mfq.push(["tag", "Popup open " + parseFloat(mf_timer/1000) + " seconds"]);
var mf_timer = null;

Is there a way to use the plugin to do that or do I need to hardcode this in one of the files? If that's the case which file should I edit?

Best Regards,
Rafal

  • Rupok

    Hi Rafal, hope you had a wonderful day.

    Is there a way to use the plugin to do that or do I need to hardcode this in one of the files? If that's the case which file should I edit?

    Actually you don't need to hardcode this in any of the plugin core file. Rather you can create a MU Plugin for doing this. For creating a mu plugin, create a folder named "mu-plugins" inside your "wp-content" folder. Then inside that "mu-plugins" folder, create a file with any name and with a .php extension. Now paste the code inside that file and save.

    <?php
    add_action( 'wp_footer', 'mouse_movement' );
    function mouse_movement() {
        ?>
        <script type="text/javascript">
            // Your JavaScript Code Here
        </script>
        <?php
    }

    For getting more idea on mu plugins, you can go through this article: http://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Please let us know if you have any confusion. We will be glad to help.

    Have a nice day. Cheers!
    Rupok

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.