Example #1
0
$document = JFactory::getDocument();
$document->addScript((JBrowser::getInstance()->isSSLConnection() ? 'https' : 'http') . '://www.google.com/jsapi');
$document->addScript(JURI::root() . 'administrator/components/com_ganalytics/libraries/jquery/fancybox/jquery.easing-1.3.pack.js');
$document->addScript(JURI::root() . 'administrator/components/com_ganalytics/libraries/jquery/fancybox/jquery.mousewheel-3.0.4.pack.js');
$document->addScript(JURI::root() . 'administrator/components/com_ganalytics/libraries/jquery/fancybox/jquery.fancybox-1.3.4.pack.js');
$document->addStyleSheet(JURI::root() . 'administrator/components/com_ganalytics/libraries/jquery/fancybox/jquery.fancybox-1.3.4.css');
if (GAnalyticsHelper::isPROMode()) {
    $document->addScript(JURI::base() . 'administrator/components/com_ganalytics/libraries/jquery/ganalytics/chart.js');
} else {
    $document->addScript(JURI::base() . 'administrator/components/com_ganalytics/libraries/jquery/ganalytics/list.js');
}
$document->addStyleSheet(JURI::base() . 'components/com_ganalytics/views/ganalytics/tmpl/ganalytics.css');
$document->addScript(JURI::base() . 'components/com_ganalytics/views/ganalytics/tmpl/ganalytics.js');
$showDateSelection = $params->get('showDateSelection', 'yes') == 'yes';
$profile = $this->profile;
echo GAnalyticsHelper::render($this->titleFormat, array('accountname' => $profile->accountName, 'profilename' => $profile->profileName, 'username' => JFactory::getUser()->username));
if ($showDateSelection) {
    ?>
<table class="ganalytics-table">
	<tr>
		<td style="padding-right:20px">
		<?php 
    echo JText::_('COM_GANALYTICS_CHART_VIEW_SELECT_DATE_FROM');
    echo JHtml::_('calendar', $this->startDate->format('Y-m-d'), 'date_from', 'date_from', '%Y-%m-%d', array('size' => 10));
    ?>
		</td>
		<td style="padding-right:20px">
		<?php 
    echo JText::_('COM_GANALYTICS_CHART_VIEW_SELECT_DATE_TO');
    echo JHtml::_('calendar', $this->endDate->format('Y-m-d'), 'date_to', 'date_to', '%Y-%m-%d', array('size' => 10));
    ?>
Example #2
0
 public function getStatsData()
 {
     $params = $this->getState('params');
     $startDate = JFactory::getDate();
     $startDate->modify('-1 day');
     $endDate = JFactory::getDate();
     $endDate->modify('-1 day');
     if ($params->get('daterange', 'month') == 'advanced') {
         $tmp = $params->get('advancedDateRange', null);
         if (!empty($tmp)) {
             $startDate = JFactory::getDate(strtotime($tmp));
         } else {
             $tmp = $params->get('startdate', null);
             if (!empty($tmp)) {
                 $startDate = JFactory::getDate($tmp);
             }
             $tmp = $params->get('enddate', null);
             if (!empty($tmp)) {
                 $endDate = JFactory::getDate($tmp);
             }
         }
     } else {
         $range = '';
         switch ($params->get('daterange', 'month')) {
             case 'day':
                 $range = '-1 day';
                 break;
             case 'week':
                 $range = '-1 week';
                 break;
             case 'month':
                 $range = '-1 month';
                 break;
             case 'year':
                 $range = '-1 year';
                 break;
         }
         $startDate = JFactory::getDate(strtotime($range));
     }
     $dimensions = array();
     $metrics = array();
     $sort = array();
     if ($params->get('type', 'visitsbytraffic') == 'advanced') {
         $dimensions = $params->get('dimensions', array('ga:date'));
         $metrics = $params->get('metrics', array('ga:visits'));
         $sort = $params->get('sort', array());
     } else {
         switch ($params->get('type', 'visitsbytraffic')) {
             case 'visits':
                 $dimensions[] = 'ga:date';
                 $metrics[] = 'ga:visits';
                 $metrics[] = 'ga:newVisits';
                 $sort[] = 'ga:date';
                 break;
             case 'visitsbytraffic':
                 $dimensions[] = 'ga:source';
                 $metrics[] = 'ga:visits';
                 $metrics[] = 'ga:newVisits';
                 $sort[] = '-ga:visits';
                 break;
             case 'visitsbybrowser':
                 $dimensions[] = 'ga:browser';
                 $metrics[] = 'ga:visits';
                 $metrics[] = 'ga:newVisits';
                 $sort[] = '-ga:visits';
                 break;
             case 'visitsbycountry':
                 $dimensions[] = 'ga:country';
                 $metrics[] = 'ga:visits';
                 $sort[] = '-ga:visits';
                 break;
             case 'timeonsite':
                 $dimensions[] = 'ga:region';
                 $metrics[] = 'ga:timeOnSite';
                 $sort[] = '-ga:timeOnSite';
                 break;
             case 'toppages':
                 $dimensions[] = 'ga:pagePath';
                 $metrics[] = 'ga:pageviews';
                 $sort[] = '-ga:pageviews';
                 break;
         }
     }
     $max = $params->get('max', 1000);
     if (JRequest::getVar('type', null) == 'visitor') {
         $dimensions = array('ga:date');
         $metrics = array('ga:newVisits', 'ga:visits');
         $sort = array('ga:date');
         $max = 1000;
     }
     if (JRequest::getVar('start-date', null) != null) {
         $startDate = JFactory::getDate(JRequest::getVar('start-date', null));
         $startDate->setTime(0, 0);
     }
     if (JRequest::getVar('end-date', null) != null) {
         $endDate = JFactory::getDate(JRequest::getVar('end-date', null));
         $endDate->setTime(0, 0);
     }
     $filter = null;
     if ($params->get('filterType', '') == 'page') {
         $uri = JFactory::getURI();
         $filter = 'ga:pagePath==' . $uri->getPath() . '?' . $uri->getQuery();
     }
     if ($params->get('filterType', '') == 'advanced') {
         $filter = GAnalyticsHelper::render($params->get('filter', null), array('userId' => JFactory::getUser()->id, 'username' => strtolower(JFactory::getUser()->username)));
     }
     return GAnalyticsDataHelper::getData($this->getProfile(), $dimensions, $metrics, $startDate, $endDate, $sort, $filter, $max);
 }
        case 'timeonsite':
            $dimensions[] = 'ga:region';
            $metrics[] = 'ga:timeOnSite';
            $sort[] = '-ga:timeOnSite';
            break;
        case 'toppages':
            $dimensions[] = 'ga:pagePath';
            $metrics[] = 'ga:pageviews';
            $sort[] = '-ga:pageviews';
            break;
    }
}
$max = $params->get('max', 1000);
$dateFormat = $params->get('dateFormat', '%d.%m.%Y');
$dims = array();
foreach ($dimensions as $dim) {
    $dims[] = GAnalyticsHelper::translate($dim);
}
$metrs = array();
foreach ($metrics as $metr) {
    $metrs[] = GAnalyticsHelper::translate($metr);
}
$title = GAnalyticsHelper::render($params->get('titleFormat', '<p>Dimension: {{dimensions}} <br/> Metric: {{metrics}}</p>'), array('accountname' => $profile->accountName, 'profilename' => $profile->profileName, 'username' => JFactory::getUser()->username, 'dimensions' => implode(' | ', $dims), 'metrics' => implode(' | ', $metrs)));
$width = $params->get('width', '200px');
$height = $params->get('height', '200px');
$color = $params->get('color', null);
$mode = $params->get('mode', 'list');
if (!GAnalyticsHelper::isProMode()) {
    $mode = 'list';
}
require JModuleHelper::getLayoutPath('mod_ganalytics_stats', $mode);