Google Hacking, Programming, SEO

Using the Google Analytics API with Ruby, Open-Uri & Hpricot

You may or may not have heard that Google has finally opened up their Analytics API to the public. You can read Googles official statement here.

I thought I’d show you all a quick crash introduction on how you can access the API using Ruby.

The following code uses Open-Uri to access the API and Hpricot to parse the response. In this example, we’re going to authenticate with the API, and then we’re going to use it to extract all the keywords (organic and paid) which have brought visitors to our site within the past year (limited to 100 keywords max)

NB: sorry for the shitty formatting. I tried like hell to get this code to display well, but I gave up. Just copy and paste..you’ll be able to sort it out.

require ‘rubygems’
require ‘open-uri’
require ‘hpricot’

USER_EMAIL=”XXXXXX” #Insert your Google Account email address here
USER_PASS=”XXXXXX” #Insert your password here
PROFILE_ID=”XXXXXX” #Insert your profile ID here (Find this in your analytics profile under profile settings)
results = {}
keywords = []
auth_url = “https://www.google.com/accounts/ClientLogin?Email=#{USER_EMAIL}&Passwd=#{USER_PASS}&accountType=GOOGLE&source=open-uri-limbo-v01&service=analytics”

auth_key = (open(auth_url).read).split(”\n”).last

#now query for keywords, you can change the date values as you see fit, as well as the max-results value
response = Hpricot.XML(open(”https://www.google.com/analytics/feeds/data?start-date=2008-10-01&end-date=2009-04-21&dimensions=ga:keyword&max-results=100&ids=ga:#{PROFILE_ID}&prettyprint=true”,
“Authorization” => “GoogleLogin #{auth_key}”).read)
## storing some of the extra information in a “results” hash in case we need it later
results[:total_results] = (response/’openSearch:totalResults’).inner_text
results[:start_index] = (response/’openSearch:startIndex’).inner_text
results[:items_per_page] = (response/’openSearch:itemsPerPage’).inner_text
results[:start_date] = (response/’dxp:startDate’).inner_text
results[:end_date] = (response/’dxp:endDate’).inner_text
results[:aggregates] = (response/’dxp:aggregates’).inner_text
results[:data_source] = (response/’dxp:dataSource’)
results[:entries] = (response/’entry’)
## the entries contain each individual keyword

## for my purposes, I’m not interested in visitors coming from search operators like “site:”
## so we’re scrubbing those out.
for entry in results[:entries]
keyword = (entry/’dxp:dimension’).first[:value]
keywords << keyword unless keyword.include? “site:” or keyword.match(/\(.*\)/)
end

## Now print out our keywords
keywords.each {|kw|
puts kw
}

UPDATE just seconds ago, a new gem was released called Gattica which you can use to access the Google Analytics API. How’s that for up to the minute blogging? Thanks Twitter!

Announcements & News, Programming, Random!, SEO

So, you want to build a Web App…

Are you unemployed? Were you fired from your job as an accountant at a Fortune 500 company? Looking for a good way to make money, but don’t want to get back in the rat race? If you answered yes to any of those questions, you should consider building a WEB APP!

Web Applications are EASY to build! Anyone can do it!

First, you need an idea. This can be the hardest part. Basically, you just want to think about something people do every day that you can do better.
Here are some ideas to get you started:

  • web-based makeup mirror (requires a webcam)
  • sea-monkeys…give them facebook pages, make them twitter…put them up for adoption.
  • a calculator, with lots and lots of ajax….and really big buttons.

These are just a few ideas, but you get the picture. Take some time coming up with your idea, and be patient! You have to refine the idea before you waste time building something no one will ever use. Take at least 30 minutes to decide.

Once you’ve decided on what your highly profitable Web App is going to do, you have to build it! This is the easiest part. You don’t even have to know how to write code. Really! There are new programming languages that don’t even require complicated things like squiggly brakets {} or dollar signs $.  Thanks to the magic of Ruby on Rails, if you can write a grocery list, you can write a Web App. Seriously!

Do you know how to view the source code for an HTML page? Great! That means you know how to design a website! Now, I know, designing things is complicated, but don’t worry about it! NO ONE DESIGNS THEIR OWN WEBSITES ANYMORE! Seriously! All you need is a Template. There are even WEB APPS to build Templates for WEB APPS! Totally meta! Gnarly!

So, you’ve got your ruby, you’ve got your template….you’re almost done! Now, you need a LOGO! Most people say you should hire a designer to get a Logo done professionally, but you don’t want to spend any money out of pocket, do you? I mean, what are you, Mother Teresa?!? Hell no! I recommend you just rip one off for now, and once you make some revenue, you can buy some cheap stock Logo from istockphoto.com.

Remember, in order to maximize Web App profits, you need to always be vigilant so that no corners escape uncut. When building your Web App, you should be sure to try and burden yourself with as many of the details as possible. You need to be prepared to be the programmer, the tester, the designer, the marketer and the support staff, ALL IN ONE! But don’t get stressed out about handling a big workload, because it’s not like you have to do ANY of those things at 100% efficiency, as long as you’re the only one doing them. The people who will use your Web App are just nameless, faceless drones anyways; it’s not like you owe them timely responses to their emails. Always remember that your users are eternally indentured to you in exchange for access to your Web App.

OK, so you’ve got your Template, you’ve got your Logo……..it’s time to do some programming! First, you want to download as many plugins and gems as possible. The more the better, because the more gems you have, the less code you have to write. Remember when your teacher crushed your dreams and told you that there are no unique ideas left, that everything has already been done? Well, when it comes to Gems, its true! There is a Gem or Plugin for every possible thing you could ever conceive of wanting to do – now, or in the future. So basically, just get as many Gems and Plugins as possible, and just start plugging them in wherever you need content.

Look at you! You go-getter! You’ve just programmed your first Web App! It’s going to be the BEST CALCULATOR EVER! Don’t worry about scaling it up. If your users ever start calculating pi, you can just use the Cloud, man! The Cloud is where it’s at! In case you haven’t heard of the Cloud yet, I’ll tell you a bit about it. The Cloud is this place in the Amazon Basin, a humid, godless, no-mans-land inhabited by under paid savages (Amazonians). Anyways, the Cloud is like this giant parking garage, but instead of cars, they’ve parked hundreds and hundreds of servers which they’ve woven together with millions of long, tangled fibreoptic wires (hence the name ‘the Cloud’). Anyways, you just email your program to the Amazonians, and they’ll put your program on a piece of the cloud, giving you the ability to add as many mongrel instances to your server cluster as your heart desires. Scaling?!?! What Scaling?!?!

Now that you’ve got your Template, and your Logo and your Program on the Cloud, you’re ready to start marketing!!! This part is really really easy. You just need to stir the pot a little bit, & kick up a little media interest. For example, let’s say one of your Virtual Sea-Monkeys ends up having to see a Substance Abuse Counselor…..that’s marketing gold! Big-mouthed bloggers love stories like that! The more sensational the better, especially because people will put your media story on sites like Digg, or StumbleUpon. These sites will send you visitors who will really take the time to read your story, visit your site, interact with your product, and develop long-lasting, meaningful connections with your brand. You just have to keep your eyes open for marketing opportunities!

By now, thanks to your Web App, you’re probably well on your way to dealing with your delinquent mortgage payments and are no longer dodging your relatives. Congratulations! Feel free to send your former boss a cruel and insensitive e-card from someecards.com, because You’ve Arrived!!! You’re a big web success story! Expect to hear from Inc. Magazine within minutes.

But! But! But! Don’t stop there! This is just the beginning! Now that you’ve seen how easy it is to create one Web App, create more! Don’t worry about the Web Apps that you’re already managing, it’s OK to let them slide. If you want, you can start an affiliate program and get affiliates to keep marketing your old, stale Web Apps while you’re busy building new ones! You’ll want to get an Email Autoresonder so that you’re not burdened by time consuming support requests to have subscriptions canceled, you’ve got better things to do! You’re an entrepreneur!

Random!

The Genius, The Moron, And Your Lot In This Terrible, Magnificent Life

Show me one man
who has gotten
power, fame
and money through
incredible talent
effortless genius
carefully cultivated network
and I’ll show you
ten fools who
got the same
in spite of
themselves

Show me one business
that has achieved
dominance in its
industry through
good decisions
careful planning
unrelenting diligence
and I’ll show you
one hundred
who have thrived through
directionless and
unplanned ways

Show me one writer
who has attained greatness
through higher education
cultural savvy
bald nepotism
and I’ll show you
one thousand
uneducated hacks
who whisper
into eternity
with effortless grace

The facts are clear

The Genius regularly fails

The Moron regularly wins

And the bookshelves
of the world
bend low
ready to teach
us why
and how
this is so

It seems the only
thing left to do
is to do the thing
as best you can
and leave the rest
in your overstuffed
suitcase
on your rented porch
as you walk out to
do it again
tomorrow

And the day
after

And the day
after
that

Until
your lot in this life
and
your concern for it
are no
more
forever
(via http://www.knifegunpen.com/genius-book/)

———————–

I havent written a post here in far too long. I apologize for that, sincerely. It’s not my intention to let this blog fade away. I have simply been busy working on some very exciting new projects, as well as growing my business. Between my business obligations and my social obligations, I’ve been left with very little time to nourish this blog. That’s not to say I don’t have anything to talk about (ask anyone who follows me on twitter), it’s just that I rarely take the time to sit down and put my thoughts into a format you all would enjoy reading.

That said, I was galvinzed into writing a post by the above poem. Now, I’m not much for poetry…most of the poems I know have to do with places like Nantuckett, and bodily sounds, but this poem resonated with me.

As an entrepeneur, I’ve witnessed the truth in those verses, first hand. The best man rarely wins, but all you can do is keep your mometnum, day after day after day, of doing the best you can.

Programming, SEO, Theory

Will Google stop SERP scrapers by going Ajax?

Some of you might have noticed the buzz going around the net today about Google’s SERPs going ajax. There is a great post about it here:

Google Web Search Ajax

I’ve heard more than a few people asking if this will stop automation software from crawling Googles SERPs to retrieve rankings or Adwords data. In short, the answer is no.

I doubt this development would be solely intended to stop people from using automated rank checkers or content scrapers, but Google has to know that whatever they change, people will simply adapt and evolve their software to keep pace. My personal opinion is that a move to ajax SERPs would provide google with a tighter control of how they serve data, as well as providing them with a whole slew of new metrics they could leverage. On the flip-side, this move could hamper the accessibility of Googles service from outdated/underpowered computers and browsers.

Regardless, the possibility of Google going ajax does indeed raise some questions in so far as how people should proceed with developing automation software. Not only is ajax delivered content more difficult to automate, but ajax also could be used to track mouse movement. This would be one of the metrics that ajax would make available to Google, and also it could be a possible means by which Google could begin to distinguish bots from humans. (although, on the Google-scale, that would be an incredibly large amount of data to process.) While AJAX content is not as trivial to scrape as traditional content, it is still quite possible. I think that as Google evolves to develop ways to clean up their SERPs, programmers and marketers will evolve as well. I believe that software will inevitably evolve to mimic human browsing behavior. This includes filling out form data, mouse movement, sending Google Toolbar data, using back buttons, clicking links, storing cookes, etc. And don’t forget, all that will have to be done at human speeds, not computer speeds. The requirement to mimic human behavior also means that it will become more and more difficult to multi-thread and do simultaneous requests from one IP range. Rather than managing massive proxy farms, in the future, it will be more cost-effective and productive to off-load automation requests to client computers which, when required, send data back to a master server for processing (no, I’m not talking about malware here….more like browser plugins).

There are already a slew of different libraries which mimic browsing behavior and also handle ajax. Off the cuff, ScrubyT handles ajax quite well. Watir can actually open an instance of IE, FF, Safari, or even Chrome, and thus fully mimic a browser. Marketers and programmers can use these libraries, and other libraries to both mimic human browsing behavior and make ajax calls to automate SERPs. In the future, you can expect these kinds of libraries to evolve and become more advanced and customized towards mimicking human behavior. Even still, if ajax calls are not encoded, you can simply extract the appropriate call out of the page and make it yourself. An example of this can be seen here.

At the end of the day, a move on Google’s part to ajax SERPs may throw a wrench into some peoples software, but it will certainly not herald an end to automation tools like Aaron Wall’s excellent SEOToolbar, or others.

Random!, Theory

Never Up-Sell a Customer

We went out to buy a new couch today, which its FAR down on my list of favorite things to do on a sunday afternoon. I always find furniture shopping to be a harrowing experience, especially when dealing with commissioned sales people hovering like vultures.

Currently we have two big ultra-modern leather couches in our media room. We have been thinking that they’re a bit too stiff, a bit too cold. Basically, you have to be a contortionist to perform any kind of cuddling while watching a movie…so…it was time for a new couch.

In the first store we stopped at, we immediately saw a modular sofa set that was perfect…it had modern leather-clad frame but big comfy fabric cushions, and throw pillows instead of stiff leather cushions for the back…it was, in short, the ideal couch for us; especially since we were able to buy separate pieces and put them together in the arrangement we wanted (I love modular furniture). So, long story short, after we checked the dimensions, we were a firm sale (probably the easiest sale our salesman got all day).

Now, when we were checking out and paying for the sofa, the salesman did something that got me thinking: He didn’t up-sell us. He didn’t even TRY to up-sell us into add-ons, warranties, teflon stain-proofing, etc etc. No, he didn’t up-sell us, because he just put it all on the bill anyways without even asking us. Basically, he breezed over the itemized list on the bill and drew our attention directly to the total and said, “so that will be $____ dollars.” Now, I had been calculating the whole thing in my head, so I knew what to expect in terms of a final total. When I heard his total, I said, “Let me see that bill….O.K, you’ve put Teflon on here for 25.99 per module, coming to 181.00.” and he says, “Oh you want that, you definitely want that. I put it on there because you’d be crazy not to want that.” And Randy, standing next to me, said “Oh yeah, let’s get that! You’re always spilling your wine!” (sadly, it’s true). So I went on down the bill to the next item, “Now, whats this 125.00 steel base item?” and the salesman says “Well, of course, you want the steel base right? It looks a lot better than the wood. Everyone is going steel nowadays.” And Randy was there saying “Oh yeah! I love that style.” So, we got the steel base, too….

This debacle went on, item by item, until I was completely defeated and had no choice but to accept every add-on item on that bill except for one thing: the rug underlay (no joke, that was on the bill…) After we paid up and left – my wallet hurting alot more than I expected it too – I said, “We certainly bought alot more than we bargained for”, and Randy replied, “Well we knew it was going to be expensive, and besides, we didn’t end up paying as much as he initially tried to bill us.”

And there it was, the brilliance of not up-selling your customers. We never even saw what the price would have been without all those add-ons, we only saw the total price with all the add-ons included. The psychology of the situation is that once a customer sees an expensive base price, their wallet tightens up and they don’t want to spend anything more, even if it is just 25.99 per module for teflon coating, or 125.00 for a steel base.

Think about what would be more difficult: showing your customer a total price and then convincing them to spend more on upgrades? or showing a customer an upgraded price and letting them remove what they don’t really want? The answer is obvious. Chances are, the latter method will tend to get more customers to spend money on upgrades than the former method.

This lesson applies to the web as well, especially if you are marketing any kind of web-application. If you are selling something that has upgrades, why not include the upgrades automatically at checkout? It’s a win-win situation: The customer always feels better when they see their total price decrease as they customize their purchase to their needs, and chances are you’ll sell more upgrades than usual.