<?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>thought snippets &#187; api</title>
	<atom:link href="http://blog.u-blue.com/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.u-blue.com</link>
	<description>a little bit of everything</description>
	<lastBuildDate>Tue, 08 Nov 2011 03:42:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Visible stat from Google Analytics</title>
		<link>http://blog.u-blue.com/en/2010/02/10/visible-stat-with-google-analytics/</link>
		<comments>http://blog.u-blue.com/en/2010/02/10/visible-stat-with-google-analytics/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 11:15:48 +0000</pubDate>
		<dc:creator>nice</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[playground]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[google analytic]]></category>

		<guid isPermaLink="false">http://blog.u-blue.com/?p=213</guid>
		<description><![CDATA[From my old blog Extract data from google analytic with PHP makes me wanna write another script to show number of pageviews on the web for all the world to see. It&#8217;s actually an old school &#8220;web counter&#8221; as we know it and since normally you can&#8217;t just extract pageviews data from google analytics to display ]]></description>
			<content:encoded><![CDATA[<p>From my old blog <a href="http://blog.u-blue.com/en/2010/02/09/google-analytic-api-extract-data-php/">Extract data from google analytic with PHP</a> makes me wanna write another script to show number of pageviews on the web for all the world to see. It&#8217;s actually an old school &#8220;web counter&#8221; as we know it and since normally you can&#8217;t just extract pageviews data from google analytics to display on your website I have to make use of my old GAAPI class to extract data to create the counter, see example below.</p>
<div id="attachment_214" class="wp-caption alignnone" style="width: 122px"><a href="http://blog.u-blue.com/wp-content/uploads/2010/02/Screen-shot-2010-02-10-at-5.56.11-PM.png"><img class="size-full wp-image-214" title="Google Analytic Visible Stat" src="http://blog.u-blue.com/wp-content/uploads/2010/02/Screen-shot-2010-02-10-at-5.56.11-PM.png" alt="" width="112" height="41" /></a><p class="wp-caption-text">GA Visible Stat</p></div>
<p><span id="more-213"></span></p>
<p><strong>How to use?</strong></p>
<ol>
<li>Load <strong> <a href="http://blog.u-blue.com/wp-content/uploads/2010/02/GAAPI1.zip">GAAPI</a> </strong> from my old blog though we&#8217;ll use only gaapi.class.php here.</li>
<li>Construct gaapi class and call method All Time Page Views (total number of page views)
<pre class="brush:php">
include_once('gaapi.class.php');
$ga=new gaApi('google username','password','ga:site id');
$allTimeSummery=$ga-&gt;getAllTimeSummery();</pre>
</li>
<li>Show the counter using HTML with CSS<br />
CSS:&nbsp;</p>
<pre class="brush:css">#vGA{
	width: 100px;
	position: relative;
	font-size: 9px;
	font-family: Verdana, Verdana, Geneva, sans-serif;
	padding-bottom: 15px;
	background: url(poweredBy.gif) no-repeat bottom left;
}
#vGA div{
	text-align: right;
	border: 2px solid #4f6db0;
	color: #555;
	line-height: 15px;
}
#vGA #vGALabel{
	background: #4f6db0;
	text-align: center;
	color: white;
	float: right;
	padding: 0 0 0 2px;
	margin: 0 0 0 2px;
}</pre>
<p>HTML:</p>
<pre class="brush:html">
<div id="vGA">
<div>&lt;?= $allTimeSummery['ga:pageviews'] ?&gt;
       <span id="vGALabel">Views</span></div>
</div>
</pre>
</li>
<li>Save this Powered By Google image into the same folder as others files
<p><div id="attachment_215" class="wp-caption alignright" style="width: 97px"><a href="http://blog.u-blue.com/wp-content/uploads/2010/02/poweredBy.gif"><img class="size-full wp-image-215" title="Powered By Google Analytic" src="http://blog.u-blue.com/wp-content/uploads/2010/02/poweredBy.gif" alt="" width="87" height="15" /></a><p class="wp-caption-text">Powered By</p></div></li>
</ol>
<p>And now we&#8217;ve got easy Visible Stat from Google Analytic. If you wish to show other data such as Unique Visits you can do so by follow instruction from my old blog <a href="http://blog.u-blue.com/en/2010/02/09/google-analytic-api-extract-data-php/">Extract data from google analytic with PHP</a></p>
<p><strong>Put it all together</strong></p>
<pre class="brush:html">&lt;html&gt;
&lt;head&gt;
&lt;style type="text/css"&gt;
#vGA{
	width: 100px;
	position: relative;
	font-size: 9px;
	font-family: Verdana, Verdana, Geneva, sans-serif;
	padding-bottom: 15px;
	background: url(poweredBy.gif) no-repeat bottom left;
}
#vGA div{
	text-align: right;
	border: 2px solid #4f6db0;
	color: #555;
	line-height: 15px;
}
#vGA #vGALabel{
	background: #4f6db0;
	text-align: center;
	color: white;
	float: right;
	padding: 0 0 0 2px;
	margin: 0 0 0 2px;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?
include_once('gaapi.class.php');
$ga=new gaApi('google username','password','ga:site id');
$allTimeSummery=$ga-&gt;getAllTimeSummery();
?&gt;
<div id="vGA">
<div>&lt;?= $allTimeSummery['ga:pageviews'] ?&gt;
       <span id="vGALabel">Views</span></div>
</div>

&lt;/body&gt;
&lt;/html&gt;</pre>
<div class="ref-wrapper" id="ref-related"><h5 class="box primary">Related Entries</h5><ul><li class="boxlist"><a href="http://blog.u-blue.com/en/2010/02/09/google-analytic-api-extract-data-php/" class="box accent" >Extract data from google analytic with PHP</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.u-blue.com/en/2010/02/10/visible-stat-with-google-analytics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Extract data from google analytic with PHP</title>
		<link>http://blog.u-blue.com/en/2010/02/09/google-analytic-api-extract-data-php/</link>
		<comments>http://blog.u-blue.com/en/2010/02/09/google-analytic-api-extract-data-php/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 20:30:41 +0000</pubDate>
		<dc:creator>nice</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[playground]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[google analytic]]></category>

		<guid isPermaLink="false">http://blog.u-blue.com/?p=189</guid>
		<description><![CDATA[My PHP class to extract data from Google Analytics API to show on your own website. Using: PHP cURL to connect to Google Analytics Data Extract API PHP DOMDocument to parse XML Google Graph API to show analytic data Screenshot: How to use? Download full source code here -&#62; GAAPI Construct and use the class Include ]]></description>
			<content:encoded><![CDATA[<p>My PHP class to extract data from Google Analytics API to show on your own website.<br />
Using:</p>
<ul>
<li>PHP</li>
<li>cURL to connect to Google Analytics Data Extract API</li>
<li>PHP DOMDocument to parse XML</li>
<li>Google Graph API to show analytic data</li>
</ul>
<p>Screenshot:</p>
<div id="attachment_190" class="wp-caption alignnone" style="width: 410px"><a href="http://blog.u-blue.com/wp-content/uploads/2010/02/Screen-shot-2010-02-10-at-2.52.53-AM.png"><img class="size-full wp-image-190 " title="Google Analytic Data Export API with PHP" src="http://blog.u-blue.com/wp-content/uploads/2010/02/Screen-shot-2010-02-10-at-2.52.53-AM.png" alt="" width="400" /></a><p class="wp-caption-text">Google Analytic Data Export API with PHP</p></div>
<p><span id="more-189"></span></p>
<p><strong>How to use?</strong></p>
<p><strong>Download full source code here -&gt; <a href="https://github.com/nblue/GA-API">GAAPI</a></strong></p>
<p><strong>Construct and use the class</strong><br />
Include class file and call to construct with params username, password and site id(from url in google analytic account &#8220;id=xxxxxxxx&#8221;)</p>
<pre class="brush:php">include_once('gaapi.class.php');
$ga=new gaApi('google username','google password','ga:site id');
//e.g. ('myname@gmail.com','myPassword','ga:1234567');</pre>
<p>Site ID in Google Analytic URL</p>
<div id="attachment_202" class="wp-caption alignnone" style="width: 460px"><a href="http://blog.u-blue.com/wp-content/uploads/2010/02/analyticd.jpg"><img class="size-full wp-image-202 " title="analyticd" src="http://blog.u-blue.com/wp-content/uploads/2010/02/analyticd.jpg" alt="" width="450" height="55" /></a><p class="wp-caption-text">Analytic ID</p></div>
<p><strong>Generate Report</strong><br />
This require knowledge of Dimension and Metric from <a href="http://code.google.com/intl/en/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html">Google Analytic Data Extract API</a>. Basically it is to combine between Dimensions and Metrics to generate reports through method genReport(array). For examples.</p>
<pre class="brush:php">$params = array ('metrics' 		=&gt; 'ga:visits',
				'dimensions'	=&gt; 'ga:source',
				'start-date' 	=&gt; '2010-01-01',
				'end-date' 		=&gt; '2010-02-09',
				'max-results' 	=&gt; '5',
				'filter'		=&gt; 'ga:source != (direct)',
				'sort'			=&gt; '-ga:visits');
$result=$ga-&gt;genReport($params);
print_r($result);</pre>
<p>The result will be collection of array like this.</p>
<pre class="brush:php">Array
(
    [0] =&gt; Array
        (
            [ga:source] =&gt; google
            [ga:visits] =&gt; 5029
        )
    [1] =&gt; Array
        (
            [ga:source] =&gt; xxxxxxx.com
            [ga:visits] =&gt; 162
        )
    [2] =&gt; Array
        (
            [ga:source] =&gt; search
            [ga:visits] =&gt; 49
        )
)</pre>
<p><strong>Also there&#8217;s some pre-made method of frequency use statistic in my class such as:</strong></p>
<pre class="brush:php">$now=date("Y-m-d");
$lastmonth=date('Y-m-d', strtotime('-30 days'));

//Summery: visitors, unique visit, pageview, time on site, new visits, bounce rates
$summery=$ga-&gt;getSummery($lastmonth,$now);

//All time summery: visitors, page views
$allTimeSummery=$ga-&gt;getAllTimeSummery();

//Last 10 days visitors (for graph)
$visits=$ga-&gt;getVisits($lastmonth,$now,10);

//Top 10 search engine keywords
$topKeywords=$ga-&gt;getTopKeyword($lastmonth,$now,10);

//Top 10 visitor countries
$topCountries=$ga-&gt;getTopCountry($lastmonth,$now,10);

//Top 10 page views
$topPages=$ga-&gt;getTopPage($lastmonth,$now,10);

//Top 10 referrer websites
$topReferrer=$ga-&gt;getTopReferrer($lastmonth,$now,10);

//Top 10 visitor browsers
$topBrowsers=$ga-&gt;getTopBrowser($lastmonth,$now,10);

//Top 10 visitor operating systems
$topOs=$ga-&gt;getTopOs($lastmonth,$now,10);</pre>
<p>Each method generate collection of array with dimension and metric name as key</p>
<p>Download the code here -&gt; <a href="https://github.com/nblue/GA-API">GAAPI</a></p>
<p>Please let me know if you find any bugs!</p>
<div class="ref-wrapper" id="ref-related"><h5 class="box primary">Related Entries</h5><ul><li class="boxlist"><a href="http://blog.u-blue.com/en/2010/02/10/visible-stat-with-google-analytics/" class="box accent" >Visible stat from Google Analytics</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.u-blue.com/en/2010/02/09/google-analytic-api-extract-data-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

