Jump to content

[SOLVED]: "ACTIVITY OVERVIEW" dashboard module not showing "traffic" data


Recommended Posts

I've migrated my 1.4.5.2 PS version to 1.6.1.5, updated the database manually and everything is working fine, except that the Traffic data in the dashboard is not visible - it shows only 0 and NO DATA (screenshot attached).

 

Some background story on this:

1. I've made a clean 1.6.1.5 install,

2. moved old database by manually merging with 1.6.1.5 structure.

 

Data was showing up fine, but then it just disappeared. The only change I've made around that time, was installing google API and google analytics modules.

 

Might they be interferring with traffic data? Or this is definitely something else?

 

 

post-379330-0-37990100-1477552820_thumb.jpg

Edited by sting5 (see edit history)
  • Like 1
Link to comment
Share on other sites

Hi Knowband,

 

thanks - I will check out the thread and give the answer if it helped to solve anything. Thanks again!

 

[EDIT]: No luck, the fix is dedicated for those whose dashboard ACTIVITY OVERVIEW is not showing any data - mine is showing all except traffic. If You have any other ideas, I would really appreciate that!

Edited by sting5 (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...
If you will open /modules/dashactivity/dashactivity.php file you will find the following code in hookDashboardData() function.

 



$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
$visits = $unique_visitors = $online_visitor = 0;
if ($result = $gapi->requestReportData('', 'ga:visits,ga:visitors', Tools::substr($params['date_from'], 0, 10), Tools::substr($params['date_to'], 0, 10), null, null, 1, 1))
{
$visits = $result[0]['metrics']['visits'];
$unique_visitors = $result[0]['metrics']['visitors'];
}
}
else
{
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(*) as visits, COUNT(DISTINCT `id_guest`) as unique_visitors
FROM `'._DB_PREFIX_.'connections`
WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
'.Shop::addSqlRestriction(false)
);
extract($row);
}



This code is responsible for showing the traffic data on Admin dashboard and as you are saying that there is no traffic data, that means there is some problem with your `connections` table. Please check if you have moved the data in `connections` table from old to the new database correctly.

 

You can also try installing the gapi module as per the above code.

  • Like 1
Link to comment
Share on other sites

I did install the Google API module, but it's not transferring any data to the dashboard for some reason (I've checked the settings three times, everything works), and analytics is gathering the info successfully - I did an override (to ignore gapi module) for ..\controllers\admin\AdminStatsController.php - maybe dashactivity.php is the reason why dashboard keeps ignoring my changes. My ps_connections is fine. Thanks again for the suggestion, I'll try this and report results.

 

 

[EDIT]:

 

Ok, problem solved - I've removed the first part of if condition, left only else condition together with it's contents in dashactivity.php for function and plain code.

 

Here's the final code for getReferer (refferer site info will appear in dashboard):

	protected function getReferer($date_from, $date_to, $limit = 3)
	{
		$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
		if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
		{
			$websites = array();
			if ($result = $gapi->requestReportData(
				'ga:source',
				'ga:visitors',
				Tools::substr($date_from, 0, 10),
				Tools::substr($date_to, 0, 10),
				'-ga:visitors',
				null,
				1,
				$limit
			))
				foreach ($result as $row)
					$websites[$row['dimensions']['source']] = $row['metrics']['visitors'];
		}
		else
		{
			$direct_link = $this->l('Direct link');
			$websites = array($direct_link => 0);

			$result = Db::getInstance()->ExecuteS('
				SELECT http_referer
				FROM '._DB_PREFIX_.'connections
				WHERE date_add BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'"
				'.Shop::addSqlRestriction().'
				LIMIT '.(int)$limit
			);
			foreach ($result as $row)
			{
				if (!isset($row['http_referer']) || empty($row['http_referer']))
					++$websites[$direct_link];
				else
				{
					$website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST));
					if (!isset($websites[$website]))
						$websites[$website] = 1;
					else
						++$websites[$website];
				}
			}
			arsort($websites);
		}

		return $websites;
	}

And here's the final example of edit around line 159 (visits will appear in dashboard):

Original code:

		$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
		if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
		{
			$visits = $unique_visitors = $online_visitor = 0;
			if ($result = $gapi->requestReportData('', 'ga:visits,ga:visitors', Tools::substr($params['date_from'], 0, 10), Tools::substr($params['date_to'], 0, 10), null, null, 1, 1))
			{
				$visits = $result[0]['metrics']['visits'];
				$unique_visitors = $result[0]['metrics']['visitors'];
			}
		}
		else
		{
			$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
						SELECT COUNT(*) as visits, COUNT(DISTINCT `id_guest`) as unique_visitors
						FROM `'._DB_PREFIX_.'connections`
						WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
						'.Shop::addSqlRestriction(false)
					);
			extract($row);
		}

The final code with deleted gapi part:

			$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
						SELECT COUNT(*) as visits, COUNT(DISTINCT `id_guest`) as unique_visitors
						FROM `'._DB_PREFIX_.'connections`
						WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
						'.Shop::addSqlRestriction(false)
					);
			extract($row);

Few notes: Though "gapi" module is installed and fully configured, it does not transfer the visits/referrers data to the dashboard "traffic" information block for some reason. I don't know why and I don't see any reason why I should waste my time finding out - Prestashop is mining it's data into the database, so it's better to show it instead, at least while they figure out why the gapi is not giving data for dashboard as it should. Yes, google gives more accurate data and all, but better get any info instead of none.

Edited by sting5 (see edit history)
Link to comment
Share on other sites

Ok, feel the responsibility to give the final result - my setup with API was bad after all!

 

checked the credentials, and the profile code was wrong - now the visits and referrers are fine! Thanks again Knowband Plugins for the input in solving this, I hope someone else will manage to use the code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...