Learn business growth with Google Analytics 4 Forums Google Analytics 4 Measuring Duration of jQuery 'Modal' Opens with GA4 and GTM

  • Measuring Duration of jQuery 'Modal' Opens with GA4 and GTM

    Posted by Abigail on 21 April 2023 at 7:05 am

    Hey there, need a little help understanding how to track how long a user has a modal window open using Google Analytics and Google Tag Manager. I’m working with a non-Analytics Universal setup, so I’m guessing using GTM events is the best way to go.

    I notice there’s a “Timer” activator, but I’m a bit lost on how to put it to work. I reckon I can fire it up using Percent Visible (to know when the window’s open) and Click Classes (to keep an eye on the popup element), so it sends a ping every, say, XXX seconds. But the question is, how do I calculate the total time? And what TAG should I be using?

    — Just a bit more info —

    I’m using a jQuery modal. So it’s pretty simple, it’s just a hidden DIV that appears when a button gets pressed. If someone clicks outside the modal, or hit the close button, the DIV goes back into hiding. Because of this, I figure I can use Percent Visible that sends a ping every XXX seconds as long as the % visible is higher than 0.

    Thanks in advance!

    ===

    Jackson replied 1 year, 3 months ago 2 Members · 1 Reply
  • 1 Reply
  • Jackson

    Member
    21 June 2023 at 3:22 am

    To track how long a user has a modal window open, you can use the ‘Timer’ trigger in Google Tag Manager (GTM). Essentially, you want to start the timer when the modal is opened and stop it when the modal is closed. Send events to Google Analytics at these two points capturing the timestamp. The difference in time will give you the total time the modal was open. For your setup where you use a jQuery modal, use ‘Percent Visible’ to start the timer and ‘Click Classes’ (clicking outside the modal or the close button) to stop the timer.

Log in to reply.