You shouldn't just "upgrade your scripts". This is a good way to learn some good practices when writing software that depends of other resources, specially when they aren't covered by a specification or API.
Since you need to refactor your scripts, consider creating at least a method that verifies if the url is in some of both structures presented here in your post. Doing this way, now and in the forseable future, at least your script is going to fail gracefully. "Ooops! Couldn't get google referer information" is better than an error trace.
When I download some plugins to Wordpress (like Flickr integration), I always do a quick read on the source code. I've found some that looked really great on the front-end, but when I watched closely it used a regular expression to extract the images from divs in a user profile in Flickr.
So, the other advice is to do some source code checkin in all extensions you usually download from other people to see if they have this kind of concern about external resources.