Monthly Archives: November 2012

Last updated by at .

PHP and Dates – Tearing My Hair Out

I had an interesting problem this morning with some dates in PHP. When I use dates in PHP I generally try to handle them as a unix timestamp using the local unix time of the server. I then modify this based on clients timezone to show them their local time. This has worked fine up until now.

November the 4th 2012 was the day that daylight savings rolled back in the USA and this caused a problem when reports for one of my products were run across this transition day. The trouble was when you got a local server time and converted it to a client time. For example using something like this:

$date=mktime(8,0,0,11,4,2012); //set to 8 AM on November 4
$date_time=new DateTime("now",new DateTimeZone('America/Los_Angeles'));
$date_time->setTimestamp($date);
echo "date_time:: ".$date_time->format("D j m y h:i:s");

Resulted in a different time to:

$date=mktime(8,0,0,11,5,2012); //set to 8 AM on November 5
$date_time=new DateTime("now",new DateTimeZone('America/Los_Angeles'));
$date_time->setTimestamp($date);
echo "date_time:: ".$date_time->format("D j m y h:i:s");

Which normally isn’t a problem except when you’re cycling through a date range one day at a time by adding (24*60*60) seconds to each day and expecting the client time to be indexed one day at a time too. But, it’s not, on one of the days there’s going to be an extra hour (or an hour) less. So, the solution (and it’s horrid) is to convert server to time to local client time and add a day to that, and then convert it back to server time. Yuck. But it works, and it works something like this:

	//
	//convert to local time
	//		
	$start_date=mktime(8,0,0,11,1,2012);
	$date_time=new DateTime_52("now",new DateTimeZone('America/Los_Angeles'));
	$date_time->setTimestamp($start_date);
			
	for ($i=0;$i<7;$i++)	
	{
		$date_time->setDate($date_time->format("Y"),$date_time->format("m"),$date_time->format("j")+$i);	
		echo "day ".$i." local time ".$date_time->format("D j m y H:i:s")."<br />";
		echo "day ".$i." server time ".date("D j m y h:i:s",$date_time->getTimestamp())."<br />";
	  $first_day_of_week1=get_first_day_of_week($date_time->getTimestamp(),new DateTimeZone('America/Los_Angeles'));
		echo "day ".$i." first_day_of_week:: ".date("D j m y h:i:s",$first_day_of_week1)."<br />";
		
	}

Google Experiments

Google Experiments

Google Experiments

I use Google Analytics to monitor the traffic on my websites. Have done since it was Urchin and Google bought them up. There’s a pretty neat feature in there called Google Experiments which allows you to perform AB tests on different web layouts pretty simply. Above you can see a test I’m running at the moment comparing two very different layouts of a page on my website. Setting up the experiment was very easy. Here’s the steps I followed:

  1. Designed the new layout and uploaded it and make sure it worked OK.
  2. Setup the new experiment in my Analytics account.
  3. Uploaded some tracking javascript into the header of the HTML file for the new layout and old layout.
  4. Decide how much traffic to divert to the experiment. In my case I chose 100% because I was confident the new layout would be at least as good as the old one. If you’re trying something radical I guess you’d direct less traffic to the experiment just in case something bad happens.
  5. Start the experiment and monitor your stats. Google decides when the experiment is over and assigns a winner or a loser or decides it cannot split the difference.

It helps if you’ve got some Goals setup for your Analytics account so you’ve got something to measure the experiment by. Don’t forget to look at other things though, such as the time visitors spend on your site and the bounce rate. Right now my new layout is outperforming the old layout by 13% and has outperformed it on 7 of 11 days the experiment has been running. 13% doesnt sound like much but it works out to about 700 extra conversions a year. Not too shabby.

If you want some more information I’d suggest taking a look at the Google Analytics Experiments help page.

Google Antics

Everyone knows about Google and nearly everyone uses it to do their searches. It’s become so dominant in the market that small online businesses (like mine) can be made or broken by where they appear in Google searches. Appear in the first 10 SERPs (Search Engine Ranking Positions) and you can make some money. Appear in the first 5 and you could make good money, appear as number 1 and you could potentially make LOTS of money. So getting high up in the Google rankings for your product search terms is important, and as with anything important that money can be made from there’s a whole industry formed around getting high Google rankings. It’s known as the SEO (Search Engine Optimisation) market. And it’s shocking.

People charge huge money to optimise a site and VERY VERY few have any concrete idea about what they are doing and the effects it might have on Google rankings in either the long or short term. The main reason for this is that Google hold their cards very close to their chest, and while they might give general indications of the things that affect search engine rankings they never, ever provide intimate details. The reason of course is that they do not want people gaming the rankings for financial gain. Not that this actually stops anyone, because hundreds of thousands of web-sites are spawned every year just to game the rankings and make their owners a few quick bucks.

Back in the day (more than 5 years ago) I used to read various SEO blogs and forums. But gradually I realised that no one person really knew what they were talking about and constant Google algorithm updates were constantly shifting the goal posts of the SEO game. That’s the key problem you see, Google changes their algorithm that ranks web-sites in searches ALL THE TIME. And whenever an update happened there’d be an up-roar about this site that gained rankings and that site that dropped and much wailing and wringing of hands by web-masters whose gaming of Google suddenly didn’t work any more. So I quit reading SEO blogs, I quit reading SEO forums, and I unsubscribed from all my SEO mailing lists. And I just concentrated on building better products and adding useful content to my web-sites.

The only slightly SEO based activity I’ve taken part in for years is making sure that I research the right keywords for my products, make sure those keywords are in page <h1> tags and that the keywords appear a few times in my text. That’s it. No link building, no auto content generation, no paying SEO consultants, no mini-sites, no nothing. And Google has (apparently) rolled out dozens of updates in that time and I couldn’t have cared less. Links to my web-sites have grown naturally, reviews of my products have popped up, and I’ve had mentions on social media sites, all without me getting involved. And my life has been better for it.

Until mid-October 2012 that is. That’s when I noticed that traffic to one of my major sites was down a bit, maybe 15%. Which is unusual because my web-traffic follows a pretty predictable pattern and has done for 5 years. Anyway it turned out that at the end of September Google announced they’d be rolling out an update that devalued exact match domains. Exact match domains use keywords in their domain names to try to get a bonus in their Google rankings. So, if I was selling blue foozles, I’d try to register an exact match domain like www.blue-foozles.com anticipating that Google would rank me higher because of it. All in all this isn’t a bad thing but of course if there’s money to be made the low-lifes crawl out of the gutter and hey-presto the internet became inundated with spammy exact match domain web-sites. So it turns out in late September 2012 Google said “no more” and appears to have removed the bonus that exact match domains (and apparently partial match domains) gained.

And that’s what zapped my traffic. Almost all my software product domains are partial match domains. That’s because I’m particularly unimaginative when it comes to naming my products. If it’s a timesheet program then I call it timesheet something-or-other. If it’s a time clock program then I’m going to call it time-clock-a-ma-jig. If it’s a coin collecting application then I’ll call it coin-collector-whatsit. Now I am not the first person to do this, there’s a little WORD processing program you may have heard about called Microsoft WORD, and a book-keeping program called QuickBOOKs, and a little known anti-virus program called Norton ANTI-VIRUS. So in these cases (and mine) the keyword is the BRAND. And sadly it appears that right now I might be getting walloped in the search engine rankings because of my brand.