Blast Analytics and Marketing

Analytics Blog

Supporting Leaders to EVOLVE
Category: Digital Analytics

How to Fully Track the Print Page Action with Google Analytics

July 9, 2013

Have you ever wondered if people are printing pages from your website?

Wonder no more…here is a solution to track all the methods people use to print a page on your website. We will show you how to capture this data whether they;

  • click on your pretty print button,
  • right click and choose print from the right click menu,
  • use keyboard shortcuts ‘Ctrl+P’ (Windows) or ‘Cmd+P’ (Mac),
  • or use the ‘File > Print’ menu.

A common solution is to listen for clicks onto your website’s print button. This works well if everyone used that button. However, there are several other ways that users can print a page, as detailed above. The Google Analytics tracking solution we provide below, tracks all print methods as it hooks into the browser to listen to events just prior to the print dialog appearing.

How to Track the Print Button in Google Analytics

Before we begin, it is important to understand that if a user initiates the print dialog and then cancels, this code will still track it as a print. Thus, I label it in Google Analytics as more of an intent. The tracking code below can be implemented anywhere below your Google Analytics script. Depending on if you use Google’s Classic Analytics (ga.js/dc.js) or Universal Analytics (analytics.js), you’ll want to remove the line of code that doesn’t apply. I’ve included them both in the below code to illustrate the coding for each.

[sourcecode language="js"]<script type="text/javascript">
try{
(function() {
var afterPrint = function() {
_gaq.push(['_trackEvent', 'Print Intent', document.location.pathname]); //for classic GA
ga('send', 'event', 'Print Intent', document.location.pathname); //for Universal GA
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (!mql.matches)
afterPrint();
});
}
window.onafterprint = afterPrint;
}());
} catch(e) {}
</script>[/sourcecode]

Credit for the actual print detection logic goes to TJ VanToll. Be sure to check out his great front end development blog. The code listens for either the window.onafterprint (if the browser supports it) or listens for the mediaQuery to switch to print.

Embed Script via Google Tag Manager

If you are using Google Tag Manager, simply add this as a new tag to fire on all pages. I recommend loading it after the page has loaded (by adding a rule of ‘event’ equals ‘gtm.dom’). Below are the settings in Google Tag Manager (GTM):

ga-track-print-gtm-tag

The Result

Once you have this Google Analytics event tracking code in place, you should start to see the print activity data populate in the Event reports. Below is a sample output after you click into the ‘Print Intent’ event category. For example, you can see below that 1,964 people had the intent to print the about us page.Print Tracking in GA Report

Interested in how to track other outbound/external link activity? Check out this related post on how to track downloads and other outbound tracking in Google Analytics.

Joe Christopher
About the Author

As Vice President of Analytics at Blast Analytics, Joe leads a team of talented analytics consultants responsible for helping clients understand and take action on their vast amounts of data, to continuously improve and EVOLVE their organizations. With over 20 years of experience in analytics and digital marketing, Joe offers a high-level of knowledge and guidance to clients across all industries. He is an expert in all major analytics platforms including Google Analytics and Adobe Analytics, as well as various tag management systems such as Tealium and Adobe Launch. He also consults on data visualization, data governance, and data quality strategies. Having extensive expertise in many areas, has enabled Joe to become a well known thought leader and speak at industry events such as Tealium’s Digital Velocity series. Joe remains on the pulse of various information technology, programming languages, tools and services, keeping Blast and its clients on the leading edge.

Connect with Joe on LinkedIn. Joe Christopher has written on the Blast Digital Customer Experience and Analytics Blog.

Related Insights