Skip to content

Instantly share code, notes, and snippets.

@nicinabox
Last active December 19, 2015 00:28
Show Gist options
  • Save nicinabox/5868570 to your computer and use it in GitHub Desktop.
Save nicinabox/5868570 to your computer and use it in GitHub Desktop.
/*
* Modified from TJ VanToll's script
* http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/
*/
(function() {
var beforePrint = function() {
_gaq.push(['_trackEvent', 'Print', document.title, window.location.pathname]);
};
var afterPrint = function() {
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
if (mediaQueryList.addListener) {
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment