Category: Search Engine

Google’s Analytics API with PHP

I was recently asked about my experience with Google’s Analytics API, my reply was bla, bla, bla, I do not have any experience with their API’s.  But to be honest I couldn’t remember why at that moment I didn’t. I think the only reason was because of their documentation, for some of their API’s it’s a pretty long, difficult read. But overall that wasn’t a very good reason, so I decided to take some time and dive in and whoop that trick (line from the hustle and flow movie).
The goal for this post to help anyone who may be having a hard time understanding how to build a connection to Google’s Analytics API.
So first there are a couple of things you need to know.

There are only two files needed in this script but the connection part is the only part we will be going over, it’s in the gaClass.php file.
So basically I’m still new to  Google’s Analytics API but what I’ve learned so far is that once you’ve established a connection the rest is pretty simple.  So basically that’s why we will be focusing on the establishing a connection part only.

Your first major goal while trying to establish a connection is to collect the authentication string. Within that string is your authentication token, and without that token you can’t get anywhere so remember that. The overall objective is to get the authentication token.

So open up the gaClass.php file and take a look at the construct method, this is where the connection happens. Please contact me if I confuse your somewhere, I try to code so that it’s easy to follow.

  • Within the construct method we start off by collection your email and password that was set on the form page. They of course are needed to connect to your account.
  • We set the url that we will be trying to making a connection to. In this case it’s the ClientLogin URL (https://www.google.com/accounts/ClientLogin) . Take note that the protocol starts with HTTPS.
  • Within our POST request we have a few additional parameters that will need to be pass along including your email and password. A short description of these parameters can be found at (http://code.google.com/apis/analytics/docs/gdata/gdataAuthentication.html) scroll down until you see the HTTP Protocol Details heading
  • Now once we have all the parameters set we will try to actually make the connection. We do this within the next method. The curlConnection method, and it does exactly what it says, tries to makes the connection via cURL
  • The curlConnection method will take the parameters we talked about earlier and send them to the ClientLogin URL via cURL using a POST method. The answer we receive from this post will or will not include our authentication token.
  • Now let’s suppose it does and the header status code equal 200, which means it’s A-OK. Within that connection response output you will see a encrypted string. But look closers you’ll see three variables with three values assigned to it. The variables are labeled , “SID”, “LSID” and  “AUTH”. Well you want the AUTH and it value.  Our next task is to parse out the AUTH variable and its value, and we do this with the setAccessToken method.
  • The setAccessToken is fairly simple we take that string and convert it to an array using PHP’s built in explode function.  The access token should be in the second element. I then assign this value to a token variable to be used later for accessing other parts of the API. If you recall when we started this post the authentication token is essential to other parts of the API. Without it you basically can’t do anything.

So that you can get a idea of what the output data look like.  I’ve included a screen shot of the header response output, the authentication output, when the authentication output is converted into a array, and the authentication token.

Googles Analytics API Header Response

 

 

 

 

 

 

 

 

 

 

 

 

I’m new to Mercurial so please don’t give me a hard time about my commits or the lack of.
https://bitbucket.org/josephtinsley/google-analytics-api/overview

Google Analytics API with PHP

 

 

R.I.P. Yahoo Search Submit Pro

YSSP went offline this morning; it’s going to be interesting to see what Yahoo will focus on next. I actually believed in the YSSP program, it was a great way for some of these mammoth sized websites to get their products indexed. Could there have been more transparency, yea probably so. But to see the true benefit of the program you would have to look at the big picture. A bunch of revenue was generated and butt load of jobs where also created. Plus I like to believe that the program help customers locate products easier. And if I had to guess I would guess that majority of the agencies/resellers that Yahoo partnered with operated in good faith. So think about it for a second there where probably hundreds of agencies/resellers submitting millions and millions of clean, optimized and sometimes fresh URL’s to Yahoo. I like that idea. I like the fact that I can trust a program that employed a bunch of people to police and submitted trusted data. So when I clicked on a link then that’s where I’m directed to. Yea in any program that involves money your going to have people who will try and dupe the system. But in the grand scheme of things I believe there had to be more good then evil here.

Anyway sorry for the rant, back to topic, what will Yahoo focuses on next. I personally hope Yahoo and the other engines will put a little more effort into the Search Monkey, RDFa and Rich Snippet projects. I think there’s a lot of opportunity in enhanced search results, especially if your site is product driven. Right now it doesn’t seem like it’s on anyone’s radar and that perhaps all of the Search Monkey and Rich Snippet hoopla was a just a big PR stunt. Basically one of those “We can do it also” type of things.
Here’s an example. Shortly after the dust settled on the Yahoo killing YSSP program stuff AOL announced that they may offer a paid inclusion program. Now it’s hard to tell if this was a serious statement or just a stunt to attract attention.

AOL To Capitalize On Yahoo Ending Paid Inclusion Program

 

Google XML Sitemap: Export Title, Description and Keywords to Excel

Google XML Sitemap: Download the Title, Description & Keywords tags from your sites webpage via your Google XML sitemap and then export the data into a excel spreadsheet. I’m not totally sure what to call this tool yet. I started out creating something else and took a totally different direction. That’s not to say this is not a useful tool. Basically if you’ve ever been in a situation and wonder how many URL’s are included in a Google XML sitemap, then this application will help you. Or if you’ve ever been in a pickle and wondered how well my Titles, Descriptions, or Keywords Tags are optimized, then this application will help yuo also. Once you submit your Google XML sitemap the application will download all of the URL’s included in your XML Sitemap and then one URL at a time goes out and fetches the Title and Meta Information. It then runs the character count from this data against what is deemed by Yahoo as being a well formatted Title and Meta Tag by YSSP standards. Title 70 characters in length, Description 170 characters in length, and 12 Keywords. I took a look at the Google Webmaster rule set also and added in some padding.
So for example the application will color the character count number Green if the Title falls in-between 60 and 70 characters. Then Red if the count is over 70 characters and Purple if it’s under 60 characters. This color theme is used also for the Description and the Keywords.

The complete thresholds includes.
Title: >=60 <=70 Good; > 70 Red; < 60 Purple
Description: >=150 <=170 Good; > 170 Red; < 150 Purple
Keywords:   >=10 <=12 Good; > 12 Red; < 10 Purple

Google Sitemap Tool
Creating and submitting Sitemaps

Why Bing

Bing is quickly becoming my new best friend. A couple of weeks I blogged about RDFa tags and Rich Snippets and the visibility I was getting from Bing search engine. Well the day after I modified the tags to see if I could learn how to better control the content that is being displayed in the hover description section. Well I just noticed the address was updated so it seems that Bing is actually responsive to my updates. My next goal is to see if I can get my image displayed within that section. I have an RDFa image tag already in place but I must have something wrong because that has not been displayed yet. So I’m going to do some additional research and modify the code a bit when I fine something out. The new information is a great discovery and I’m pretty stoked right now. It’s all about testing your data and not always relying on what you read. Trust yourself first!

Yahoo Search Monkey, Google Rich Snippets: No Love

Yahoo Search Monkey and Google Rich Snippets is giving me no love. I have been working really hard to get some type of visibility from Yahoo Search Monkey and Google rich Snippets. I’ve tried RDFa tags and the Yahoo’s adjunct tags and nothing. It’s probably going on the 3rd or 4th week now, and nada. With Yahoo Search Monkey I’ve tried thier several options, DataRSS, submitting via Site Explorer but I still come up empty. But today surprisingly I did catch a little luck, not from the search engines that I was expecting and targeting, but from Bing, Yea Bing. It’s nothing to go shouting from the roof tops about but it was kind of interesting. Within the description you get when you mouse over the search results Title Tag, Bing is now including by Street Address. This can only be pulling from the RDF tags that I included. It’s little but it give me hope that things are possible and with some tweaks perhaps I can better control what’s being displayed in that area. Again not really a big deal but I’m really happy to see some movement. Thanks Bing for the love!

Google Favicon API, PHP Code

I ran into something very, very interesting today. Google Favicon API
(A Favorite Icon API)
. It’s an API that allows you to pull websites Favicons, plus the API dynamically converts the image into a PNG format. This actually comes at a great time because I was just thinking the other day that since I have the option to add offsite URL’s to my site now. Would’nt it would be supa cool if I could also included their Favicon? To beak it down if you look into my site’s right side navigation you will see the “Links” category. Well I thought it would be nice, I mean supa cool if I had a script that could automatically include the corresponding sites Favicons.  And BAM! Thanks Google Favicon API. I wrapped this APIs up with some cURL and a little PHP and now I have a working PHP function. I don’t know much about the Google Favicon API but it looks like it’s been around for about a year. So it’s a good chance that this API could suddenly up and move or disappear all togehter. Basically what I’m saying is I don’t know how long the good times will last. So in my opinion I suggest you consider the use of this script temporary until you can get the time to build a much reliable one yourself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?PHP
function getFavicon($var){
$filName=substr($var,0,-4);
$fp = fopen ('folder/'.$filName.'.png', 'w+');
$ch = curl_init('http://www.google.com/s2/favicons?domain='.$var);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);

}

$var='techcrunch.com';
getFavicon($var);
?>

Copyright © 2024 Joseph Tinsley

Theme by Anders NorenUp ↑