My desktop software products run on Windows. I spend a significant amount each month on Google Adwords to drive traffic to my websites, which is problematic as Adwords does not allow you to filter traffic by operating system. It does allow you to reduce bids on Mobile traffic but it bundles Desktop/Full Sized Tablet with Browser traffic into one segment. In the last few years the amount of non Windows OS traffic I receive via Adwords has grown steadily and now makes up slightly more than 50%. I’ve been struggling for a while to work out what to do with this traffic as clearly users from non Windows devices cannot use my software. Yesterday at 4AM I hit on a possible solution and spent the day implementing it. Basically I’m now intercepting the clicks on my “Download Now” buttons/links, checking the client operating system, and if it’s not a version of MS Windows then redirecting them to a page targeted at my online SAAS products. Those products WILL work on their non Windows devices. Sure, it’s an obvious thing to do but I work in isolation and sometimes it takes me a while (years) to reach the “obvious” solution to a problem.
Here’s how I did it:
1) Installed the PGWBrowser plugin for jQuery. This plugin allows you to detect the OS, browser and viewport of web clients.
2) Enabled the plugin in WordPress by enqueuing the JS file:
wp_enqueue_script('pgwbrowser',get_stylesheet_directory_uri().'/js/pgwbrowser.min.js',array(),false,true);
For non WordPress pages (my Adwords landing pages) I used the following (making sure it came after loading jQuery):
<script type="text/javascript" src="/wp-content/themes/Divi-child/js/pgwbrowser.min.js"></script>
3) Now I adjusted the onclick call on my download buttons. I know that using the onclick event like this is archaic but I’ve been doing it this way since 2004 and it works nicely so I’m not changing it! I use this event to redirect users who download the software to a “Download Complete” page that allows me to count downloads. Here’s what the HTML/JS looks like now:
<a class="button_class button_icon_download" href="/downloads/some_file_name.exe" onclick="SetUpRedirect('some_file_name.exe',event)">
You can see I’ve passed the file name to be downloaded to the JavaScript function as well as the event (click) object.
4) The final step was to adjust the SetUpRedirect JS function to accomplish my goals. Here’s what that looks like now:
function SetUpRedirect(destination,event_object) { var pgwBrowser = jQuery.pgwBrowser(); var os=pgwBrowser["os"]; var os_name=os["name"]; os_name=os_name.toLowerCase(); if (os_name.indexOf("windows")>-1) { setTimeout(function(){window.location='http://'+location.hostname+'/download-file/?file='+destination;},3000); return true; } else { event_object.preventDefault(); location.href="http://"+location.hostname+"/some-landing-page/?file="+destination+""; } }
That’s all pretty self explanatory. We’re making use of the PGWBrowser plugin to get the Operating System of clients and checking if it contains “Windows”. If it does those users get redirected to the download success page as usual. However, if they are not Windows users we use the jQuery preventDefault method on the event object to stop those users downloading the trial version of my software. They are then redirected to another landing page that says something like “hey we noticed you’re using a non Windows device, why not try out our spiffy web-based product instead?” Neat.