Before I tell you this, I’m not saying this is the best way to do this, nor the only way. I’m not even telling you to do this.
The idea behind this post came from a question that appeared in Episode 6 of ShopTalk. Forgive me if I get this wrong, but the question went a little like so:
Is there anyway to track the usage of your print stylesheets?
Proposed Solution
In the podcast, the suggested using some kind of JS script to capture keyboard shortcuts such as CTRL+P or ⌘+P which immediately sparked up three issues in my mind.
Issues
- What if javascript is disabled?
- What if the user uses a menu item?
- What if ther browser uses different key maps?
The first issue, “What if javascript is disabled?”, might not be that big of an issue, as typically analytics don’t track any user that doesn’t have javascript turned on. And lets face it, how many people don’t have javascript enabled these days?
The second issue, “What if the user uses a menu item?”, has no javascript solution (as far as I know, don’t quote me). Therefore, it’s a huge issue, and possibly the biggest issue out of the 3.
And the last issue, “What if the browser uses different key maps?”, is another large issue, not unsolvable, but enough to make you want a different solution.
Update #1: My initial two ideas have been deleted as they do not work.
My Solution
The idea for this solution is to set the background image of the body to a PHP script when in a print stylesheet or media query. The PHP script will then track the amount of requests it gets, therefore, tracking the amount of times your site is printed. When the browser gets back invalid image data from the script, it should fallback to the original background. I’m not going to show you what to do in the PHP script as not every implementation will work in all situations.
/* File Name: print.css */
body {
background: url(print.php);
}
Then you link to it like any other print stylesheet.
<link rel="stylesheet" href="print.css" media="print">
Footnote
Once again, I’m not saying you should use this idea, as it may be filled with flaws I haven’t noticed. If you see any, please let me know in the comments.