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

@ -4,21 +4,21 @@
ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': '{$trans.id}', // Transaction ID. Required
'affiliation': '{$trans.store}', // Affiliation or store name.
'revenue': '{$trans.total}', // Grand Total.
'shipping': '{$trans.shipping}', // Shipping.
'tax': '{$trans.tax}' // Tax.
'id': '{$trans.id}', // Transaction ID. Required
'affiliation': '{$trans.store}', // Affiliation or store name.
'revenue': '{$trans.total}', // Grand Total.
'shipping': '{$trans.shipping}', // Shipping.
'tax': '{$trans.tax}' // Tax.
});
{foreach from=$items item=item}
ga('ecommerce:addItem', {
'id': '{$item.OrderId}', // Transaction ID. Required.
'name': '{$item.Product}', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': '{$item.Category}', // Category or variation.
'price': '{$item.Price}', // Unit price.
'quantity': '{$item.Quantity}' // Quantity.
'id': '{$item.OrderId}', // Transaction ID. Required.
'name': '{$item.Product}', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': '{$item.Category}', // Category or variation.
'price': '{$item.Price}', // Unit price.
'quantity': '{$item.Quantity}' // Quantity.
});
{/foreach}
@ -26,25 +26,27 @@
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).
'name': '{$item.Product}', // Product name (string).
'category': '{$item.Category}', // Product category (string).
'brand': '{$item.Category}', // Product brand (string).
'price': '{$item.Price}', // Product price (currency).
'quantity': {$item.Quantity} // Product quantity (number).
});
ga('ec:addProduct', { // Provide product details in an productFieldObject.
'id': '{$item.SKU}', // Product ID (string).
'name': '{$item.Product}', // Product name (string).
'category': '{$item.Category}', // Product category (string).
'brand': '{$item.Category}', // Product brand (string).
'price': '{$item.Price}', // Product price (currency).
'quantity': {$item.Quantity} // Product quantity (number).
});
{/foreach}
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).
});
{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).
'revenue': '{$trans.total}', // Revenue (currency).
'tax': '{$trans.tax}', // Tax (currency).
'shipping': '{$trans.shipping}', // Shipping (currency).
});
{/if}
{literal}
var re = new RegExp("([?&])(email=)[^&#]*", "g");

View File

@ -42,6 +42,42 @@ class OrderConfirmationController extends OrderConfirmationControllerCore
require_once _PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php';
$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(
@ -49,7 +85,8 @@ class OrderConfirmationController extends OrderConfirmationControllerCore
'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');