<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>code-diesel &#187; google</title>
	<atom:link href="http://www.codediesel.com/category/google/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Google Translation PHP wrapper</title>
		<link>http://www.codediesel.com/php/google-translation-php-wrapper/</link>
		<comments>http://www.codediesel.com/php/google-translation-php-wrapper/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 04:27:20 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/php/google-translation-php-wrapper/</guid>
		<description><![CDATA[php wrapper for the google translation api]]></description>
			<content:encoded><![CDATA[<blockquote><p>
<strong>UPDATE</strong><br />
Google has deprecated its Translation service, hence it will not be available for download anymore.
</p></blockquote>
<p>Google translation is an interesting service. Not only can you do language translation, you can also detect the language of a particular text. I recently needed to create a WordPress plugin to translate post titles from one language to another. As the translation API is only available for Java and Javascript, I decided to create a quick one for PHP. In this post we will see how to translate text from one language to another in a simple and quick way using the created class.<br />
<span id="more-2497"></span></p>
<h4>Getting the class</h4>
<p>Before we begin you need to get the PHP class from below.</p>
<h4>Testing the class</h4>
<p>The Translation class used cURL to access the Google translation service, so you need to have that installed. A quick way to check if the class is working correctly is to use the &#8216;selfTest&#8217; method of the class.</p>

<div class="wp_codebox"><table><tr id="p24971"><td class="code" id="p2497code1"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'googleTranslate.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleTranslateWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selfTest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Which will print &#8216;Test Ok&#8217; if everything is working fine.</p>
<h4>Translating text</h4>
<p>Once you are sure that the class is working properly, you can use the following simple example to translate a piece of text from one language to another.</p>

<div class="wp_codebox"><table><tr id="p24972"><td class="code" id="p2497code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'googleTranslate.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Initialize the class translate class */</span>
<span style="color: #000088;">$gt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleTranslateWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sampleText</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bonjour de cette partie du monde&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* translate(string, to_language, from_language) */</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sampleText</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;fr&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* This should print 'Hello from this part of the world' */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The first parameter of the &#8216;translate()&#8217; method takes the text to translate, the second and third parameters take the target language to translate to and the language to translate from, respectively. You can eliminate the third parameter, the language name to translate from, and Google will automatically detect the source language and translate the text. This can be useful if you are not sure of the source language but want to translate and also detect the same. A short example is given below. The following will convert the sample text and also detect the source language (French here).</p>

<div class="wp_codebox"><table><tr id="p24973"><td class="code" id="p2497code3"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'googleTranslate.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleTranslateWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bonjour de cette partie du monde&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/* Convert from English */</span>
<span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDetectedSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Errors during translation</h4>
<p>If the class fails to translate the text for some reason, you can read the error message using the &#8216;getLastError&#8217; method.</p>

<div class="wp_codebox"><table><tr id="p24974"><td class="code" id="p2497code4"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">.</span></pre></td></tr></table></div>

<p>The class also provides the &#8216;isSuccess&#8217; method to check if the translation was successful.</p>

<div class="wp_codebox"><table><tr id="p24975"><td class="code" id="p2497code5"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/* Was translation successful */</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isSuccess</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>Detecting language of a text block</h4>
<p>You can also detect the language of a particular text block as shown below. This can be quite useful if you would like to detect the language of a web page or a block of a chat conversation.</p>

<div class="wp_codebox"><table><tr id="p24976"><td class="code" id="p2497code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'googleTranslate.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$gt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleTranslateWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Detect the language of the given text */</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;For me, it is far better to grasp
        the Universe as it really is than
        to persist in delusion, however
        satisfying and reassuring.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">detectLanguage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This will output an array with the following response elements:</p>

<div class="wp_codebox"><table><tr id="p24977"><td class="code" id="p2497code7"><pre class="text" style="font-family:monospace;">[language] =&gt; en
[isReliable] =&gt; 1
[confidence] =&gt; 0.7626736</pre></td></tr></table></div>

<p>The first index gives the language code for the given text block. The second index represents a boolean value showing whether or not the detected language code is reliable for the given text. The third and last parameter is a numeric value between 0 &#8211; 1.0 that represents the confidence level in the language detected for the given text.</p>
<h4>Caching</h4>
<p>The class also has the facility to cache the results, so if you post a text for translation and it is already in the cache the cached results will be returned instead of going out to Google for translation, this helps decrease translation time. The cache can be enabled or disabled as below, by default the cache is enabled.</p>

<div class="wp_codebox"><table><tr id="p24978"><td class="code" id="p2497code8"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'googleTranslate.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleTranslateWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/* Enable the cache */</span>
<span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cacheEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* This will disable the cache; by default the cache is enabled */</span>
<span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cacheEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Make sure that the &#8216;cache&#8217; directory is there in the directory where your php file is located. If you need to locate the &#8216;cache&#8217; directory somewhere different than you can change it in the &#8216;googleTranslate.class.php&#8217; file. Locate the following line in the file, and then change the directory path to the one you want.</p>

<div class="wp_codebox"><table><tr id="p24979"><td class="code" id="p2497code9"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_cache_directory</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./cache/'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Setting correct Referer header</h4>
<p>Google requires that you send the referrer header with every request. Although it works without it, it is recommended that you use it. You can add a referrer header as below:</p>

<div class="wp_codebox"><table><tr id="p249710"><td class="code" id="p2497code10"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
<span style="color: #000088;">$gt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleTranslateWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setReferrer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.your_site_name.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span></pre></td></tr></table></div>

<p>This sends your site name in the &#8216;Referer&#8217; header in the request.</p>
<h4>Passing valid credentials</h4>
<p>Although the class works without you providing a apiKey &#8211; <strong>using a key in your application/site is completely optional</strong>, Google recommends adding your API key and a IP address during the translation request. This helps Google detect valid requests coming from your site and helps it in contacting you in case a need arises. You can signup for the api key <a href="http://code.google.com/apis/ajaxsearch/signup.html" rel="nofollow" target="_blank" >here</a>.</p>
<p>You can pass a API key and a IP address using the following.</p>

<div class="wp_codebox"><table><tr id="p249711"><td class="code" id="p2497code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'googleTranslate.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$apiKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR API KEY&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/* Change to your IP address */</span>
<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GoogleTranslateWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCredentials</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$apiKey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mon nom est Sameer&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$gt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Passing correct content headers</h4>
<p>Make sure you have the following code at the start of your php code:</p>

<div class="wp_codebox"><table><tr id="p249712"><td class="code" id="p2497code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/html; charset=utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span></pre></td></tr></table></div>

<p>or if the page is html, the following in your head tags:</p>

<div class="wp_codebox"><table><tr id="p249713"><td class="code" id="p2497code13"><pre class="html" style="font-family:monospace;">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;</pre></td></tr></table></div>

<p>Not setting the correct content type will display gibberish characters for Chinese and texts that have special characters.</p>
<h4>Language Codes</h4>
<p>Below is a list of language codes you can use during translation.</p>

<div class="wp_codebox"><table><tr id="p249714"><td class="code" id="p2497code14"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">&quot;af&quot;</span><span style="color: #339933;">-</span>Afrikaans
<span style="color: #0000ff;">&quot;sq&quot;</span><span style="color: #339933;">-</span>Albanian
<span style="color: #0000ff;">&quot;ar&quot;</span><span style="color: #339933;">-</span>Arabic
<span style="color: #0000ff;">&quot;hy&quot;</span><span style="color: #339933;">-</span>Armenian ALPHA
<span style="color: #0000ff;">&quot;az&quot;</span><span style="color: #339933;">-</span>Azerbaijani ALPHA
<span style="color: #0000ff;">&quot;eu&quot;</span><span style="color: #339933;">-</span>Basque ALPHA
<span style="color: #0000ff;">&quot;be&quot;</span><span style="color: #339933;">-</span>Belarusian
<span style="color: #0000ff;">&quot;bg&quot;</span><span style="color: #339933;">-</span>Bulgarian
<span style="color: #0000ff;">&quot;ca&quot;</span><span style="color: #339933;">-</span>Catalan
<span style="color: #0000ff;">&quot;zh-CN&quot;</span><span style="color: #339933;">-</span>Chinese
<span style="color: #0000ff;">&quot;hr&quot;</span><span style="color: #339933;">-</span>Croatian
<span style="color: #0000ff;">&quot;cs&quot;</span><span style="color: #339933;">-</span>Czech
<span style="color: #0000ff;">&quot;da&quot;</span><span style="color: #339933;">-</span>Danish
<span style="color: #0000ff;">&quot;nl&quot;</span><span style="color: #339933;">-</span>Dutch
<span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #339933;">-</span>English
<span style="color: #0000ff;">&quot;et&quot;</span><span style="color: #339933;">-</span>Estonian
<span style="color: #0000ff;">&quot;tl&quot;</span><span style="color: #339933;">-</span>Filipino
<span style="color: #0000ff;">&quot;fi&quot;</span><span style="color: #339933;">-</span>Finnish
<span style="color: #0000ff;">&quot;fr&quot;</span><span style="color: #339933;">-</span>French
<span style="color: #0000ff;">&quot;gl&quot;</span><span style="color: #339933;">-</span>Galician
<span style="color: #0000ff;">&quot;ka&quot;</span><span style="color: #339933;">-</span>Georgian ALPHA
<span style="color: #0000ff;">&quot;de&quot;</span><span style="color: #339933;">-</span>German
<span style="color: #0000ff;">&quot;el&quot;</span><span style="color: #339933;">-</span>Greek
<span style="color: #0000ff;">&quot;ht&quot;</span><span style="color: #339933;">-</span>Haitian Creole ALPHA
<span style="color: #0000ff;">&quot;iw&quot;</span><span style="color: #339933;">-</span>Hebrew
<span style="color: #0000ff;">&quot;hi&quot;</span><span style="color: #339933;">-</span>Hindi
<span style="color: #0000ff;">&quot;hu&quot;</span><span style="color: #339933;">-</span>Hungarian
<span style="color: #0000ff;">&quot;is&quot;</span><span style="color: #339933;">-</span>Icelandic
<span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #339933;">-</span>Indonesian
<span style="color: #0000ff;">&quot;ga&quot;</span><span style="color: #339933;">-</span>Irish
<span style="color: #0000ff;">&quot;it&quot;</span><span style="color: #339933;">-</span>Italian
<span style="color: #0000ff;">&quot;ja&quot;</span><span style="color: #339933;">-</span>Japanese
<span style="color: #0000ff;">&quot;ko&quot;</span><span style="color: #339933;">-</span>Korean
<span style="color: #0000ff;">&quot;lv&quot;</span><span style="color: #339933;">-</span>Latvian
<span style="color: #0000ff;">&quot;lt&quot;</span><span style="color: #339933;">-</span>Lithuanian
<span style="color: #0000ff;">&quot;mk&quot;</span><span style="color: #339933;">-</span>Macedonian
<span style="color: #0000ff;">&quot;ms&quot;</span><span style="color: #339933;">-</span>Malay
<span style="color: #0000ff;">&quot;mt&quot;</span><span style="color: #339933;">-</span>Maltese
<span style="color: #0000ff;">&quot;no&quot;</span><span style="color: #339933;">-</span>Norwegian
<span style="color: #0000ff;">&quot;fa&quot;</span><span style="color: #339933;">-</span>Persian
<span style="color: #0000ff;">&quot;pl&quot;</span><span style="color: #339933;">-</span>Polish
<span style="color: #0000ff;">&quot;pt&quot;</span><span style="color: #339933;">-</span>Portuguese
<span style="color: #0000ff;">&quot;ro&quot;</span><span style="color: #339933;">-</span>Romanian
<span style="color: #0000ff;">&quot;ru&quot;</span><span style="color: #339933;">-</span>Russian
<span style="color: #0000ff;">&quot;sr&quot;</span><span style="color: #339933;">-</span>Serbian
<span style="color: #0000ff;">&quot;sk&quot;</span><span style="color: #339933;">-</span>Slovak
<span style="color: #0000ff;">&quot;sl&quot;</span><span style="color: #339933;">-</span>Slovenian
<span style="color: #0000ff;">&quot;es&quot;</span><span style="color: #339933;">-</span>Spanish
<span style="color: #0000ff;">&quot;sw&quot;</span><span style="color: #339933;">-</span>Swahili
<span style="color: #0000ff;">&quot;sv&quot;</span><span style="color: #339933;">-</span>Swedish
<span style="color: #0000ff;">&quot;th&quot;</span><span style="color: #339933;">-</span>Thai
<span style="color: #0000ff;">&quot;tr&quot;</span><span style="color: #339933;">-</span>Turkish
<span style="color: #0000ff;">&quot;uk&quot;</span><span style="color: #339933;">-</span>Ukrainian
<span style="color: #0000ff;">&quot;ur&quot;</span><span style="color: #339933;">-</span>Urdu ALPHA
<span style="color: #0000ff;">&quot;vi&quot;</span><span style="color: #339933;">-</span>Vietnamese
<span style="color: #0000ff;">&quot;cy&quot;</span><span style="color: #339933;">-</span>Welsh
<span style="color: #0000ff;">&quot;yi&quot;</span><span style="color: #339933;">-</span>Yiddish</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/google-translation-php-wrapper/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Reading Google Analytics data from PHP</title>
		<link>http://www.codediesel.com/php/reading-google-analytics-data-from-php/</link>
		<comments>http://www.codediesel.com/php/reading-google-analytics-data-from-php/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 10:42:59 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[analytics]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/php/reading-google-analytics-data-from-php/</guid>
		<description><![CDATA[How you can access the Google Analytics data from PHP]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.google.com/analytics/" rel="nofollow" target="_blank" >Google Analytics</a> has become a important part of any web sites traffic analysis strategy. And with the release of the Analytics API people have been able to create custom reports and mashups for their organizations. Although no standard library is available from Google for PHP, some small and easy interfaces are available out there. In this post we will see how to access Google Analytics data using PHP using the GAPI library.<br />
<span id="more-2377"></span></p>
<h4>Installing the GAPI class</h4>
<p>The following code uses the  GAPI &#8211; Google Analytics API PHP Interface to help us access the Analytics data. So before proceeding you need to download the class file from the <a href="http://code.google.com/p/gapi-google-analytics-php-interface/" rel="nofollow" target="_blank" >GAPI home</a>.</p>
<h4>Dimensions &#038; Metrics</h4>
<p>Before we start a small primer on Google Analytics Dimensions &#038; Metrics will be helpful.</p>
<p><strong>What is a dimension?</strong><br />
Dimensions are things like browser and country, browser versions, landing and exit pages, the URL of a page, and the source website a visitor has come from.<br />
Google Analytics uses the following 5 main marketing dimensions for analysis:</p>
<p>    * Source<br />
    * Medium<br />
    * Term<br />
    * Content<br />
    * Campaign</p>
<p><strong>What is a metric?</strong><br />
Metrics are the quantitative measure of a dimension for specific data types, such as counts of new visitors, page views, unique page views etc.</p>
<h4>Getting the Google Analytics data</h4>
<p>Now that we have seen what Dimensions &#038; Metrics are we will proceed with an example. In this example we will fetch the &#8216;source&#8217; dimension, which shows the source website the visitor is coming from and the &#8216;visits&#8217; metric. This tells us how many visitors are coming from a particular source to our site.</p>

<div class="wp_codebox"><table><tr id="p237715"><td class="code" id="p2377code15"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require</span> <span style="color: #0000ff;">'gapi-1.3/gapi.class.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Set your Google Analytics credentials */</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ga_account'</span>     <span style="color: #339933;">,</span><span style="color: #0000ff;">'YOUR ANALYTICS EMAIL'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ga_password'</span>    <span style="color: #339933;">,</span><span style="color: #0000ff;">'YOUR ANALYTICS PASSWORD'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ga_profile_id'</span>  <span style="color: #339933;">,</span><span style="color: #0000ff;">'ANALYTICS SITE PROFILE ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ga</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> gapi<span style="color: #009900;">&#40;</span>ga_account<span style="color: #339933;">,</span>ga_password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* We are using the 'source' dimension and the 'visits' metrics */</span>
<span style="color: #000088;">$dimensions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'source'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$metrics</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'visits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* We will sort the result be desending order of visits, 
    and hence the '-' sign before the 'visits' string */</span>
<span style="color: #000088;">$ga</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">requestReportData</span><span style="color: #009900;">&#40;</span>ga_profile_id<span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #339933;">,</span> <span style="color: #000088;">$metrics</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'-visits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gaResults</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ga</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResults</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gaResults</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%-4d</span> <span style="color: #009933; font-weight: bold;">%-40s</span> <span style="color: #009933; font-weight: bold;">%5d</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
           <span style="color: #000088;">$i</span><span style="color: #339933;">++,</span>
           <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getVisits</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>-----------------------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Total Results : {<span style="color: #006699; font-weight: bold;">$ga-&gt;getTotalResults</span>()}&quot;</span><span style="color: #339933;">;</span>    
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Below I&#8217;ve listed the top ten results of the output.</p>

<div class="wp_codebox"><table><tr id="p237716"><td class="code" id="p2377code16"><pre class="text" style="font-family:monospace;">No.  Source                                   Visits
------------------------------------------------------
1    google                                   10549
2    (direct)                                  1484
3    stumbleupon.com                           1338
4    webintenta.com                             159
5    bing                                       142
6    yahoo                                      115
7    feedburner                                  97
8    phpdeveloper.org                            70
9    t3n.de                                      64
10   clearspace.openqa.org                       43</pre></td></tr></table></div>

<p>As you can see the main method in the class is the &#8216;requestReportData()&#8217;, which has the following structure:</p>

<div class="wp_codebox"><table><tr id="p237717"><td class="code" id="p2377code17"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> requestReportData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$report_id</span><span style="color: #339933;">,</span>      
                           <span style="color: #000088;">$dimensions</span><span style="color: #339933;">,</span> 
                           <span style="color: #000088;">$metrics</span><span style="color: #339933;">,</span> 
                           <span style="color: #000088;">$sort_metric</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> 
                           <span style="color: #000088;">$filter</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> 
                           <span style="color: #000088;">$start_date</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> 
                           <span style="color: #000088;">$end_date</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> 
                           <span style="color: #000088;">$start_index</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
                           <span style="color: #000088;">$max_results</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>You can get the Dimension and Metric result by prefixing &#8216;get&#8217; to the dimension or metric name. For e.g, if you metric name is &#8216;region&#8217;, you can get the result by using:</p>

<div class="wp_codebox"><table><tr id="p237718"><td class="code" id="p2377code18"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRegion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Although I have only provided a single Dimension and Metric in the example code, the $dimensions and $metrics parameter can take multiple parameters as shown below:</p>

<div class="wp_codebox"><table><tr id="p237719"><td class="code" id="p2377code19"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dimensions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'source'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'region'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$metrics</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'visits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Bear in mind to specify a valid &#8216;dimension-metric&#8217; combination as given in the <a href="http://code.google.com/apis/analytics/docs/gdata/gdataReferenceValidCombos.html" rel="nofollow" >API Docs</a>. Specifying an invalid combination will return 0 results.</p>
<p>The output after adding the &#8216;region&#8217; dimension is shown below.</p>

<div class="wp_codebox"><table><tr id="p237720"><td class="code" id="p2377code20"><pre class="text" style="font-family:monospace;">No. Source     Region               Visits
-----------------------------------------
1   google     (not set)              965
2   google     England                796
3   google     California             650
4   google     Maharashtra            343
5   google     Karnataka              340
6   google     Tamil Nadu             295
7   google     New York               225
8   google     Andhra Pradesh         189
9   google     Texas                  172
10  google     Ontario                165</pre></td></tr></table></div>

<h4>Modifying the amount of results returned</h4>
<p>By default the class returns the first 30 results, although the raw Google API returns 1000 results by default. You can increase the same by changing the $max_results parameter. Google Analytics returns a maximum of 10,000 results, even if you set the $max_results parameter above 10,000. To get the results above that limit you need to set the $start_index parameter to 10,000, which will then get the results starting at 10,000.</p>

<div class="wp_codebox"><table><tr id="p237721"><td class="code" id="p2377code21"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ga</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">requestReportData</span><span style="color: #009900;">&#40;</span>ga_profile_id<span style="color: #339933;">,</span>
                       <span style="color: #000088;">$dimensions</span><span style="color: #339933;">,</span>
                       <span style="color: #000088;">$metrics</span><span style="color: #339933;">,</span>
                       <span style="color: #0000ff;">'-visits'</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// Sort by 'visits' in descending order</span>
                       <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// We are not using this paras yet</span>
                       <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>  <span style="color: #009933; font-style: italic;">// Start Index</span>
                       <span style="color: #cc66cc;">500</span> <span style="color: #009933; font-style: italic;">// Max results</span>
                       <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You can get the total number of results by using the getTotalResults() method. This can be helpful in pagination.</p>

<div class="wp_codebox"><table><tr id="p237722"><td class="code" id="p2377code22"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ga</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTotalResults</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Setting the Google Analytics report period</h4>
<p>By default the class returns the data for the last 1 month from today if no report period is specified. You can specify the report period as below. The date format is in the form &#8216;YYYY-MM-DD&#8217;.</p>

<div class="wp_codebox"><table><tr id="p237723"><td class="code" id="p2377code23"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ga</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">requestReportData</span><span style="color: #009900;">&#40;</span>ga_profile_id<span style="color: #339933;">,</span>
                       <span style="color: #000088;">$dimensions</span><span style="color: #339933;">,</span>
                       <span style="color: #000088;">$metrics</span><span style="color: #339933;">,</span>
                       <span style="color: #0000ff;">'-visits'</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// Sort by 'visits' in descending order</span>
                       <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                       <span style="color: #0000ff;">'2009-10-01'</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// Start Date</span>
                       <span style="color: #0000ff;">'2009-12-31'</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// End Date</span>
                       <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>  <span style="color: #009933; font-style: italic;">// Start Index</span>
                       <span style="color: #cc66cc;">500</span> <span style="color: #009933; font-style: italic;">// Max results</span>
                       <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Filtering the data</h4>
<p>You can further filter the results using the $filter parameter. Filtering is a little tricky, so be sure to read the Google <a href="http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDataFeed.html#filters" rel="nofollow" >documentation</a>.</p>

<div class="wp_codebox"><table><tr id="p237724"><td class="code" id="p2377code24"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$filter</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'country == United States'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ga</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">requestReportData</span><span style="color: #009900;">&#40;</span>ga_profile_id<span style="color: #339933;">,</span>
                       <span style="color: #000088;">$dimensions</span><span style="color: #339933;">,</span>
                       <span style="color: #000088;">$metrics</span><span style="color: #339933;">,</span>
                       <span style="color: #0000ff;">'-visits'</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// Sort by 'visits' in descending order</span>
                       <span style="color: #000088;">$filter</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// Filter the data</span>
                       <span style="color: #0000ff;">'2009-10-01'</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// Start Date</span>
                       <span style="color: #0000ff;">'2009-12-31'</span><span style="color: #339933;">,</span> <span style="color: #009933; font-style: italic;">// End Date</span>
                       <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>  <span style="color: #009933; font-style: italic;">// Start Index</span>
                       <span style="color: #cc66cc;">500</span> <span style="color: #009933; font-style: italic;">// Max results</span>
                       <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You can also combine various options:</p>

<div class="wp_codebox"><table><tr id="p237725"><td class="code" id="p2377code25"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$filter</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'country == United States &amp;&amp; visitorType == New Visitor'</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">// OR</span>
<span style="color: #000088;">$filter</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'country == United States &amp;&amp;
           visitorType == New Visitor &amp;&amp;
           browser == Firefox'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Getting a list of your Google Analytics Accounts</h4>
<p>Most users have more than one profiles in their Analytics account. You can easily get a list of all your accounts (sitename &#8211; profileid) with the following code.</p>

<div class="wp_codebox"><table><tr id="p237726"><td class="code" id="p2377code26"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require</span> <span style="color: #0000ff;">'gapi-1.3/gapi.class.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Set your Google Analytics credentials */</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ga_account'</span>     <span style="color: #339933;">,</span><span style="color: #0000ff;">'YOUR ANALYTICS EMAIL'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ga_password'</span>    <span style="color: #339933;">,</span><span style="color: #0000ff;">'YOUR ANALYTICS PASSWORD'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ga</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> gapi<span style="color: #009900;">&#40;</span>ga_account<span style="color: #339933;">,</span>ga_password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gaResult</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ga</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">requestAccountData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gaResult</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%-30s</span> <span style="color: #009933; font-weight: bold;">%15d</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProfileId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>With this we conclude this post. It will be quite helpful if you go over the below references if you are unfamiliar with the Google Analytics API.</p>
<h4>Update</h4>
<p><a href="http://www.webresourcesdepot.com/feedcount-like-google-analytics-counter/" rel="nofollow" target="_blank" >Webresourcesdepot</a> features a nifty little application using the above to dispay the Google pageviews in a Feed-burner style chicklet display.</p>
<blockquote><p>
References:<br />
a. <a href="http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDataFeed.html#dataRequest" rel="nofollow" >Google Analytics Data API &#8211; Data Feed</a><br />
b. <a href="http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html" rel="nofollow" >Dimensions &#038; Metrics Reference</a><br />
c. <a href="http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDataFeed.html#filters" rel="nofollow" >Filters</a>
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/reading-google-analytics-data-from-php/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Google Chrome benchmarks</title>
		<link>http://www.codediesel.com/javascript/google-chrome-benchmarks/</link>
		<comments>http://www.codediesel.com/javascript/google-chrome-benchmarks/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 08:55:25 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=97</guid>
		<description><![CDATA[Google Chrome Beta for Windows is finally here. There are many factors that make this browser interesting; being open source and using the WebKit rendering engine is one of them. But one of the great things is the speed of the JavaScript engine. Chrome uses Google&#8217;s open source V8 JavaScript engine, and it is amazingly [...]]]></description>
			<content:encoded><![CDATA[<p>Google Chrome Beta for Windows is finally here. There are many factors that make this browser interesting; being open source and using the WebKit rendering engine is one of them. But one of the great things is the speed of the JavaScript engine. Chrome uses Google&#8217;s open source <a href="http://www.google.com/chrome/" rel="nofollow"  target="_blank">V8</a> JavaScript engine, and it is amazingly fast. I ran the <a href="http://www2.webkit.org/perf/sunspider-0.9/sunspider.html" rel="nofollow"  target="_blank">SunSpider 0.9</a> benchmark and here are the results:<br />
<span id="more-97"></span><br />
<a href="http://www.codediesel.com/wp-content/uploads/2008/09/chrome_benchmark1.gif"><img class="aligncenter" style="border: 1px solid #c0c0c0;" title="chrome_benchmark1" src="http://www.codediesel.com/wp-content/uploads/2008/09/chrome_benchmark1.gif" alt="google chrome benchmarks" width="519" height="310" /></a></p>
<p>As you can see it is blazingly fast, being twice as fast as Firefox 3 and twenty times faster than Internet Explorer 6.  If you are using JavaScript heavy applications like Gmail or Javascript UI frameworks like Yahoo UI, extJS, jQuery etc. than you can really reap the benefits of a fast engine. If you like to see a visual comparison try running one of John Resig&#8217;s <a href="http://ejohn.org/apps/processing.js/examples/topics/reach3.html" rel="nofollow" title="processing.js demo"  target="_blank">Processing.js demo</a> in Firefox 3 and Chrome and you can see how fast Chrome can run JavaScript.</p>
<p>Some of the other interesting things Google Chrome offers can be read in a comic format <a href="http://www.google.com/googlebooks/chrome/" rel="nofollow"  target="_blank">here</a> &#8211; designed by the brilliant <a href="http://www.scottmccloud.com/" rel="nofollow" title="scott mccloud"  target="_blank">Scott McCloud</a>, a sample page is shown below.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2008/09/chrome_comic.gif"><img class="aligncenter size-full wp-image-99" style="border: 1px solid #c0c0c0;" title="chrome_comic" src="http://www.codediesel.com/wp-content/uploads/2008/09/chrome_comic.gif" alt="" width="358" height="509" /></a></p>
<p>You can download Google Chrome <a href="http://www.google.com/chrome/" rel="nofollow"  target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/google-chrome-benchmarks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

