Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ARNHOE/master
SS3 fixes & language added
- Loading branch information
Showing
8 changed files
with
220 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
<?php | ||
|
||
/** | ||
* @package googleanalytics | ||
*/ | ||
class GoogleAnalyzer extends DataExtension { | ||
|
||
static public $sapphire_version; | ||
|
||
// credentials for the Google Analytics API | ||
public static $profile_id; | ||
public static $email; | ||
public static $password; | ||
|
||
static $has_many = array( | ||
'Events' => 'GoogleLogEvent', | ||
); | ||
|
||
/** | ||
* for legacy reasons | ||
* @return String, version number, e.g. 2.4 or 2.3.6 | ||
*/ | ||
public static function get_sapphire_version() { | ||
if(self::$sapphire_version) return self::$sapphire_version; | ||
return method_exists('SiteTree', 'nested_urls') ? '2.4' : '2.3'; | ||
} | ||
|
||
/** | ||
* Activate the GoogleAnalyzer | ||
* | ||
* @param $profile String: | ||
* the Google Analytics profile ID or | ||
* 'SiteConfig' for using the SiteConfig to configure this value | ||
* @param $email String email address of the account to use (can be left blank if configured with SiteConfig) | ||
* @param $password String password for the above account (can be left blank if configured with SiteConfig) | ||
**/ | ||
public static function activate($profile = 'SiteConfig', $email = null, $password = null) { | ||
switch($profile) { | ||
case 'SiteConfig': Object::add_extension('SiteConfig', 'GoogleConfig'); break; | ||
default: | ||
self::$profile_id = $profile; | ||
self::$email = $email; | ||
self::$password = $password; | ||
} | ||
|
||
Object::add_extension('SiteTree', 'GoogleAnalyzer'); | ||
} | ||
|
||
public function updateCMSFields(FieldList $fields) { | ||
$fields->addFieldToTab('Root', new Tab('GoogleAnalytics', 'Google Analytics')); | ||
$fields->addFieldToTab("Root.GoogleAnalytics", new TabSet('Stats')); | ||
$fields->addFieldToTab('Root.GoogleAnalytics.Stats', new Tab('Performance', 'Performance')); | ||
$fields->addFieldToTab("Root.GoogleAnalytics.Stats.Performance", new GooglePerformanceChart($this->owner)); | ||
} | ||
<?php | ||
|
||
/** | ||
* @package googleanalytics | ||
*/ | ||
class GoogleAnalyzer extends DataExtension { | ||
|
||
static public $sapphire_version; | ||
|
||
// credentials for the Google Analytics API | ||
public static $profile_id; | ||
public static $email; | ||
public static $password; | ||
|
||
static $has_many = array( | ||
'Events' => 'GoogleLogEvent', | ||
); | ||
|
||
/** | ||
* for legacy reasons | ||
* @return String, version number, e.g. 2.4 or 2.3.6 | ||
*/ | ||
public static function get_sapphire_version() { | ||
if(self::$sapphire_version) return self::$sapphire_version; | ||
return method_exists('SiteTree', 'nested_urls') ? '2.4' : '2.3'; | ||
} | ||
|
||
/** | ||
* Activate the GoogleAnalyzer | ||
* | ||
* @param $profile String: | ||
* the Google Analytics profile ID or | ||
* 'SiteConfig' for using the SiteConfig to configure this value | ||
* @param $email String email address of the account to use (can be left blank if configured with SiteConfig) | ||
* @param $password String password for the above account (can be left blank if configured with SiteConfig) | ||
**/ | ||
public static function activate($profile = 'SiteConfig', $email = null, $password = null) { | ||
|
||
switch($profile) { | ||
case 'SiteConfig': Object::add_extension('SiteConfig', 'GoogleConfig'); break; | ||
default: | ||
self::$profile_id = $profile; | ||
self::$email = $email; | ||
self::$password = $password; | ||
} | ||
|
||
Object::add_extension('SiteTree', 'GoogleAnalyzer'); | ||
} | ||
|
||
public function updateCMSFields(FieldList $fields) { | ||
$fields->addFieldToTab('Root', Tab::create("GoogleAnalytics", _t('GoogleAnalyzer.TABTITLE',"Google Analytics"))); | ||
$fields->addFieldToTab("Root.GoogleAnalytics", TabSet::create("Stats", _t('GoogleAnalyzer.STATS',"Stats"))); | ||
$fields->addFieldToTab('Root.GoogleAnalytics.Stats', Tab::create("Performance", _t('GoogleAnalyzer.PERFORMANCE',"Performance"))); | ||
$fields->addFieldToTab("Root.GoogleAnalytics.Stats.Performance", new GooglePerformanceChart($this->owner)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* @package googleanalytics | ||
*/ | ||
class GoogleConfig extends DataExtension { | ||
|
||
static $db = array( | ||
'GoogleAnalyticsCode' => 'Varchar', | ||
'GoogleAnalyticsProfileId' => 'Varchar', | ||
'GoogleAnalyticsEmail' => 'Varchar', | ||
'GoogleAnalyticsPassword' => 'Varchar', | ||
); | ||
|
||
public function updateCMSFields(FieldList $fields) { | ||
|
||
$fields->addFieldToTab("Root", new Tab('GoogleAnalytics')); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', new TextField('GoogleAnalyticsCode', 'Google Analytics Code (UA-XXXXXX-X)')); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', new TextField('GoogleAnalyticsProfileId', 'Google Analytics Profile ID (hidden in the URL parameter "id" of the "View Report" link inside Google Analytics)')); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', new TextField('GoogleAnalyticsEmail', 'GoogleAnalyticsEmail (the email address of the Google Analytics account to use)')); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', new PasswordField('GoogleAnalyticsPassword', 'Google Analytics Password (the password for the above account)')); | ||
} | ||
|
||
/** | ||
* Return various configuration values | ||
* | ||
* @param $key String: | ||
* 'profile' the Google Analytics profile id or | ||
* 'email' the Google Analytics account's email address or | ||
* 'password' the password for the above Google Analytics account | ||
* @return String the config value | ||
**/ | ||
public static function get_google_config($key) { | ||
if(class_exists('SiteConfig') && Object::has_extension('SiteConfig', 'GoogleConfig')) { | ||
$config = SiteConfig::current_site_config(); | ||
} | ||
switch($key) { | ||
case 'code': return !empty($config) && $config->GoogleAnalyticsCode ? $config->GoogleAnalyticsCode : GoogleLogger::$google_analytics_code; | ||
case 'profile': return !empty($config) && $config->GoogleAnalyticsProfileId ? $config->GoogleAnalyticsProfileId : GoogleAnalyzer::$profile_id; | ||
case 'email': return !empty($config) && $config->GoogleAnalyticsEmail ? $config->GoogleAnalyticsEmail : GoogleAnalyzer::$email; | ||
case 'password': return !empty($config) && $config->GoogleAnalyticsPassword ? $config->GoogleAnalyticsPassword : GoogleAnalyzer::$password; | ||
} | ||
} | ||
<?php | ||
|
||
/** | ||
* @package googleanalytics | ||
*/ | ||
class GoogleConfig extends DataExtension { | ||
|
||
static $db = array( | ||
'GoogleAnalyticsCode' => 'Varchar', | ||
'GoogleAnalyticsProfileId' => 'Varchar(255)', | ||
'GoogleAnalyticsEmail' => 'Varchar', | ||
'GoogleAnalyticsPassword' => 'Varchar', | ||
); | ||
|
||
public function updateCMSFields(FieldList $fields) { | ||
|
||
$fields->addFieldToTab("Root", new Tab('GoogleAnalytics')); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', TextField::create("GoogleAnalyticsCode")->setTitle(_t('GoogleConfig.CODE',"Google Analytics Code"))->setRightTitle("(UA-XXXXXX-X)")); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', TextField::create("GoogleAnalyticsProfileId")->setTitle(_t('GoogleConfig.PROFILEID',"Google Analytics Profile ID"))->setRightTitle(_t('GoogleConfig.PROFILEIDEXPLANATION','Hidden in the URL parameter "id" of the "View Report" link inside Google Analytics'))); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', TextField::create("GoogleAnalyticsEmail")->setTitle(_t('GoogleConfig.EMAIL',"Google Analytics Email"))->setRightTitle(_t('GoogleConfig.EMAILEXPLANATION',"The email address of the Google Analytics account to use"))); | ||
$fields->addFieldToTab('Root.GoogleAnalytics', PasswordField::create("GoogleAnalyticsPassword")->setTitle(_t('GoogleConfig.PASSWORD',"Google Analytics Password"))->setRightTitle(_t('GoogleConfig.PASSWORDEXPLANATION',"The password for the above account"))); | ||
} | ||
|
||
/** | ||
* Return various configuration values | ||
* | ||
* @param $key String: | ||
* 'profile' the Google Analytics profile id or | ||
* 'email' the Google Analytics account's email address or | ||
* 'password' the password for the above Google Analytics account | ||
* @return String the config value | ||
**/ | ||
public static function get_google_config($key) { | ||
if(class_exists('SiteConfig') && Object::has_extension('SiteConfig', 'GoogleConfig')) { | ||
$config = SiteConfig::current_site_config(); | ||
} | ||
switch($key) { | ||
case 'code': return !empty($config) && $config->GoogleAnalyticsCode ? $config->GoogleAnalyticsCode : GoogleLogger::$google_analytics_code; | ||
case 'profile': return !empty($config) && $config->GoogleAnalyticsProfileId ? $config->GoogleAnalyticsProfileId : GoogleAnalyzer::$profile_id; | ||
case 'email': return !empty($config) && $config->GoogleAnalyticsEmail ? $config->GoogleAnalyticsEmail : GoogleAnalyzer::$email; | ||
case 'password': return !empty($config) && $config->GoogleAnalyticsPassword ? $config->GoogleAnalyticsPassword : GoogleAnalyzer::$password; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
<?php | ||
|
||
class GoogleDataController extends Controller { | ||
|
||
function performance($request) { | ||
$markers = array(); | ||
|
||
$q = substr(GoogleAnalyzer::get_sapphire_version(), 0, 3) == '2.3' ? '`' : '"'; | ||
|
||
$metrics = $request->requestVar('metrics'); | ||
|
||
$filters = null; | ||
$eventfiltersql = "{$q}GoogleLogEvent{$q}.{$q}PageID{$q} = 0"; | ||
$page = DataObject::get_by_id('SiteTree', (int)$request->param('ID')); | ||
if($page) { | ||
$url = trim($page->Link(), '/'); | ||
if(!empty($url)) $url .= '/'; | ||
$filters = 'ga:pagePath==/' . $url; | ||
$eventfiltersql .= " OR {$q}GoogleLogEvent{$q}.{$q}PageID{$q} = " . (int)$page->ID; | ||
$allversions = $q == '"' ? | ||
'"WasPublished" = 1 AND ' . DB::getConn()->datetimeDifferenceClause('"LastEdited"', date('Y-m-d 23:59:59', strtotime('-1 Year'))) . ' > 0' : | ||
"{$q}WasPublished{$q} = 1 AND {$q}LastEdited{$q} > '" . date('Y-m-d 23:59:59', strtotime('-1 Year')) . "'"; | ||
foreach($page->allVersions() as $version) { | ||
$markers[] = array(strtotime($version->LastEdited) * 1000, 'Updated', 'Long descr.'); | ||
} | ||
} | ||
$events = DataObject::get('GoogleLogEvent', $eventfiltersql); | ||
if($events) foreach($events as $event) $markers[] = array(strtotime($event->Created) * 1000, $event->Title, 'Long descr.'); | ||
|
||
$store = new GoogleDataStore(GoogleConfig::get_google_config('profile'), GoogleConfig::get_google_config('email'), GoogleConfig::get_google_config('password')); | ||
$data = $store->fetchPerformance(array( | ||
'dimensions' => 'ga:date', | ||
'metrics' => 'ga:visits,ga:pageviews', | ||
'sort' => '-ga:date', | ||
'filters' => $filters, | ||
)); | ||
|
||
return json_encode(array('series' => $data, 'markers' => $markers)); | ||
} | ||
|
||
<?php | ||
|
||
class GoogleDataController extends Controller { | ||
|
||
function performance($request) { | ||
|
||
$markers = array(); | ||
|
||
$q = substr(GoogleAnalyzer::get_sapphire_version(), 0, 3) == '2.3' ? '`' : '"'; | ||
|
||
$metrics = $request->requestVar('metrics'); | ||
|
||
$filters = null; | ||
$eventfiltersql = "{$q}GoogleLogEvent{$q}.{$q}PageID{$q} = 0"; | ||
$page = SiteTree::get()->byID((int)$request->param('ID')); | ||
if($page) { | ||
$url = trim($page->Link(), '/'); | ||
if(!empty($url)) $url .= '/'; | ||
$filters = 'ga:pagePath==/' . $url; | ||
$eventfiltersql .= " OR {$q}GoogleLogEvent{$q}.{$q}PageID{$q} = " . (int)$page->ID; | ||
$allversions = $q == '"' ? | ||
'"WasPublished" = 1 AND ' . DB::getConn()->datetimeDifferenceClause('"LastEdited"', date('Y-m-d 23:59:59', strtotime('-1 Year'))) . ' > 0' : | ||
"{$q}WasPublished{$q} = 1 AND {$q}LastEdited{$q} > '" . date('Y-m-d 23:59:59', strtotime('-1 Year')) . "'"; | ||
foreach($page->allVersions() as $version) { | ||
$markers[] = array(strtotime($version->LastEdited) * 1000, 'Updated', 'Long descr.'); | ||
} | ||
} | ||
|
||
$events = DataObject::get('GoogleLogEvent', $eventfiltersql); | ||
if($events) foreach($events as $event) $markers[] = array(strtotime($event->Created) * 1000, $event->Title, 'Long descr.'); | ||
|
||
$store = new GoogleDataStore(GoogleConfig::get_google_config('profile'), GoogleConfig::get_google_config('email'), GoogleConfig::get_google_config('password')); | ||
|
||
|
||
$data = $store->fetchPerformance(array( | ||
'dimensions' => 'ga:date', | ||
'metrics' => 'ga:visits,ga:pageviews', | ||
'sort' => '-ga:date', | ||
'filters' => $filters, | ||
)); | ||
|
||
return json_encode(array('series' => $data, 'markers' => $markers)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
<?php | ||
|
||
class GooglePerformanceChart extends Compositefield { | ||
|
||
protected $page; | ||
|
||
function __construct($page = null) { | ||
parent::__construct(); | ||
switch(true) { | ||
case $page instanceof SiteTree: $this->page = $page; break; | ||
case is_numeric($page): $page = DataObject::get_by_id('SiteTree', (int)$page); break; | ||
} | ||
} | ||
|
||
function FieldHolder($properties = array()) { | ||
return $this->renderWith('GooglePerformanceChart'); | ||
} | ||
function PageID() { | ||
if($this->page) return $this->page->ID; | ||
} | ||
<?php | ||
|
||
class GooglePerformanceChart extends Compositefield { | ||
|
||
protected $page; | ||
|
||
function __construct($page = null) { | ||
parent::__construct(); | ||
switch(true) { | ||
case $page instanceof SiteTree: $this->page = $page; break; | ||
case is_numeric($page): $page = SiteTree::get()->byID((int)$page); break; | ||
} | ||
} | ||
|
||
function FieldHolder($properties = array()) { | ||
return $this->renderWith('GooglePerformanceChart'); | ||
} | ||
|
||
function PageID() { | ||
if($this->page) return $this->page->ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
<?php | ||
|
||
class GoogleReport extends SS_Report { | ||
|
||
function title() { | ||
return "Google Analytics"; | ||
} | ||
|
||
function description() { | ||
return "add description"; | ||
} | ||
|
||
function getCMSFields() { | ||
$fields = new FieldSet(); | ||
|
||
$chart = new GooglePerformanceChart(); | ||
|
||
$fields->push(new LiteralField('ReportTitle', "<h3>{$this->title()}</h3>")); | ||
$fields->push(new LiteralField('ReportDescription', $chart->renderWith('GooglePerformanceChart'))); | ||
|
||
return $fields; | ||
} | ||
<?php | ||
|
||
class GoogleReport extends SS_Report { | ||
|
||
function description() { | ||
return "add description"; | ||
} | ||
|
||
function getCMSFields() { | ||
$fields = new FieldList(); | ||
|
||
$chart = new GooglePerformanceChart(); | ||
|
||
$fields->push(new LiteralField('ReportTitle', "<h3>{" . _t('GoogleReport.REPORTTITLE',"Google Analytics") ."}</h3>")); | ||
$fields->push(new LiteralField('ReportDescription', $chart->renderWith('GooglePerformanceChart'))); | ||
|
||
return $fields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
en: | ||
GoogleConfig: | ||
CODE: 'Google Analytics Code' | ||
PROFILEID: 'Google Analytics Profile ID' | ||
PROFILEIDEXPLANATION: 'Hidden in the URL parameter "id" of the "View Report" link inside Google Analytics' | ||
EMAIL: 'Google Analytics Email' | ||
EMAILEXPLANATION: 'The email address of the Google Analytics account to use' | ||
PASSWORD: 'Google Analytics Password' | ||
PASSWORDEXPLANATION: 'Password of the Google Analytics account' | ||
GoogleAnalyzer: | ||
TABTITLE: 'Google Analytics' | ||
STATS: 'Stats' | ||
PERFORMANCE: 'Performance' | ||
GoogleReport: | ||
REPORTTITLE: 'Google Analytics' |
Oops, something went wrong.