162 lines
8.3 KiB
PHP
162 lines
8.3 KiB
PHP
<?php
|
|
|
|
class SQ_Models_Focuspages_Traffic extends SQ_Models_Abstract_Assistant {
|
|
|
|
protected $_category = 'traffic';
|
|
|
|
protected $_bounce_rate = false;
|
|
protected $_page_views = false;
|
|
protected $_page_sessions = false;
|
|
protected $_page_newvisits = false;
|
|
protected $_page_time = false;
|
|
protected $_gacode_duplicate = false;
|
|
|
|
const BOUNCE_MAXVAL = 50;
|
|
const AVGTIME_MINVAL = 120;
|
|
const EXIT_MAXVAL = 70;
|
|
const VISITS_MINVAL = 70;
|
|
|
|
public function init() {
|
|
parent::init();
|
|
|
|
if (!isset($this->_audit->data)) {
|
|
$this->_error = true;
|
|
return;
|
|
}
|
|
|
|
if ($this->_audit->sq_analytics_google_connected) {
|
|
if (isset($this->_audit->data->sq_analytics_google->page_bouce)) {
|
|
$this->_bounce_rate = $this->_audit->data->sq_analytics_google->page_bouce;
|
|
}
|
|
if (isset($this->_audit->data->sq_analytics_google->page_views)) {
|
|
$this->_page_views = $this->_audit->data->sq_analytics_google->page_views;
|
|
}
|
|
if (isset($this->_audit->data->sq_analytics_google->page_sessions)) {
|
|
$this->_page_sessions = $this->_audit->data->sq_analytics_google->page_sessions;
|
|
}
|
|
if (isset($this->_audit->data->sq_analytics_google->page_newvisits)) {
|
|
$this->_page_newvisits = $this->_audit->data->sq_analytics_google->page_newvisits;
|
|
}
|
|
if (isset($this->_audit->data->sq_analytics_google->page_time)) {
|
|
$this->_page_time = $this->_audit->data->sq_analytics_google->page_time;
|
|
}
|
|
}
|
|
|
|
if (isset($this->_audit->data->sq_seo_body->ga_duplicate)) {
|
|
$this->_gacode_duplicate = $this->_audit->data->sq_seo_body->ga_duplicate;
|
|
}
|
|
}
|
|
|
|
public function setTasks($tasks) {
|
|
parent::setTasks($tasks);
|
|
|
|
$this->_tasks[$this->_category] = array(
|
|
'bounce' => array(
|
|
'title' => sprintf(__("Below %s Bounce Rate", _SQ_PLUGIN_NAME_), self::BOUNCE_MAXVAL . '%'),
|
|
'value' => number_format($this->_bounce_rate, 2) . '%'. ' ' . __('bounce rate', _SQ_PLUGIN_NAME_),
|
|
'description' => sprintf(__('Make sure this number is below %s %s Why? %s A high bounce rate means that your users just click on your search listing, visit the page and then decide they\'ve seen enough and bounce off to another page on the web. %s This is, for Google, an indicator of the quality of the search result it displayed. And if many of your users bounce off your pages, it means (to Google) that your page is not worth displaying in search results, because it has low performance with the user groups it sends your way. %s Easy way to complete this task: give users pages to click and send them to other pages from your site.', _SQ_PLUGIN_NAME_), self::BOUNCE_MAXVAL . '%', '<br /><br />', '<br /><br />', '<br /><br />', '<br /><br />'),
|
|
),
|
|
'avgtime' => array(
|
|
'title' => sprintf(__("Time on page is %s minutes", _SQ_PLUGIN_NAME_), (self::AVGTIME_MINVAL / 60)),
|
|
'value' => ($this->_page_time > 0 ? number_format(($this->_page_time / 60), 0) : 0) . ' ' . __('minutes', _SQ_PLUGIN_NAME_),
|
|
'penalty' => 10,
|
|
'description' => sprintf(__('Make sure that visitors spend on average at least %s minutes on your site. %s Get an average time on page of minimum %s minutes for this focus page. You can do this by editing the content and making it more appealing to visitors. %s In the Best Practices section you\'ll find a plugin for WordPress that will help your Google Analytics tracker to track the real time on page for people. Sometimes, Google Analytics tracks this lower than it should. %s If your visitors don\'t spend at 2 minutes on your Focus Page, it can mean that the page is not important enough for them, or that the content from the page is boring, or hard to read, or the page just loads too slow.', _SQ_PLUGIN_NAME_), (self::AVGTIME_MINVAL / 60), (self::AVGTIME_MINVAL / 60), '<br /><br />', '<br /><br />', '<br /><br />'),
|
|
),
|
|
'visits' => array(
|
|
'title' => sprintf(__("%s visitors / day / page", _SQ_PLUGIN_NAME_), self::VISITS_MINVAL),
|
|
'value' => $this->_page_sessions . ' ' . __('unique views', _SQ_PLUGIN_NAME_),
|
|
'description' => sprintf(__("For this task, we're looking at unique page views from your Google Analytics. %s If you don't get %s visitors / day / page, then this Focus Page is not yet popular enough on your site. %s You should make sure that more people end up visiting it.", _SQ_PLUGIN_NAME_), '<br /><br />', self::VISITS_MINVAL, '<br /><br />'),
|
|
),
|
|
'gacode' => array(
|
|
'title' => sprintf(__("Just one Google Analytics tracking code", _SQ_PLUGIN_NAME_), self::VISITS_MINVAL),
|
|
'description' => sprintf(__("We've seen many sites where there were multiple google analytics codes placed by different employees, themes or plugins. %s With this check, we're helping you make sure that your tracker is setup properly and that there will be no errors with your Google Analytics account. %s To turn this green, you'll have to investigate your theme, custom code that you may have placed in your theme, other plugins, header settings. Once you have a clear view of all the tracking codes, make sure that only one remains and that the one code is the one linked to your Google Analytics account. %s These problems happen more often than you would think.", _SQ_PLUGIN_NAME_), '<br /><br />', '<br /><br />', '<br /><br />'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/*********************************************/
|
|
/**
|
|
* Check if the Google Analytics is connected
|
|
* @return string
|
|
*/
|
|
public function getHeader() {
|
|
if (!$this->_audit->sq_analytics_gsc_connected) {
|
|
return '<li class="completed">
|
|
<a href="' . SQ_Classes_RemoteController::getApiLink('gaoauth') . '" target="_blank" class="btn bg-primary text-white col-sm-10 offset-1 mt-3">' . __('Connect Google Analytics', _SQ_PLUGIN_NAME_) . '</a>
|
|
</li>';
|
|
}
|
|
if (!$this->_audit->sq_analytics_google_connected) {
|
|
return '<li class="completed">
|
|
<a href="' . SQ_Classes_RemoteController::getApiLink('gaoauth') . '" target="_blank" class="btn bg-primary text-white col-sm-10 offset-1 mt-3">' . __('Connect Google Analytics', _SQ_PLUGIN_NAME_) . '</a>
|
|
</li>';
|
|
}
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Keyword optimization required
|
|
* @param $title
|
|
* @return string
|
|
*/
|
|
public function getTitle($title) {
|
|
parent::getTitle($title);
|
|
|
|
if ($this->_error && !$this->_audit->sq_analytics_google_connected) {
|
|
$title = __("Connect Google Analytics first", _SQ_PLUGIN_NAME_);
|
|
}else{
|
|
$title = __("Not enough traffic to show relevant stats", _SQ_PLUGIN_NAME_);
|
|
}
|
|
return $title;
|
|
}
|
|
|
|
/**
|
|
* API Google Analytics Bounce rate
|
|
* @return bool|WP_Error
|
|
*/
|
|
public function checkBounce($task) {
|
|
if ($this->_bounce_rate !== false) {
|
|
$task['completed'] = ($this->_bounce_rate <= self::BOUNCE_MAXVAL);
|
|
return $task;
|
|
}
|
|
|
|
$task['error'] = true;
|
|
return $task;
|
|
}
|
|
|
|
/**
|
|
* API Google Analytics Avg Time rate
|
|
* @return bool|WP_Error
|
|
*/
|
|
public function checkAvgtime($task) {
|
|
if ($this->_page_time !== false) {
|
|
$task['completed'] = ($this->_page_time >= self::AVGTIME_MINVAL);
|
|
return $task;
|
|
}
|
|
|
|
$task['error'] = true;
|
|
return $task;
|
|
}
|
|
|
|
/**
|
|
* API Google Analytics Visits rate. Unique page views
|
|
* @return bool|WP_Error
|
|
*/
|
|
public function checkVisits($task) {
|
|
if ($this->_page_sessions !== false) {
|
|
$task['completed'] = ($this->_page_sessions >= self::VISITS_MINVAL);
|
|
return $task;
|
|
}
|
|
|
|
$task['error'] = true;
|
|
return $task;
|
|
}
|
|
|
|
/**
|
|
* API Google Analytics GA code duplicate
|
|
* @return bool|WP_Error
|
|
*/
|
|
public function checkGacode($task) {
|
|
$task['completed'] = !$this->_gacode_duplicate;
|
|
return $task;
|
|
}
|
|
} |