Simple Mobile User Targeting With PHP

June 23, 2011 - by Greg · Filed Under Uncategorized Comments Off on Simple Mobile User Targeting With PHP 
Be Sociable, Share!

    This is a guest post by Greg Walker from

    Targeting Mobile Devices With PHP

    Do you get many mobile visitors to your website? Would you like to be able to identify these users and deliver content or ads specifically to them?

    Targeting visitors that are using a mobile device like an iPhone or Blackberry is surprisingly straightforward, I promise. Mobile-targeting is much easier than geo-targeting, so if you’ve ever done geo-targeting before using PHP then this will be a doddle.

    If you absolutely hate PHP, then you may as well stop reading now. However, if you know the very basics of PHP or are happy to spend 20 minutes with me figuring it out, fantastic. I’m going to try an make this introduction to targeting mobile users with PHP as comfortable for you as I can.

    Targeting all mobile users.

    [sourcecode language=’php’]

    You’re on a mobile!

    You’re not on a mobile =[


    Copy all this code, stick it in a file like mobile.php (call it whatever you want, just make sure it ends in .php), upload it anywhere on your site and check it out for yourself. Congratulations, you’ve just made your first page that targets mobile users.

    How it works.

    The first line is the important part. We all have what’s called a “user agent string” that a website server (and PHP) can read. This contains information about your OS and browser. You can see what your user agent looks like for yourself.

    What the first line does is check this string for any occurrence of the word “mobile”, which is what any mobile visitor will have in their user agent string. If the word “mobile” does appear in this string, the $mobile variable is set to true. If it’s not there, $mobile is set to false.

    Using this $mobile variable, we can do a basic if/else conditional statement to show specific content to mobile and non-mobile users. If $mobile is true, the first p tag is displayed. If it’s false, the first p tag is skipped and the second one is displayed instead. Easy game.

    For what it’s worth, I’ve set this code up using the alternative format for conditional statements. This basically means that you can shove any HTML you like in to where the current p tags are and it will all work fine. Have fun with it.

    Targeting specific mobile devices.

    That first line of code targets all kinds of mobile users, as it’s just looking for the word “mobile”. You can go a little further and target iPhones, Androids, Blackberrys… anything. You just need to change the information you’re looking for in that user agent string.

    Here are a few mobile-specific snippets:

    [sourcecode language=’php’]
    $iphone = stristr(($_SERVER[‘HTTP_USER_AGENT’]), ‘iphone’);
    $android = stristr(($_SERVER[‘HTTP_USER_AGENT’]), ‘android’);
    $blackberry = stristr(($_SERVER[‘HTTP_USER_AGENT’]), ‘blackberry’);
    $ipad = stristr(($_SERVER[‘HTTP_USER_AGENT’]), ‘ipad’);

    Each of those variables will return true if the visitor is using the specific device you are looking for. All I’ve done is change the second part of the stristr function (this bit searches for the occurrence of a string) to look for a different device.

    Note: I also changed the variable name, but that’s entirely optional. So if you’re just copying one of the snippets above, make sure that when you’re doing the conditional statement that you’re checking the right variable name. For example:

    [sourcecode language=’php’]

    You’re on an iPhone!

    If you haven’t got an iPhone, you haven’t got an iPhone.


    These are the more popular devices, but you could target others as well if you like. You just have to find out what’s in a device’s user agent string, then search for that.

    Which devices are the most popular?

    If you’re interested in targeting specific devices you might find these stats helpful. This is the break up of visitors using mobile devices over the last 3 months at my main poker website.

    Number of Mobile Users Table and Chart: Feb 23, 2011 - May 23, 2011

    I realise that this obviously doesn’t represent the entire gambling sector, but it’s a handy insight in to the popularity of different devices.

    Ideas for this sort of user targeting.

    Okay cool, we can find out if a visitor is on a mobile phone and deliver specific content to them. Now what?

    Well, here are a few quick ideas off the top of my head.

    1) Mobile specific ads.

    If someone is on their mobile, they’re not going to be able to download PokerStars through your affiliate link and sign up. So instead, consider displaying ads and links for stuff that can make you money.

    If you’re an affiliate for the app store, you could push poker apps like this equity calculator. Or, you could try promoting one of those real money poker rooms for mobile users.

    2) Redirect to a different page.

    Maybe you have an entire section of your site just for mobile users. You could redirect these visitors by sticking the following code right at the top of any page you want them to be redirected from:

    [sourcecode language=’php’]


    I don’t think forcing mobile users away from a page is great for usability, so it might be worth trying to come up with some better ideas for this.

    3) Usability considerations.

    There are some things that mobile browsers can’t do. On the iPhone for example, two big things are Flash and the ability to “hover” over elements. So you could change a few things on your site to make it more mobile-friendly.

    For example, in my recent guest post about increasing newsletter subscribers at Kevin’s blog, I mentioned a problem I had with a rollover/hover effect not being able to work properly on mobile devices. So to fix this, I displayed a static image instead of a sprite to mobile browsers to help prevent any confusion.

    Being considerate isn’t directly going to make you any money. However, there’s the off chance that a visitor browsing your site from their mobile will notice the helpful tweaks you’ve made, and this may help to make your site that little bit more memorable.

    4) Advanced tracking.

    If you’ve played about with Google Analytics much, you may have set up event tracking for a few things. This could be for tracking file downloads, video plays, newsletter submissions, or other fun stuff like that.

    A guide to event tracking is outside the scope of this article (it’s long enough already), so check out the google guide if you’re interested. However, if you’re tracking events already, you could incorporate some extra information about mobile users in to your tracking.

    For example, I wanted to track how many of my newsletter subscribers were coming from mobile visitors. So using similar code to the bits I’ve already outlined in this article, this little snippet adds the text “(Mobile)” to all my event tracking for newsletter submits.

    [sourcecode language=’text’]
    onClick=”javascript: pageTracker._trackEvent(‘Newsletter’, ‘Submit’, ‘‘);”

    You just add this inside the button on your form. This little snippet also tracks the page the user submits from, but I’m not going to go through that right now. If you know a bit about PHP you will be able to figure it out anyway.

    Is it worth targeting mobile users on my gambling website?

    Not really no.

    I know that kinda sh1ts all over the guide I’ve just written, but in all honesty I don’t think it’s worthwhile for most affiliates. Why? Two reasons:

    1. When it comes to affiliating for services/products, there’s not a lot of profit to be made from mobile users in my opinion.
    2. As helpful and innovative this might be in terms of usability and features, this stuff doesn’t directly put more money in your pocket.

    Sure, targeting mobile visitors is cool and all, but it’s not money-making cool. Unless you’ve got a good plan, I just don’t think the juice is worth the squeeze.

    Geo-targeting on the other hand is a much better tactic. You’d make more money sending UK visitors to your pound currency poker sites, than you would sending a iPhone visitor to the app store.

    Right now, I think the absolute best thing you could do for mobile-targeting is to get those users to sign up to your email list. If they do that, you can get in touch with them when they’re on their real computers and ready to sign up for stuff and spend money. When they’re on their phones there’s not a lot you can squeeze out of them.

    Nonetheless, hopefully something lucrative will turn up at some point in the near future, and we can all come back to this quick guide and start profiting from those fancy mobile users.

    Are but made exceptions. Since is even inside this one. Hope enough lot electro a to a with big impatient water gray.

    Follow Me on Twitter @AffiliateFYI for Even More Affiliate, Business and SEO Updates!

    Be Sociable, Share!

      Comments are closed.