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; }
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; }
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)); }
public function actionHeatmap() { $this->_assertLinkedAccount(); if ($this->isConfirmedPost()) { $input = $this->_input->filter(array('metric' => XenForo_Input::STRING, 'segment' => XenForo_Input::STRING, 'weeks' => XenForo_Input::UINT, 'end' => XenForo_Input::UINT)); if (!DigitalPointBetterAnalytics_Helper_Api::check()) { if (array_search($input['metric'], array('ga:users', 'ga:sessions', 'ga:hits', 'ga:organicSearches')) === false) { return $this->responseError(new XenForo_Phrase('not_all_metrics_available')); } } $heatmapData = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getWeeklyHeatmap($input['end'], $input['weeks'], $input['metric'], $input['segment']); return $this->responseView('DigitalPointBetterAnalytics_ViewAdmin_Heatmaps_Ajax', 'analytics_heatmap_data', array('heatmap_data' => $heatmapData)); } $heatmapData = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getWeeklyHeatmap(7, 10, 'ga:sessions'); $_hourMap = array(); for ($i = 0; $i < 24; $i++) { $_hourMap[$i] = date('g A', $i * 3600); } return $this->responseView('DigitalPointBetterAnalytics_ViewAdmin_Heatmaps', 'analytics_heatmaps', array('heatmap_data' => $heatmapData, 'metrics' => $this->_getMetrics(), 'segments' => $this->_getSegments(), 'hour_map' => $_hourMap)); }
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); }
?> <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>
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'); }
$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>';
public static function getAllExperiments($accountId, $webPropertyId, $profileId) { $experiments = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getExperiments($accountId, $webPropertyId, $profileId); self::compileActiveExperiments($experiments); return $experiments; }
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 } } } }
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)); }