Permalink
Browse files

Added google analytics test

  • Loading branch information...
1 parent b3bdcce commit c45ef0f213af85ccbbbd66b89fc56a446a550668 @Ephigenia Ephigenia committed Oct 14, 2010
View
@@ -108,6 +108,12 @@ number of results found.
* `geocode`
* `locale`
+## Google Analytics API
+
+This for now rather basic test exports pageViews or visits from google
+analytics data to franklin. Please see the `config.php.dist` file for an
+example.
+
# UPDATES/FEEDBACK
Franklin will be updated from time to time. Check the official [Franklin
View
@@ -79,6 +79,35 @@ $config = array(
),
),
array(
+ 'test' => 'GoogleAnalyticsAPI',
+ 'config' => array(
+ 'email' => 'email@host.de',
+ 'password' => 'password',
+ 'profile_id' => 1234567890, // get this code from GA
+ 'metric' => 'visits',
+ 'time' => '1 day',
+ ),
+ ),
+ array(
+ 'test' => 'GoogleAnalyticsAPI',
+ 'config' => array(
+ 'email' => 'email@host.de',
+ 'password' => 'password',
+ 'profile_id' => 1234567890, // get this code from GA
+ 'metric' => 'pageViews',
+ 'time' => '1 day',
+ ),
+ ),
+ array(
+ 'test' => 'TwitterSearchApiResultsCount',
+ 'config' => array(
+ 'name' => 'Twitter Mentions (1 day)',
+ 'q' => '@horrorblogorg',
+ 'interval' => '24 hours',
+ 'since' => '-1 days',
+ ),
+ ),
+ array(
'test' => 'TwitterFollowers',
'config' => array(
'username' => 'horrorblogorg',
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Franklin: <http://code.marceleichner.de/project/franklin>
+ * Copyright 2009+, Ephigenia M. Eichner, Kopernikusstr. 8, 10245 Berlin
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @copyright copyright 2007+, Ephigenia M. Eichner
+ * @link http://code.ephigenia.de/projects/franklin/
+ * @filesource
+ */
+
+class_exists('Test') or require dirname(__FILE__).'/Test.php';
+
+/**
+ * http://code.google.com/p/gapi-google-analytics-php-interface/
+ *
+ * @package Franklin
+ * @subpackage Franklin.Test
+ * @author Ephigenia // Marcel Eichner <love@ephigenia.de>
+ * @since 2009-10-13
+ */
+class GoogleAnalyticsAPITest extends Test
+{
+ public $time = '1 day';
+
+ public function run()
+ {
+ class_exists('gapi') or require dirname(__FILE__).'/../vendor/gapi/gapi.class.php';
+ $ga = new gapi($this->email, $this->password);
+ $ga->requestReportData($this->profile_id,
+ array('date'),
+ array($this->metric),
+ null,
+ null,
+ date('Y-m-d', strtotime('yesterday')),
+ date('Y-m-d', strtotime('-'.$this->time))
+ );
+ $methodName = 'get'.ucFirst($this->metric);
+ $this->result = $ga->$methodName();
+ return parent::afterConstruct();
+ }
+}
@@ -30,6 +30,6 @@ public function afterConstruct()
{
$this->url = 'http://www.twitter.com/'.urlencode($this->username);
$this->regexp = '@id="follower_count" class="stats_count numeric">([\d+.,]+)\s*</span>@i';
- return parent::afterConstruct();
+ return $this->result;
}
}
@@ -0,0 +1,14 @@
+<?php
+define('ga_email','youremail@email.com');
+define('ga_password','your password');
+
+require 'gapi.class.php';
+
+$ga = new gapi(ga_email,ga_password);
+
+$ga->requestAccountData();
+
+foreach($ga->getResults() as $result)
+{
+ echo $result . ' (' . $result->getProfileId() . ")<br />";
+}
@@ -0,0 +1,62 @@
+<?php
+define('ga_email','youremail@email.com');
+define('ga_password','your password');
+define('ga_profile_id','your profile id');
+
+require 'gapi.class.php';
+
+$ga = new gapi(ga_email,ga_password);
+
+/**
+ * Note: OR || operators are calculated first, before AND &&.
+ * There are no brackets () for precedence and no quotes are
+ * required around parameters.
+ *
+ * Do not use brackets () for precedence, these are only valid for
+ * use in regular expressions operators!
+ *
+ * The below filter represented in normal PHP logic would be:
+ * country == 'United States' && ( browser == 'Firefox || browser == 'Chrome')
+ */
+
+$filter = 'country == United States && browser == Firefox || browser == Chrome';
+
+$ga->requestReportData(ga_profile_id,array('browser','browserVersion'),array('pageviews','visits'),'-visits',$filter);
+?>
+<table>
+<tr>
+ <th>Browser &amp; Browser Version</th>
+ <th>Pageviews</th>
+ <th>Visits</th>
+</tr>
+<?php
+foreach($ga->getResults() as $result):
+?>
+<tr>
+ <td><?php echo $result ?></td>
+ <td><?php echo $result->getPageviews() ?></td>
+ <td><?php echo $result->getVisits() ?></td>
+</tr>
+<?php
+endforeach
+?>
+</table>
+
+<table>
+<tr>
+ <th>Total Results</th>
+ <td><?php echo $ga->getTotalResults() ?></td>
+</tr>
+<tr>
+ <th>Total Pageviews</th>
+ <td><?php echo $ga->getPageviews() ?>
+</tr>
+<tr>
+ <th>Total Visits</th>
+ <td><?php echo $ga->getVisits() ?></td>
+</tr>
+<tr>
+ <th>Results Updated</th>
+ <td><?php echo $ga->getUpdated() ?></td>
+</tr>
+</table>
@@ -0,0 +1,48 @@
+<?php
+define('ga_email','youremail@email.com');
+define('ga_password','your password');
+define('ga_profile_id','your profile id');
+
+require 'gapi.class.php';
+
+$ga = new gapi(ga_email,ga_password);
+
+$ga->requestReportData(ga_profile_id,array('browser','browserVersion'),array('pageviews','visits'));
+?>
+<table>
+<tr>
+ <th>Browser &amp; Browser Version</th>
+ <th>Pageviews</th>
+ <th>Visits</th>
+</tr>
+<?php
+foreach($ga->getResults() as $result):
+?>
+<tr>
+ <td><?php echo $result ?></td>
+ <td><?php echo $result->getPageviews() ?></td>
+ <td><?php echo $result->getVisits() ?></td>
+</tr>
+<?php
+endforeach
+?>
+</table>
+
+<table>
+<tr>
+ <th>Total Results</th>
+ <td><?php echo $ga->getTotalResults() ?></td>
+</tr>
+<tr>
+ <th>Total Pageviews</th>
+ <td><?php echo $ga->getPageviews() ?>
+</tr>
+<tr>
+ <th>Total Visits</th>
+ <td><?php echo $ga->getVisits() ?></td>
+</tr>
+<tr>
+ <th>Results Updated</th>
+ <td><?php echo $ga->getUpdated() ?></td>
+</tr>
+</table>
@@ -0,0 +1,11 @@
+<?php
+define('ga_email','youremail@email.com');
+define('ga_password','your password');
+
+require 'gapi.class.php';
+
+$ga = new gapi(ga_email,ga_password,isset($_SESSION['ga_auth_token'])?$_SESSION['ga_auth_token']:null);
+$_SESSION['ga_auth_token'] = $ga->getAuthToken();
+
+echo 'Token: ' . $_SESSION['ga_auth_token'];
+?>
Oops, something went wrong.

0 comments on commit c45ef0f

Please sign in to comment.