/** * Getting the instance object * * This method will return the instance of itself, if instance not exists, becauses of it's called for the first * time, the instance will be created. * * @return null|Yoast_Google_Analytics */ public static function get_instance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * Execute an API call to Google Analytics and store the data in the dashboards data class * * @param string $metric * @param string $start_date 2014-10-16 * @param string $end_date 2014-11-20 * @param string $dimensions ga:date * @param string $storage_name auto * * @return bool */ private function execute_call($metric, $start_date, $end_date, $dimensions = 'ga:date', $storage_name = 'auto') { $dimensions = $this->prepare_dimensions($dimensions, $metric); $params = $this->build_params_for_call($start_date, $end_date, $dimensions, $metric); $storage_type = $this->get_storage_type($dimensions); $response = Yoast_Google_Analytics::get_instance()->do_request('https://www.googleapis.com/analytics/v3/data/ga?' . $params); if (isset($response['response']['code']) && $response['response']['code'] == 200) { // Delete option api_fail because there it's successful now delete_option('yst_ga_api_call_fail'); // Success, set a transient which stores the latest runtime update_option('yst_ga_last_wp_run', date('Y-m-d')); $response = Yoast_Googleanalytics_Reporting::get_instance()->parse_response($response, $storage_type, $start_date, $end_date); } else { // When response is failing, we should count the number of $this->save_api_failure(); return false; } if (strpos('ga:date', $dimensions) !== false) { return $this->handle_response($response, $metric, $dimensions, $start_date, $end_date, 'datelist', $storage_name); } else { return $this->handle_response($response, $metric, $dimensions, $start_date, $end_date, 'table', $storage_name); } }
/** * Execute an API call to Google Analytics and store the data in the dashboards data class * * @param $metric * @param $start_date 2014-10-16 * @param $end_date 2014-11-20 * @param $dimensions ga:date * @param $storage_name string * * @return bool */ private function execute_call($metric, $start_date, $end_date, $dimensions = 'ga:date', $storage_name = 'auto') { $dimensions = $this->prepare_dimensions($dimensions, $metric); $params = $this->build_params_for_call($start_date, $end_date, $dimensions, $metric); $storage_type = $this->get_storage_type($dimensions); $response = Yoast_Google_Analytics::get_instance()->do_request('https://www.googleapis.com/analytics/v3/data/ga?' . $params); if (isset($response['response']['code']) && $response['response']['code'] == 200) { $response = Yoast_Googleanalytics_Reporting::get_instance()->parse_response($response, $storage_type, $start_date, $end_date); } else { return false; } if (strpos('ga:date', $dimensions) !== false) { return $this->handle_response($response, $metric, $dimensions, $start_date, $end_date, 'datelist', $storage_name); } else { return $this->handle_response($response, $metric, $dimensions, $start_date, $end_date, 'table', $storage_name); } }