Merge remote-tracking branch 'origin/ticket/r11982-ganalytics'

This commit is contained in:
Michael RICOIS 2018-01-29 14:36:38 +01:00
commit 7a7cc4d7fe
2 changed files with 68 additions and 29 deletions

View File

@ -38,6 +38,7 @@
});
{/foreach}
{if $cookie->transCpt < 2}
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
'id': '{$trans.id}', // (Required) Transaction id (string).
'affiliation': '{$trans.store}', // Affiliation (string).
@ -45,6 +46,7 @@
'tax': '{$trans.tax}', // Tax (currency).
'shipping': '{$trans.shipping}', // Shipping (currency).
});
{/if}
{literal}
var re = new RegExp("([?&])(email=)[^&#]*", "g");

View File

@ -43,13 +43,50 @@ class OrderConfirmationController extends OrderConfirmationControllerCore
$products = SaleDelay::associateDelay($products);
}
$analytics_timeover = 0;
$transCpt = 0;
// Cookie
global $cookie;
// Reset
if (isset($cookie->id_transaction)) {
if ($cookie->id_transaction != $order->id) {
unset($cookie->id_transaction);
unset($cookie->transCpt);
}
}
// Set counter
if (isset($cookie->transCpt)) {
$transCpt = (int) $cookie->transCpt;
}
$transCpt++;
if ($transCpt > 1) {
$analytics_timeover = 1;
}
// Check date order if page is refresh and not affect analytics
if ($analytics_timeover == 0) {
$timestamp_check = new DateTime();
$timestamp_check->createFromFormat('Y-m-d H:i:s', $order->date_add);
$timestamp_check->add(new DateInterval('PT10M'));
$timestamp = $timestamp_check->getTimestamp();
if (time() > $timestamp) {
$analytics_timeover = 1;
$transCpt++;
}
}
// Write cookie
$cookie->transCpt = $transCpt;
$cookie->id_transaction = $order->id;
$cookie->write();
self::$smarty->assign(
array(
'customer' => $customer,
'order' => $order,
'address_delivery' => $address_delivery,
'address_invoice' => $address_invoice,
'products' => $products
'products' => $products,
'analytics_timeover' => $analytics_timeover,
)
);
self::$smarty->display(_PS_THEME_DIR_.'order-confirmation.tpl');