{"id":2549,"date":"2016-02-03T21:04:27","date_gmt":"2016-02-03T21:04:27","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=2549"},"modified":"2016-03-15T09:12:10","modified_gmt":"2016-03-15T09:12:10","slug":"tracking-actions-in-interactive-email","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/tracking-actions-in-interactive-email\/","title":{"rendered":"Tracking Actions in Interactive Email"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2013\/12\/shoe-hover-anim.gif\" alt=\"shoe-hover-anim\" width=\"240\" height=\"170\" class=\"aligncenter size-full wp-image-33\" \/><\/p>\n<p>One of the questions I get a lot is, these interactive email techniques are great but how do I know if users are actually interacting with them? This article will cover some techniques on how you can track user interaction within an email with the selective loading of background images.<BR><BR> <\/p>\n<h4>Setting up the pixel<\/h4>\n<p>Tracking user interactions is actually pretty straightforward if you&#8217;ve already gotten the hang of <a href=\"https:\/\/freshinbox.com\/resources\/\">implementing interactive elements in email<\/a>. Like open trackers embedded by Email Service Providers (ESP) such as Mailchimp, all you need is to load a remote pixel when the user triggers an action, be it triggering a hidden radio button or hovering the cursor over an element. <\/p>\n<p>Naturally you&#8217;d need a service that generates and tracks the pixel once its fired. Here you have several options &#8211;  your ESP or Analytics provider might have an API that you could leverage or you could build one on your own. If neither option is available my follow up article will show you how to use Google Analytics for this purpose.<\/p>\n<p>Generally your pixel is going to look something like this:<\/p>\n<pre class=\"lang:default decode:true \" >http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=ZZ\r\n<\/pre>\n<p>The variables you&#8217;d normally track include the campaign, the unique user identifier and the event being tracked.<BR><BR><\/p>\n<h4>Background Image<\/h4>\n<p>The key to implementing a pixel to track user interactions in email is to load a background image when a hover or checked selector is active. There are multiple ways you can implement the pixel but the simplest method is to place an empty div inside the element and load a background image within it when activated by the :hover and :checked selector.<\/p>\n<p><B>Limitation<\/B><\/p>\n<p>A key limitation of background images is that the image will only be loaded once each time an email is opened regardless of the number of times the interaction happens. So even though the user may interact multiple times with a single element, it will only show up as a single interaction each time the email is opened. If a user opens the email twice and interacts twice, then two interactions will be recorded.<\/p>\n<p>Also, because Outlook.com <a href=\"https:\/\/freshinbox.com\/resources\/css.php\"> does not support CSS background images<\/a>, this method would not be able to track interactions in that client.<BR><BR><\/p>\n<p><H4>Tracking Hover Actions<\/h4>\n<p>Lets say you have a rollover image similar to one generated using <a href=\"https:\/\/freshinbox.com\/tools\/rollover\/\">this tool<\/a>.<\/p>\n<style>\n  .img-swap:hover img{\n    max-height: 0px;\n    height:0px;\n  } \n<\/style>\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:240px;\">\n<tr>\n<td width=\"240\" background=\"https:\/\/freshinbox.com\/tools\/rollover\/images\/2b.jpg\" style=\"border:2px solid #888888;padding:0px\"><a class=\"img-swap\" style=\"display:block;width:240px;height:170px;\" href=\"http:\/\/server.com\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/freshinbox.com\/tools\/rollover\/images\/2.jpg\" width=\"240\" height=\"170\" border=\"0\" style=\"display:block;\"><\/a><\/td>\n<\/tr>\n<\/table>\n<p>The code would look roughly like the one below:<br \/>\n(For brevity, the code examples omit the hacks required for <a href=\"https:\/\/freshinbox.com\/blog\/interactive-emails-in-gmail-using-css-attribute-selectors\/\">interactivity in Gmail<\/a>).<\/p>\n<pre class=\"wrap:true lang:default decode:true \" >&lt;style&gt;\r\n  .img-swap:hover img{\r\n    max-height: 0px;\r\n    height:0px;\r\n  } \r\n&lt;\/style&gt;\r\n&lt;table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"&gt;&lt;tr&gt;\r\n&lt;td width=\"240\" background=\"https:\/\/freshinbox.com\/tools\/rollover\/images\/2b.jpg\"&gt;\r\n&lt;a class=\"img-swap\" style=\"display:block;width:240px;height:170px;\" href=\"http:\/\/server.com\"&gt;\r\n&lt;img src=\"https:\/\/freshinbox.com\/tools\/rollover\/images\/2.jpg\" width=\"240\"  height=\"170\" border=\"0\" style=\"display:block;\"&gt;&lt;\/a&gt;\r\n&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;<\/pre>\n<p>To implement the pixel you merely insert an empty div within the &#8220;img-swap&#8221; anchor tag with a tracking class (ie. tpixel).<\/p>\n<pre class=\"wrap:true lang:default mark:3 decode:true \" >&lt;a class=\"img-swap\" style=\"display:block;width:240px;height:170px;\" href=\"http:\/\/server.com\"&gt;\r\n&lt;img src=\"https:\/\/freshinbox.com\/tools\/rollover\/images\/2.jpg\" width=\"240\"  height=\"170\" border=\"0\" style=\"display:block;\"&gt;\r\n&lt;div class=\"tpixel\"&gt;&lt;\/div&gt;\r\n&lt;\/a&gt;<\/pre>\n<p>And then load the pixel as the background image when the user hovers over the img-swap link:<\/p>\n<pre class=\"lang:default decode:true \" >.img-swap:hover .tpixel{\r\n  background-image:url(http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=rollover);\r\n} <\/pre>\n<p>This setup will fire the pixel once regardless of the number of rollover images present in your email. If you want more fine grained tracking, you can create a separate class and event identifier for each of the rollover images in your email.<BR><BR><\/p>\n<h4>Tracking Checkbox or Radio Interactions<\/h4>\n<p>Tracking checkbox or radio based interactions are also fairly straightforward. For an example of what you can do with radio elements check out the <a href=\"https:\/\/freshinbox.com\/blog\/image-carousel-for-email-tool\/\">Image Carousel for Email Tool<\/a>.<\/p>\n<style>\n.radio1:checked ~ .carousel{\n  background-image:url(https:\/\/freshinbox.com\/tools\/rollover\/images\/1.jpg);\n}\n.radio2:checked ~ .carousel{\n  background-image:url(https:\/\/freshinbox.com\/tools\/rollover\/images\/2.jpg);\n}\n.radio3:checked ~ .carousel{\n  background-image:url(https:\/\/freshinbox.com\/tools\/rollover\/images\/3.jpg);\n}\n[name=myradio]{\n  display:inline-block;\n  margin:5px;\n}\n<\/style>\n<form>\n<input class=\"radio1\" type=radio name=\"myradio\" checked><input class=\"radio2\" type=radio name=\"myradio\"><input class=\"radio3\" type=radio name=\"myradio\"><\/p>\n<div class=\"carousel\" style=\"width:240px;height:170px;\">\n<\/div>\n<\/form>\n<p>The rudimentary radio based carousel above can be created using the example code below (Note: using the (~) general sibling selector in iOS9 requires a <a href=\"https:\/\/freshinbox.com\/blog\/android-css-general-sibling-selector-bug\/\">special hack<\/a>)<\/p>\n<pre class=\"wrap:true lang:default decode:true \" >&lt;style&gt;\r\n.radio1:checked ~ .carousel{\r\n  background-image:url(https:\/\/freshinbox.com\/tools\/rollover\/images\/1.jpg);\r\n}\r\n.radio2:checked ~ .carousel{\r\n  background-image:url(https:\/\/freshinbox.com\/tools\/rollover\/images\/2.jpg);\r\n}\r\n.radio3:checked + .carousel{\r\n  background-image:url(https:\/\/freshinbox.com\/tools\/rollover\/images\/3.jpg);\r\n}\r\n&lt;\/style&gt;\r\n&lt;input class=\"radio1\" type=radio name=\"myradio\" checked&gt;\r\n&lt;input class=\"radio2\" type=radio name=\"myradio\"&gt;\r\n&lt;input class=\"radio3\" type=radio name=\"myradio\"&gt;\r\n&lt;div class=\"carousel\" style=\"width:240px;height:170px;\"&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>To add tracking, add an empty div in the carousel container.<\/p>\n<pre class=\"lang:default mark:2 decode:true \" >&lt;div class=\"carousel\" style=\"width:240px;height:170px;\"&gt;\r\n  &lt;div class=\"tpixel\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>And then trigger background image pixels when the second and third radio elements are selected. You don&#8217;t want to fire the pixel when for the first radio since the image is already visible by default.<\/p>\n<pre class=\"wrap:true lang:default decode:true \" >.radio2:checked ~ .carousel .tpixel{\r\n  background-image:url(http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=radio2_select);\r\n}\r\n.radio3:checked + .carousel .tpixel{\r\n  background-image:url(http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=radio3_select);\r\n}\r\n<\/pre>\n<p><BR><BR> <\/p>\n<h4>Detecting Client Type<\/h4>\n<p>Naturally you&#8217;d also want to know the percentage of opens on the different types of clients so you can get a sense on how many people who were able to interact with your creative actually interacted with them.<\/p>\n<p><B>Default Open Tracker<\/B><\/p>\n<p>This tracker will fire on all emails that are opened where images are displayed.<\/p>\n<pre class=\"wrap:true lang:default decode:true \" >&lt;img src=\"http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=open\" width=1 height=1&gt;<\/pre>\n<p><BR><BR> <\/p>\n<p><B>Tracking Open by Media Query Types<\/B><\/p>\n<p>Here&#8217;s how you can implement a webkit pixel.<\/p>\n<pre class=\"wrap:true lang:default decode:true \" >&lt;style&gt;\r\n@media screen and (-webkit-min-device-pixel-ratio:0) {\r\n  .webkit-pixel{\r\n    background-image: url(http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=webkit-open);\r\n  }\r\n}\r\n&lt;\/style&gt;\r\n&lt;div class=\"webkit-pixel\"&gt;&lt;\/div&gt;<\/pre>\n<p>Here&#8217;s how you can track mobile opens.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n&lt;style&gt;\r\n@media screen and (max-device-width: 600px) {\r\n  .mobile-pixel{\r\n    background-image: url(http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=mobile-open);\r\n  }\r\n}\r\n&lt;\/style&gt;\r\n&lt;div class=\"mobile-pixel\"&gt;&lt;\/div&gt;<\/pre>\n<p><BR><BR> <\/p>\n<p><B>Tracking Opens on Clients with Checkbox Support<\/B><\/p>\n<p>If you have interactive elements that <a href=\"https:\/\/freshinbox.com\/resources\/techniques.php\">leverage checkboxes and radio elements<\/a>, you can track the clients that are able to display these elements using the code below:<\/p>\n<pre class=\"wrap:true lang:default decode:true \" >&lt;style&gt;\r\n.pixel-cbox{\r\n  display:none;\r\n}\r\n.pixel-cbox:checked + .checked-pixel{\r\n    background-image: url(http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=cbox-support-open);\r\n}\r\n&lt;\/style&gt;\r\n&lt;input type=checkbox class=\"pixel-cbox\" style=\"display:none !important\" checked&gt;\r\n&lt;div class=\"checked-pixel\"&gt;&lt;\/div&gt;<\/pre>\n<p><BR><BR> <\/p>\n<p><B>Tracking Opens on Gmail Webmail<\/B><\/p>\n<p>Here&#8217;s an interesting trick. Because Gmail webmail <a href=\"https:\/\/freshinbox.com\/blog\/interactive-emails-in-gmail-using-css-attribute-selectors\">supports attribute selectors<\/a> but not classes, you can track the opens in Gmail webmail with this code. (Note the style block must be <a href=\"https:\/\/freshinbox.com\/resources\/css.php#gmail\">in the &lt;head&gt;<\/a>)<\/p>\n<pre class=\"wrap:true lang:default decode:true \" >\r\n&lt;style&gt;\r\n* [summary=pixel-gmail]:not(.pixel-gmail){\r\n  background-image: url(http:\/\/tracker.com\/track?campaign=XX&amp;user=YY&amp;event=gmail-webmail-open);\r\n}\r\n&lt;\/style&gt;\r\n&lt;div class=\"pixel-gmail\" summary=\"pixel-gmail\"&gt;&lt;\/div&gt;<\/pre>\n<p><BR><BR> <\/p>\n<h4>Next Step &#8211; Using Google Analytics.<\/h4>\n<p>What if you don&#8217;t have the resources to code your own pixel service? Not to worry, check out <a href=\"https:\/\/freshinbox.com\/blog\/tracking-interactions-in-email-with-google-analytics\/\">this follow up article<\/a> on how you can implement these techniques using the free Google Analytics!<BR><BR><\/p>\n<p>There you have it, the basics to tracking interactions in your email. To add support for tracking interactions within Gmail, you incorporate the attribute selectors <a href=\"https:\/\/freshinbox.com\/blog\/interactive-emails-in-gmail-using-css-attribute-selectors\/\">covered in this article<\/a>.<BR><BR> <\/p>\n<p><BR><BR><BR><br \/>\n<div style=\"padding:10px; border: 2px solid #99C731;background-color:#FFF8DC;border-radius:5px;\">\n<form action=\"https:\/\/freshinbox1.createsend.com\/t\/i\/s\/adrmi\/\" method=\"post\" id=\"subForm\">\n<span class=\"fisub_header\" style=\"font-weight:bold;\">Subscribe to the #EmailGeeks Newsletter<\/span>\n<p><input id=\"fieldEmail\" name=\"cm-adrmi-adrmi\" type=\"email\" style=\"width:90%\" required placeholder=\"Your Email Address\" \/><\/p>\n<p><button type=\"submit\">Subscribe<\/button><\/p>\n<\/form>\n<\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the questions I get a lot is, these interactive email techniques are great but how do I know if users are actually interacting with them? This article will cover some techniques on how you can track user interaction within an email with the selective loading of background images&#8230;.<\/p>\n","protected":false},"author":2,"featured_media":2597,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28,25,47],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2549"}],"collection":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/comments?post=2549"}],"version-history":[{"count":80,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2549\/revisions"}],"predecessor-version":[{"id":2814,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2549\/revisions\/2814"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/2597"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=2549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=2549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=2549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}