Gerbz Logo

Open For Business

Gerbz LLC is a transparent lifestyle business incubator. We're sharing what we learn as we validate our process for evaluating and transforming ideas into successful businesses.

Our Mission

Building An Opt In eBook Download Flow

I needed to create a flow for customers to trade me their email address in exchange for the 6PS eBook. A key requirement for me was that the process also added the customer to my Campaign Monitor email list which is also Opt In (meaning they need to click a link in an email before being added to the list). Once the customer clicks the opt in link, they’re automatically added to my email list and directed to download the free eBook. The closest plugin I could find was actually 2 plugins that work together. The first is Download Monitor which helps with uploading, managing and tracking downloads. And the second is an extension of Download Monitor called Email Before Download which allows you to request an email address first and integrates with the Contact Form 7 plugin. It didn’t have Campaign monitor integration and felt like I was trying to swat a fly with a sledge hammer. I also like to keep the plugins to a minimum when I can. I decided to build the flow myself. I went with Gravity Forms for my signup form because it allows me to automatically add customers to Campaign Monitor. Campaign Monitor allows me to customize the Opt In email and then redirect the Opt In link anywhere I want. So, now I just direct them to the download! Sounds easy. The problem is that when you direct someone to a PDF in the browser, the PDF displays in the browser. I’m not sure people know how to download the book when its being displayed in the browser, I want them to actually download a file. So I created a WordPress page instead that will download the file automatically when it loads. To do this, I added this function I found here to my wordpress theme:
add_action('template_redirect','auto_download_pdf');
function auto_download_pdf() {
  if ($_SERVER['REQUEST_URI']=='/downloadpage/download/') {
    header("Content-type: application/pdf",true,200);
    header("Content-Disposition: attachment; filename=6PS.pdf");
    header("Pragma: no-cache");
    header("Expires: 0");
    readfile("6PS.pdf");
    exit();
  }
}
This tells WordPress that any time someone visits /downloadpage/download/ to download a pdf file. The problem is, when the user is directed to this page from en email, the download begins on top of a blank page. To fix this, I direct them from the email to /downloadpage/ and use javascript to redirect them to /downloadpage/download/. This leaves them on /downloadpage/ and begins the file download instantly. I also pass a special token from the email so that the download only happens if they are coming from my email. That way, people can’t just stumble on the page and download the book without going through the entire flow. The end result is the exact flow I was going for:
  1. The customer enters their name and email address on my landing page
  2. The customer is notified that an email containing a link to download the book has been sent to them
  3. The customer clicks the link in their email which automatically adds them to my email list
  4. The customer is directed to my download page where the eBook download begins automatically