예제 #1
0
 public function initialize($para, $analytic)
 {
     $trackingID = Settings::getAnalyticTrackingID();
     $accountID = Settings::getAnalyticAccountID();
     // CSRF
     $csrf = new Hidden('csrf');
     $csrf->addValidator(new Identical(array('value' => $this->security->getSessionToken(), 'message' => t('CSRF validation failed'))));
     $this->add($csrf);
     $this->add(new Submit('save', ['name' => 'save', 'value' => 'Save Changes', 'class' => 'btn btn-sm btn-info']));
     $author = new Submit('author', ['name' => 'author', 'value' => 'Authorization', 'class' => 'btn btn-sm btn-info']);
     $author->setLabel("Authorization this feature with Google");
     $this->add($author);
     $unauthor = new Submit('unauthor', ['name' => 'unauthor', 'value' => 'Clear Authorization', 'class' => 'btn btn-sm btn-warning']);
     $unauthor->setLabel("This feature had been actived. Clear authorization ?");
     $this->add($unauthor);
     $accessCode = new Text('accessCode', ['placeholder' => t('Access Code'), 'class' => 'form-control', 'value' => '']);
     $accessCode->setLabel('Access Code');
     $this->add($accessCode);
     $listView = $analytic->getListView();
     $listViewDisplay = [];
     if ($listView['state']) {
         foreach ($listView['listView'] as $view) {
             $parse = parse_url($view['profileURL']);
             $listViewDisplay[$view['webPropertyId'] . "_._" . $view['accountID']] = $parse['host'] . " => " . $view['profileName'];
         }
     }
     $selectView = new Select("selectView", $listViewDisplay, ['class' => 'form-control', 'useEmpty' => true, 'emptyText' => 'Please, choose one...']);
     $selectView->setLabel('Select View ');
     $selectView->setDefault($trackingID . "_._" . $accountID);
     $this->add($selectView);
     $data = Settings::getListTopActivity();
     $listTopActivity = [];
     $listDefaultActivity = [];
     foreach ($data as $activity) {
         $listTopActivity[$activity->code] = $activity->name;
         if ($activity->default == 1) {
             $listDefaultActivity[] = $activity->code;
         }
     }
     $topActivity = new Select("topActivity", $listTopActivity, ['name' => 'topActivity[]', 'class' => 'form-control', 'multiple' => 'multiple']);
     $topActivity->setLabel('Select 4 activity on top of dashboard');
     $topActivity->setDefault($listDefaultActivity);
     $this->add($topActivity);
 }
예제 #2
0
 /**
  * Get google Analytic data from google.
  * If we use google batch, each query to get data will move to batch queue
  * @param  array/string $listGA google dimensions
  * @param  datetime $from   start time to get analytic data
  * @param  datetime $to     end time to get analytic data
  * @param  string $prefix [for batch]. separate different query
  * @return [mixed]
  */
 public function getAnalyticData($listGA, $from, $to, $prefix)
 {
     $profileID = Settings::getAnalyticProfileID();
     if ($profileID) {
         $accountID = Settings::getAnalyticAccountID();
         $service = new \Google_Service_Analytics($this->client);
         if (is_array($listGA)) {
             $metrics = implode(',', $listGA);
         } else {
             $metrics = $listGA;
         }
         if ($this->useBatch) {
             $data = $service->data_ga->get('ga:' . $profileID, $from, $to, $metrics);
             $this->batch->add($data, $metrics . $prefix);
             return true;
         } else {
             $data = $service->data_ga->get('ga:' . $profileID, $from, $to, $metrics);
             return $data['rows'][0];
         }
     }
     return false;
 }
예제 #3
0
 /**
  * Render form setting google GoogleAnalytic
  *
  * @return mixed
  */
 public function analyticAction()
 {
     $analytic = new Analytic();
     $this->view->isLogged = false;
     // We check if user authorization
     if ($analytic->checkAccessToken()) {
         $this->view->isLogged = true;
     }
     $this->assets->addCss('assets/css/bootstrap-multiselect.css');
     $this->assets->addJs('assets/js/bootstrap-multiselect.js');
     $trackingID = Settings::getAnalyticTrackingID();
     $accountID = Settings::getAnalyticAccountID();
     $this->view->isConfigured = false;
     if ($accountID) {
         $profile = $analytic->getViewInfo($accountID, $trackingID);
         if ($profile['state']) {
             $this->view->isConfigured = true;
             $this->view->profile = $profile['profile'];
         } else {
             $this->flashSession->warning(t("We can't configure your analytic profile"));
         }
     }
     $this->tag->setTitle(t('Google Analytic Settings'));
     $this->view->form = new GoogleAnalyticForm(null, $analytic);
 }