Lesson 12 of 15
Print Tracking
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
Printing is a strong intent signal on recipe, ticket and documentation pages, and like copy, GTM has no built-in trigger for it. You'll reuse the listener pattern: a Custom HTML tag binds the browser's beforeprint event and pushes a print event for a Custom Event trigger to catch.
You'll fire a tag when the print dialog opens, you can cancel it.
Goal
Fire a tag when someone prints the page, using a beforeprint listener and a Custom Event trigger.
Build it in GTM
Add the print listener
GTM has no built-in print trigger, so a small Custom HTML tag does the listening and pushes its own event.
- Go to Tags → New and choose Custom HTML.
- Paste a script that binds
beforeprint(with awindow.matchMedia('print')fallback) and pushes{ event: 'print' }. - Set its firing trigger to All Pages, name it
Listener - Print, and Save.
Create the Custom Event trigger
- Go to Triggers → New and choose Custom Event.
- Set Event name to
print(it must match theeventyou pushed). - Name it
Event - printand Save.
Tag: Custom HTML - Test
- Go to Tags → New and choose Custom HTML with
<script></script>(fires but does nothing). Name itCustom HTML - Test, this is separate from the listener tag. - Under Triggering, add
Event - print, then Save.
- Go to Tags → New and choose Custom HTML with
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
print event in the timeline and the dataLayer, and your tag fires. You can cancel the dialog.Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded