Support forums : Branches

mobile detection and hit logging

Discussion about existing branches and the directions they need to go in, or, for branches that are going to happen. "Quickies" is wide open. "Branches" is more focused.

Moderator: Dracones

Re: mobile detection and hit logging

Postby leeturner » Fri Aug 10, 2012 1:44 pm

EdB wrote:I'll make a branch for it which will be really hard to test because it'll have to be installed for real so it can be accessed via a mobile device.

I wish I had a better handle on the whole $Timer thing because I really would like to know how much more time it will take to run that class/checks immediately instead of at the end :(


I assume that it uses the user agent string to determine the client ? If so then it can be tested via firefox with the User Agent switcher plugin - https://addons.mozilla.org/en-US/firefo ... -switcher/

When you enable debug output it does display time information for certain things:

Screen Shot 2012-08-10 at 13.42.13.png
Screen Shot 2012-08-10 at 13.42.13.png (21.27 KiB) Viewed 5858 times


Maybe a crude way of doing it would be to load the page without the change running and log the time and then load page with the change enabled and see if the total time increases by much.

Very crude !!!

It is a shame we don't have unit tests as this type of thing would have been perfect for that :D
leeturner
Dracone
User avatar
 
Posts: 730
Joined: Fri Dec 11, 2009 11:55 am
Location: Brighton, UK

Re: mobile detection and hit logging

Postby EdB » Fri Aug 10, 2012 5:32 pm

I'll check out the user agent switcher :)

Right now I have (not pushed) a Global setting radio button for "detect mobile" with Off, Simple, and Complete. The idea was off is off, simple is only desktop/mobile/tablet, and complete is get all the info you can from this class.

The problem I just bumped into is that the class doesn't lend itself to returning the actual device info. Device, OS, & User Agent being the next level of granularity possible. In the demo file it checks through all and gives a true/false response - not the actual device. I am adding some methods to the class so if we want "complete" we can run through looking for a string return. The problem with that approach is upgrading the class later on down the line :(
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: mobile detection and hit logging

Postby EdB » Fri Aug 10, 2012 9:52 pm

Changed my mind already.

Assuming I call the class as an extra thing from /_ext/ (currently what I'm doing) then I will leave the class alone and loop through all the "is{something}" checks, creating an array of any true values. The array would have device name first, operating system second, and user agent third.

The alternative I keep toying with in my head is to chuck the current hit class in favor of grabbing this thing in it's place. IF that is a better way to go then I'd be okay with tweaking it as need be for our purposes.

Anyway right now I'm going with the first - leaving this mobile_detect class as-is and making our code jump through a complicated hoop to get more complex info.
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: mobile detection and hit logging

Postby leeturner » Fri Aug 10, 2012 10:04 pm

Its that tough trade off of upgrading the class later on and just working it into our codebase. I think I would have gone the same way as you.
leeturner
Dracone
User avatar
 
Posts: 730
Joined: Fri Dec 11, 2009 11:55 am
Location: Brighton, UK

Re: mobile detection and hit logging

Postby EdB » Sat Aug 11, 2012 3:42 am

https://code.launchpad.net/~edb/quam-pl ... for_mobile

The branch works, but I did end up changing the new class after all. Basically to get valuable info about the device I wanted to create an array of info bits. phoneName or tabletName, operatingSystem, userAgent. Since each of those is an array of "name => regex" I added the first as "name =>'' ", then told our code "if regex is '' then this must be the type of thing we might match on."

Anyway it works if anyone wants to take a peek at it. In _blog_main.inc.php search for "die()" and you will find 2 lines commented out ... if you want to see what it does so far. Oh you would have to change a Global setting then access it from a mobile device (or change user agent).

Next step isn't gonna be as easy as I had initially thought. Sure we could just change $disp and add a "mobile.main.php" file, but what do you do for permalinks or page-types? Plus we spend a lot of time working on the value of $disp, so to just change it seems like a bad idea. Anyway I have some thoughts and would like opinions on 'em.

1) Just change disp so we can have mobile.main and tablet.main knowing they'll default to index.main if they don't exist. Biggest drawback is the unforeseen stupids when the actual value of disp keeps reverting back to mobile or tablet.

2) If we are mobile or tablet then append the file name we're gonna look for. This will make for some convoluted code inside _blog_main.inc.php, but would allow for some awesome depth in what a template does when hit with a mobile device. $disp never changes, but we have (lets say) index.mobile.main.php and so forth. Drawback is a shedload of possibilities for template authors to work through.

3) I just now thought of this one. BEFORE we do the normal thing with $disp to pick a file, (assuming we're either mobile or tablet) we look to see if we have a mobile.main / tablet.main, and if so we serve that up. Always, knowing that (a) a template can easily exist without anything other than index.main and (b) a mobile version is generally assumed to be less complex than the desktop version.

I kinda like 3 but really wanna hear from others before proceeding.

Off topic I'll be doing this to QP5 very soon only going a step or ten further. Like, completely replacing my Hit class with this one and kinda seeing where it can go ... and where users might actually need it to go.
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: mobile detection and hit logging

Postby EdB » Fri Aug 17, 2012 12:00 am

Just had a bit of a thought... In our Hit class we say that $agent_type is 'rss' or 'robot' or 'browser' or 'unknown'. Correct me if I'm wrong, but wouldn't "browser" actually mean "desktop but maybe mobile device or maybe one of them fancy new fangled tablet thingies"?

In other words, perhaps this mobile detection should happen when a hit first happens (which is when we set the agent_type variable) so that we could call it what it is immediately? Then when we log the actual hit we could store the detailed info about the device if it happens to be mobile.

Functionally, the difference would be that we check for mobile/tablet in _main.inc.php when we first create the Hit object instead of between deciding what they're actually looking for but before we serve them a page (in _blog_main.inc.php) IF someone has opted to engage that feature.
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: mobile detection and hit logging

Postby EdB » Fri Aug 17, 2012 2:38 pm

oops - never mind. The assumption now is that everything is a desktop, and there is no reason why a phone or tablet can't be doing searches. So 'agent_type' should stay as-is with new bits for device and device_info if it's a mobile device.
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Previous

Return to Branches

Who is online

Users browsing this forum: No registered users and 1 guest

cron