Jump to content

ganalytics module recording orders twice in Google Analytics (order date and shipping date)


StoneTrader

Recommended Posts

The official ganalytics module appears to be recording orders twice in Google Analytics: once when the product is ordered and again when it is shipped. Is anyone else experiencing this problem? Does anyone know what part of the "shipping" process could cause this to happen?

 

We have recently upgraded from PrestaShop v1.4 to v1.6.0.11. We have v2.0.9 of the Google Analytics module.

Link to comment
Share on other sites

Thanks for the link Pascal.

 

Update on the issue: the trigger for the order being recorded again in Analytics does *not* appear to be the order being shipped. We have an order (transaction) recorded yesterday and again today but it's status remains "Payment accepted".

 

My assumption is that some visitor activity, when returning to the site, is causing the GA event to be re-triggered?

Link to comment
Share on other sites

OK, we have found the problem. The ganalytics flow for addTransaction appears to work as follows:

 

In hookOrderConfirmation:

 

1) Entry for order written to ps_ganalytics MySQL table with flag sent=0

2) JavaScript Google Analytics (GA) transaction tag built and returned to front-end

3) JS GA script called (via addTransaction wrapper)

4) Callback on successful addTransaction makes ajax call (to modules/ganalytics/controllers/front/ajax.php) with the intention of updating MySQL row for order to sent=1

 

In hookBackOfficeHeader:

 

5) When this hook is called (from the back office) any entries in ps_ganalytics with a flag of sent=0 and vintage of >20 minutes are selected

6) JS GA transaction code is re-built for each of these entries and rethrown

 

Presumably the back office hook is intended to catch any failed calls to addTransaction, however we are seeing the ajax call in (4) fail *despite* the fact that the GA tag has been successfully thrown. This seems to occur for all Guest orders, with the culpable line from modules/ganalytics/controllers/front/ajax.php being line 38:

 

$this->context->cookie->id_customer is empty for a Guest checkout so the script dies before updating the MySQL (regardless of whether the GA JS has been called or not), leaving sent=0. Subsequent access to the back office (usually to ship order) causes the GA tag to be fired again.

	public function initContent()
	{
		parent::initContent();

		$order = new Order((int)Tools::getValue('orderid'));
		if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->cookie->id_customer)
			die;
		Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'ganalytics` SET sent = 1, date_add = NOW() WHERE id_order = '.(int)Tools::getValue('orderid').' LIMIT 1');
		die;
	}
}
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...