How to Track Pop-up Events with Google Tag Manager (GTM) and GA4
Vitals dispatches custom JavaScript events when visitors interact with your Pop-ups. You can use these events to send tracking data to Google Tag Manager (GTM) and Google Analytics 4 (GA4).
Available Events
| Event Name | Fires When |
|---|---|
vitals:popup:view |
A popup is displayed to the visitor |
vitals:popup:close |
A popup is dismissed |
vitals:popup:submit |
An email capture form is successfully submitted |
Each event includes the following data in event.detail :
| Property | Type | Description |
|---|---|---|
popupId |
number | The unique ID of the popup |
popupType |
string | The popup type: lead_capture , discount_capture , or click_through |
Step 1 — Add Custom JavaScript in Vitals
- Go to Vitals → Preferences
- Scroll to the Custom JS Last field
- Paste the following code:
(function() {
window.dataLayer = window.dataLayer || [];
document.addEventListener('vitals:popup:view', function(e) {
window.dataLayer.push({
event: 'vitals_popup_view',
vitals_popup_id: e.detail.popupId,
vitals_popup_type: e.detail.popupType
});
});
document.addEventListener('vitals:popup:close', function(e) {
window.dataLayer.push({
event: 'vitals_popup_close',
vitals_popup_id: e.detail.popupId,
vitals_popup_type: e.detail.popupType
});
});
document.addEventListener('vitals:popup:submit', function(e) {
window.dataLayer.push({
event: 'vitals_popup_submit',
vitals_popup_id: e.detail.popupId,
vitals_popup_type: e.detail.popupType
});
});
})();
- Click Save
Tip: You can remove any of the three listeners if you only need to track specific interactions.
Step 2 — Create Triggers in GTM
- Open Google Tag Manager
- Go to Triggers → New
- Choose trigger type: Custom Event
- Set Event name to one of:
vitals_popup_view— to track popup impressionsvitals_popup_close— to track popup dismissalsvitals_popup_submit— to track form submissions
- Click Save
Repeat for each event you want to track.
Step 3 — Create GA4 Event Tags
- In GTM, go to Tags → New
- Choose tag type: Google Analytics: GA4 Event
- Select your GA4 Configuration tag
- Set an Event name (e.g.
popup_submit) - (Optional) Add Event Parameters:
- Parameter name:
popup_id→ Value:{{DLV - vitals_popup_id}} - Parameter name:
popup_type→ Value:{{DLV - vitals_popup_type}}
- Parameter name:
- Under Triggering, select the trigger you created in Step 2
- Click Save, then Publish your GTM container
Note: For the optional parameters in step 5, create a Data Layer Variable in GTM for each: go to Variables → New → Data Layer Variable, and set the name to
vitals_popup_idorvitals_popup_type.
Verifying It Works
- Open your store in a browser
- Enable GTM Preview mode (click Preview in your GTM workspace)
- Trigger a popup on your store
- In the GTM debug panel, you should see the corresponding
vitals_popup_*events appear - Click on the event to verify that
vitals_popup_idandvitals_popup_typeare populated correctly