Add counter for purchase transaction

This commit is contained in:
Michael RICOIS 2018-01-23 16:38:06 +01:00
parent d0c9e8f59b
commit 9b3f4d087b
2 changed files with 29 additions and 14 deletions

View File

@ -26,7 +26,7 @@
ga('ecommerce:clear');
{else}
ga('require', 'ec');
{foreach from=$items item=item}
ga('ec:addProduct', { // Provide product details in an productFieldObject.
'id': '{$item.SKU}', // Product ID (string).
@ -37,16 +37,16 @@
'quantity': {$item.Quantity} // Product quantity (number).
});
{/foreach}
{/literal}{if $analytics_timeover == 0}{literal}
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
{if $analytics_timeover == 0}
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
'id': '{$trans.id}', // (Required) Transaction id (string).
'affiliation': '{$trans.store}', // Affiliation (string).
'revenue': '{$trans.total}', // Revenue (currency).
'tax': '{$trans.tax}', // Tax (currency).
'shipping': '{$trans.shipping}', // Shipping (currency).
});
{/literal}{/if}{literal}
{/if}
{literal}
var re = new RegExp("([?&])(email=)[^&#]*", "g");

View File

@ -43,18 +43,33 @@ class OrderConfirmationController extends OrderConfirmationControllerCore
$products = SaleDelay::associateDelay($products);
}
// Set cookie
// Check date order if page is refresh and not affect analytics
$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();
$analytics_timeover = 0;
if (time() > $timestamp) {
$analytics_timeover = 1;
$transCpt = 0;
// Cookie
global $cookie;
if (isset($cookie->transCpt)) {
$transCpt = (int) $cookie->transCpt;
}
$transCpt++;
$cookie->transCpt = $transCpt;
$cookie->write();
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;
}
}
self::$smarty->assign(
array(
'customer' => $customer,