Exemple #1
0
 public static function getStatsWidgetEnd($setting, $cacheKey, $uri = '')
 {
     if (!$uri) {
         $uri = $_SERVER['REQUEST_URI'];
     }
     $results = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getResults($cacheKey);
     $value = intval(@$results['rows'][0][0]);
     set_transient('ba_stats_' . md5(@$setting['metric'] . '-' . @$setting['days'] . '-' . (@$setting['this_page_only'] ? $uri : '')), $value, 21600);
     return $value;
 }
Exemple #2
0
 /**
  * Renders the profile list.
  *
  * @param XenForo_View $view View object
  * @param string $fieldPrefix Prefix for the HTML form field name
  * @param array $preparedOption Prepared option info
  * @param boolean $canEdit True if an "edit" link should appear
  *
  * @return XenForo_Template_Abstract Template object
  */
 public static function renderOption(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
 {
     $preparedOption['extraChoices'] = array();
     if (DigitalPointBetterAnalytics_Helper_Reporting::checkAccessToken(false)) {
         $profiles = DigitalPointBetterAnalytics_Helper_Reporting::getProfiles();
     } else {
         $profiles = array();
     }
     $preparedOption['formatParams'] = self::groupProfiles(@$profiles['items']);
     return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal('option_list_option_select', $view, $fieldPrefix, $preparedOption, $canEdit);
 }
Exemple #3
0
 public static function getSiteAccountId()
 {
     $betterAnalyticsOptions = get_option('better_analytics');
     $profiles = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getProfiles();
     $accountId = null;
     if (!empty($profiles['items'])) {
         foreach ($profiles['items'] as $profile) {
             if ($profile['webPropertyId'] == $betterAnalyticsOptions['property_id']) {
                 $accountId = $profile['accountId'];
             }
         }
     }
     return $accountId;
 }
Exemple #4
0
 public static function hour($all = false)
 {
     DigitalPointBetterAnalytics_Model_Widget::getStatsWidgetData();
     if (get_transient('ba_exp_live') || date('G', current_time('timestamp')) == 0) {
         $betterAnalyticsOptions = get_option('better_analytics');
         if ($profile = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getProfileByProfileId($betterAnalyticsOptions['api']['profile'])) {
             DigitalPointBetterAnalytics_Model_Experiments::getAllExperiments($profile['accountId'], $profile['webPropertyId'], $profile['id']);
         }
     }
     // This really should be a core WordPress function (deleting expired transients), but w/e...
     global $wpdb;
     if (!$all) {
         $time = time();
     } else {
         $time = time() + 86400 * 365;
     }
     $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n                WHERE a.option_name LIKE %s\n                AND a.option_name NOT LIKE %s\n                AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n                AND b.option_value < %d";
     $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_ba_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', $time));
 }
Exemple #5
0
 public function api_authentication()
 {
     if (!empty($_REQUEST['code'])) {
         $code = $_REQUEST['code'];
         $response = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->exchangeCodeForToken($code);
         if (!empty($response->error) && !empty($response->error_description)) {
             echo sprintf('%1$s<br /><br /><b>%2$s</b>: %3$s', esc_html__('Invalid Google API Code:', 'better-analytics'), $response->error, $response->error_description);
             return;
         }
         if (empty($response->expires_in)) {
             echo sprintf('%1$s:<br /><br />%2$s', esc_html__('Unknown Google API Error:', 'better-analytics'), nl2br(var_export($response, true)));
             return;
         }
         $response->expires_at = time() + $response->expires_in - 100;
         unset($response->expires_in);
         DigitalPointBetterAnalytics_Base_Public::getInstance()->updateTokens($response, is_network_admin());
         DigitalPointBetterAnalytics_CronEntry_Jobs::hour(true);
         // Checks for access
         $reportingClass = DigitalPointBetterAnalytics_Helper_Reporting::getInstance();
         $reportingClass->deleteProfileCache();
         $reportingClass->getProfiles();
         if (is_network_admin()) {
             wp_redirect(self_admin_url('settings.php'), 302);
         } else {
             wp_redirect(menu_page_url('better-analytics', false) . '#top#api', 302);
         }
         return;
     }
     $url = menu_page_url('better-analytics_auth', false);
     // Hacky fix for WordPress bug:  https://core.trac.wordpress.org/ticket/28226
     if (strpos($url, 'wp-admin/settings.php')) {
         $url = str_replace('wp-admin/settings.php', 'wp-admin/network/settings.php', $url);
     }
     wp_redirect(DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getAuthenticationUrl($url, true), 302);
 }
Exemple #6
0
 public function getResults($cacheKey)
 {
     if (self::canUseCurlMulti() && self::$_curlMultiHandle && count(self::$_curlHandles) > 0) {
         do {
             while (($execrun = curl_multi_exec(self::$_curlMultiHandle, $running)) == CURLM_CALL_MULTI_PERFORM) {
             }
             if ($execrun != CURLM_OK) {
                 break;
             }
             while ($done = curl_multi_info_read(self::$_curlMultiHandle)) {
                 $results = json_decode(curl_multi_getcontent($done['handle']), true);
                 $cacheKeyForReturn = array_search($done['handle'], self::$_curlHandles, true);
                 $this->_cacheSave($cacheKeyForReturn, $results, 60);
                 curl_multi_remove_handle(self::$_curlMultiHandle, $done['handle']);
             }
         } while ($running);
         curl_multi_close(self::$_curlMultiHandle);
         self::$_curlMultiHandle = null;
     } elseif (!self::canUseCurlMulti()) {
         $results = @json_decode(self::$_curlHandles[$cacheKey]->getBody(), true);
         $this->_cacheSave($cacheKey, $results, 60);
     }
     if (!empty(self::$_cachedResults[$cacheKey])) {
         return self::$_cachedResults[$cacheKey];
     } else {
         return false;
     }
 }
Exemple #7
0
?>



			<tr valign="top" class="group_api tab_content">
				<th scope="row"></th>
				<td>

					<?php 
if (get_site_option('ba_site_tokens') && get_site_option('ba_site_tokens') != get_option('ba_tokens')) {
    $multisiteMode = true;
    esc_html_e('Multisite Mode: Analytics account linked at network level');
} else {
    $multisiteMode = false;
    if (!get_option('ba_tokens')) {
        echo DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getCreateAccountMessage() . '<br /><br />';
    }
    ?>

					<a id="ba_select_profile" class="button" href="<?php 
    menu_page_url('better-analytics_auth');
    ?>
"><?php 
    get_option('ba_tokens') ? esc_html_e('Link/Authenticate A Different Google Analytics Account', 'better-analytics') : esc_html_e('Link/Authenticate Your Google Analytics Account', 'better-analytics');
    ?>
</a>
					<?php 
}
?>
				</td>
			</tr>
Exemple #8
0
 public function actionTestSetup()
 {
     $checks['hasCache'] = XenForo_Application::getCache() ? true : false;
     if (DigitalPointBetterAnalytics_Helper_Reporting::checkAccessToken(false)) {
         $checks['profiles'] = DigitalPointBetterAnalytics_Helper_Reporting::getProfiles();
         $checks['matchingProfile'] = DigitalPointBetterAnalytics_Helper_Reporting::getProfileByPropertyId(XenForo_Application::getOptions()->googleAnalyticsWebPropertyId);
         $checks['siteSearchSetup'] = @$checks['matchingProfile']['siteSearchQueryParameters'] == 'q';
         $checks['ecommerceTracking'] = @$checks['matchingProfile']['eCommerceTracking'];
         $checks['enhancedEcommerceTracking'] = @$checks['matchingProfile']['enhancedECommerceTracking'];
         $property = DigitalPointBetterAnalytics_Helper_Reporting::getPropertyByPropertyId(@$checks['matchingProfile']['accountId'], XenForo_Application::getOptions()->googleAnalyticsWebPropertyId);
         $checks['level'] = @$property['level'];
         $checks['industryVertical'] = @$property['industryVertical'];
         $checks['dimensions'] = DigitalPointBetterAnalytics_Helper_Reporting::getDimensionsByPropertyId(@$checks['matchingProfile']['accountId'], XenForo_Application::getOptions()->googleAnalyticsWebPropertyId, array('User', 'Forum'));
     }
     $checks['licensed'] = DigitalPointBetterAnalytics_Helper_Api::check(true);
     $checks['user_dimension_set'] = XenForo_Application::getOptions()->dpBetterAnalyticsDimensionIndexUser > 0 && @$checks['dimensions']['User']['index'] == XenForo_Application::getOptions()->dpBetterAnalyticsDimensionIndexUser;
     $checks['forum_dimension_set'] = XenForo_Application::getOptions()->dpBetterAnalyticsDimentionIndex > 0 && @$checks['dimensions']['Forum']['index'] == XenForo_Application::getOptions()->dpBetterAnalyticsDimentionIndex;
     $checks['hasCurl'] = function_exists('curl_multi_init');
     return $this->responseView('DigitalPointBetterAnalytics_ViewAdmin_Tools_CheckAnalytics', 'tools_test_analytics', array('checks' => $checks));
 }
Exemple #9
0
 public function actionExperiments()
 {
     if (!$this->_assertLinkedAccount()) {
         return;
     }
     if (isset($_REQUEST['action2']) && $_REQUEST['action2'] != -1) {
         $_REQUEST['action'] = $_REQUEST['action2'];
     }
     $betterAnalyticsOptions = get_option('better_analytics');
     $reportingClass = DigitalPointBetterAnalytics_Helper_Reporting::getInstance();
     if (@$_REQUEST['action'] == 'start-selected' || @$_REQUEST['action'] == 'end-selected' || @$_REQUEST['action'] == 'delete-selected') {
         if (!empty($_REQUEST['checked']) && is_array($_REQUEST['checked'])) {
             $checkIds = array();
             foreach ($_REQUEST['checked'] as $check) {
                 if ($id = sanitize_text_field($check)) {
                     $checkIds[] = $id;
                 }
             }
             if ($checkIds) {
                 check_admin_referer('bulk-experiments');
                 if ($profile = $reportingClass->getProfileByProfileId($betterAnalyticsOptions['api']['profile'])) {
                     foreach ($checkIds as $id) {
                         if ($_REQUEST['action'] == 'delete-selected') {
                             $reportingClass->deleteExperiment($profile['accountId'], $profile['webPropertyId'], $profile['id'], $id);
                         } else {
                             $experiment = $reportingClass->patchExperiment($profile['accountId'], $profile['webPropertyId'], $profile['id'], $id, array('status' => $_REQUEST['action'] == 'start-selected' ? 'RUNNING' : 'ENDED'));
                         }
                         $reportingClass->deleteExperimentCache($profile['accountId'], $profile['webPropertyId'], $profile['id'], $id);
                     }
                     $reportingClass->deleteExperimentCache($profile['accountId'], $profile['webPropertyId'], $profile['id']);
                 }
             }
         }
     }
     $this->_view('experiments');
 }
Exemple #10
0
         $goalObject['eventDetails']['eventConditions'][] = array('type' => 'CATEGORY', 'matchType' => $_POST['event_category'], 'expression' => $_POST['event_category_value']);
     }
     if (!empty($_POST['event_action_value'])) {
         $goalObject['eventDetails']['eventConditions'][] = array('type' => 'ACTION', 'matchType' => $_POST['event_action'], 'expression' => $_POST['event_action_value']);
     }
     if (!empty($_POST['event_label_value'])) {
         $goalObject['eventDetails']['eventConditions'][] = array('type' => 'LABEL', 'matchType' => $_POST['event_label'], 'expression' => $_POST['event_label_value']);
     }
     if (!empty($_POST['event_value_value'])) {
         $goalObject['eventDetails']['eventConditions'][] = array('type' => 'VALUE', 'comparisonType' => $_POST['event_value'], 'comparisonValue' => $_POST['event_value_value']);
     }
     if (count($goalObject['eventDetails']['eventConditions']) == 0) {
         $errorMessage[] = esc_html__('You must specify a Category, Action or Label.', 'better-analytics');
     }
 }
 $reportingClass = DigitalPointBetterAnalytics_Helper_Reporting::getInstance();
 if (!$errorMessage && ($profile = $reportingClass->getProfileByProfileId(@$betterAnalyticsOptions['api']['profile']))) {
     if ($goalId) {
         $goal = $reportingClass->patchGoal($profile['accountId'], $profile['webPropertyId'], $profile['id'], $goalId, $goalObject);
     } else {
         $goal = $reportingClass->insertGoal($profile['accountId'], $profile['webPropertyId'], $profile['id'], $goalObject);
     }
     $reportingClass->deleteGoalCache();
     $goals = $reportingClass->getGoals();
     $goals = DigitalPointBetterAnalytics_Model_Reporting::filterGoalsByProfile($goals, @$betterAnalyticsOptions['property_id'], @$betterAnalyticsOptions['api']['profile'], $totals);
     if ($goalId) {
         /* translators: %1$s = <strong>, %2$s = </strong> */
         $noticeAtTop = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf(esc_html__('Goal %1$supdated%2$s.'), '<strong>', '</strong>') . '</p></div>';
     } else {
         /* translators: %1$s = <strong>, %2$s = </strong> */
         $noticeAtTop = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf(esc_html__('Goal %1$screated%2$s.'), '<strong>', '</strong>') . '</p></div>';
Exemple #11
0
 public static function getAllExperiments($accountId, $webPropertyId, $profileId)
 {
     $experiments = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getExperiments($accountId, $webPropertyId, $profileId);
     self::compileActiveExperiments($experiments);
     return $experiments;
 }
Exemple #12
0
 public function getRealtimeUsage()
 {
     if ($cache = XenForo_Application::getCache()) {
         if (@json_decode(XenForo_Application::getOptions()->dpAnalyticsTokens)) {
             $handle = DigitalPointBetterAnalytics_Helper_Reporting::getInstance();
             $cacheKey = $handle->getRealtime('rt:activeUsers', 'rt:pagePath', '-rt:activeUsers', 'rt:pagePath=~/item$,rt:pagePath=~/domain$,rt:pagePath=~/article$,rt:pagePath=@/threads/,rt:pagePath=@/forums/');
             $results = $handle->getResults($cacheKey);
             $compiled = array();
             if (@$results['totalResults'] > 0) {
                 foreach ($results['rows'] as $row) {
                     if (preg_match('#/forums/.*?\\.([0-9]+?)/#', $row[0], $matches)) {
                         $compiled['forums'][$matches[1]] = array(array(), @$compiled['forums'][$matches[1]][1] + $row[1]);
                     } elseif (preg_match('#/threads/.*?\\.([0-9]+?)/#', $row[0], $matches)) {
                         $compiled['threads'][$matches[1]] = array(array(), @$compiled['threads'][$matches[1]][1] + $row[1]);
                     } elseif (preg_match('#.*?\\.([0-9]+?)/item$#', $row[0], $matches)) {
                         $compiled['items'][$matches[1]] = array(array(), @$compiled['items'][$matches[1]][1] + $row[1]);
                     } elseif (preg_match('#.*?\\.([0-9]+?)/domain$#', $row[0], $matches)) {
                         $compiled['domains'][$matches[1]] = array(array(), @$compiled['domains'][$matches[1]][1] + $row[1]);
                     } elseif (preg_match('#.*?\\.([0-9]+?)/article$#', $row[0], $matches)) {
                         $compiled['articles'][$matches[1]] = array(array(), @$compiled['articles'][$matches[1]][1] + $row[1]);
                     }
                 }
                 $compiledOutput = array();
                 if (!empty($compiled['forums'])) {
                     $forums = XenForo_Model::create('XenForo_Model_Forum')->getForumsByIds(array_keys($compiled['forums']));
                     foreach ($compiled['forums'] as $key => $forum) {
                         if (empty($forums[$key])) {
                             //unset($forums[$key]);
                         } else {
                             $compiledOutput['forums'][$key][0] = $forums[$key];
                         }
                     }
                 }
                 if (!empty($compiled['threads'])) {
                     $threads = XenForo_Model::create('XenForo_Model_Thread')->getThreadsByIds(array_keys($compiled['threads']), array('join' => XenForo_Model_Thread::FETCH_USER | XenForo_Model_Thread::FETCH_FIRSTPOST));
                     foreach ($compiled['threads'] as $key => $thread) {
                         if (empty($threads[$key]) || $threads[$key]['discussion_state'] != 'visible') {
                             //unset($threads[$key]);
                         } else {
                             $compiledOutput['threads'][$key][0] = $threads[$key];
                         }
                     }
                 }
                 $cache->save(json_encode($compiledOutput), 'analytics_realtime_data', array(), 3600);
                 // 1h cache
             }
         }
     }
 }
Exemple #13
0
 public function actionExperiments()
 {
     if (!$this->_assertLinkedAccount()) {
         return;
     }
     $betterAnalyticsOptions = get_option('better_analytics');
     $reportingClass = DigitalPointBetterAnalytics_Helper_Reporting::getInstance();
     $experiments = array();
     if ($profile = $reportingClass->getProfileByProfileId($betterAnalyticsOptions['api']['profile'])) {
         $experiments = $reportingClass->getExperiments($profile['accountId'], $profile['webPropertyId'], $profile['id']);
     }
     $this->_view('experiments', array('experiments' => $experiments));
 }