Don't have one? Create one ↗
← All courses

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

  1. 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.

    1. Go to Tags → New and choose Custom HTML.
    2. Paste a script that binds beforeprint (with a window.matchMedia('print') fallback) and pushes { event: 'print' }.
    3. Set its firing trigger to All Pages, name it Listener - Print, and Save.
  2. Create the Custom Event trigger

    1. Go to Triggers → New and choose Custom Event.
    2. Set Event name to print (it must match the event you pushed).
    3. Name it Event - print and Save.
  3. Tag: Custom HTML - Test

    1. Go to Tags → New and choose Custom HTML with <script></script> (fires but does nothing). Name it Custom HTML - Test, this is separate from the listener tag.
    2. Under Triggering, add Event - print, then Save.

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.

  1. In your GTM, click Preview.
  2. Paste the live URL above and click Connect.
  3. Interact with the live page and watch your tag fire in Tag Assistant.

What you should expect to see

Opening the print dialog adds a 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

0 of 15 lessons complete