This Google Tag Manager Recipe was originally posted by Lunametrics.
It adds engagement time tracking to every page on your site and sends events to Google Analytics. By default, this tracks events every 15 seconds up to a maximum of 30 minutes and pauses when the page is not the active tab in the browser or when the user hasn’t moved the mouse or pressed a key in the page in the last 65 seconds.
You can customize how often events fire by editing the included variables: Engagement Timer Interval Milliseconds, Engagement Timer Idle Milliseconds, Engagement Timer Limit Seconds.
INSTRUCTIONS
- Download Container File
Download the container JSON file (right-click on the link and click “Save Link As” or “Save Target As” to save the JSON file to your computer). - Import JSON File into GTM
Log into your own Google Tag Manager container and head to the Admin section of the site. Under Container options, select Import Container. Read this blog post for more details about importing a container file. - Update With Your Own Tracking ID
Update or create a new Constant Variable named {{YOUR_GA_TRACKING_ID}} with your Google Analytics Tracking ID (a.k.a. UA Number). I’d recommend using Google Analytics Settings variable instead. Read this guide how to properly change Tracking ID in the imported container. - Preview & Publish
Use the Preview options to test this container on your own site. Try testing each of the events to make sure they’re working properly. If everything looks good, go ahead and publish! - Optional – Update Timer Interval and Limits
You can customize how often events fire by editing the variables:
Engagement Timer Interval Milliseconds
1. How often do we send events to Google?
2. (Default – 15000 milliseconds, or 15 seconds)
Engagement Timer Idle Milliseconds
1. How many seconds of inactivity until we pause?
2. (Default – 65000 milliseconds, or 65 seconds)
Engagement Timer Limit Seconds
1. What is the max amount of seconds we continue to send events?
2. (Default – 1800 seconds, or 30 minutes)
View all 40+ Google Tag Manager Recipes