Merge branch 'ticket-GAnalytics' into develop

This commit is contained in:
Marion Muszynski 2016-09-20 18:00:48 +02:00
commit 9673ff3805
3 changed files with 278 additions and 217 deletions

View File

@ -89,10 +89,12 @@
{/literal}{if isset($page_name) && $page_name == 'order'}{literal} {/literal}{if isset($page_name) && $page_name == 'order'}{literal}
ga('require', 'ec'); ga('require', 'ec');
{/literal}{if $step == 0}{literal} {/literal}
{/literal}{if $cart} {if $step == 0 || $step == 1}
{assign var='cartProducts' value=$cart->getProducts()}{literal} {if $cart}
{/literal}{foreach from=$cartProducts item=cartProduct}{literal} {assign var='cartProducts' value=$cart->getProducts()}
{foreach from=$cartProducts item=cartProduct}
{literal}
ga('ec:addProduct', { ga('ec:addProduct', {
'id': {/literal}{$cartProduct['id_product']}{literal}, 'id': {/literal}{$cartProduct['id_product']}{literal},
'name': "{/literal}{$cartProduct['name']}{literal}", 'name': "{/literal}{$cartProduct['name']}{literal}",
@ -100,20 +102,29 @@
'price': {/literal}{Tools::ps_round(Product::getPriceStatic((int)$cartProduct['id_product'], true, ((isset($cartProduct['id_product_attribute']) AND !empty($cartProduct['id_product_attribute'])) ? (int)($cartProduct['id_product_attribute']) : NULL), 2), 2)}{literal}, 'price': {/literal}{Tools::ps_round(Product::getPriceStatic((int)$cartProduct['id_product'], true, ((isset($cartProduct['id_product_attribute']) AND !empty($cartProduct['id_product_attribute'])) ? (int)($cartProduct['id_product_attribute']) : NULL), 2), 2)}{literal},
'quantity': {/literal}{$cartProduct['cart_quantity']}{literal} 'quantity': {/literal}{$cartProduct['cart_quantity']}{literal}
}); });
{/literal}{/foreach}{literal} {/literal}
{/literal}{/if}{literal} {/foreach}
{/if}
{/if}
{literal}
{/literal}{if $step == 0}{literal}
//cart
ga('ec:setAction','checkout', { ga('ec:setAction','checkout', {
'step': 1, 'step': 1,
}); });
{/literal}{else if $step == 1}{literal} {/literal}{else if $step == 1}{literal}
// address
ga('ec:setAction','checkout', { ga('ec:setAction','checkout', {
'step': 2, 'step': 2,
}); });
{/literal}{else if $step == 2}{literal} {/literal}{else if $step == 2}{literal}
// carrier
ga('ec:setAction','checkout', { ga('ec:setAction','checkout', {
'step': 3, 'step': 3,
}); });
{/literal}{else if $step == 3}{literal} {/literal}{else if $step == 3}{literal}
// payment
ga('ec:setAction','checkout', { ga('ec:setAction','checkout', {
'step': 4, 'step': 4,
}); });
@ -121,6 +132,28 @@
{/if}{literal} {/if}{literal}
ga('send', 'pageview'); ga('send', 'pageview');
function onStepComplete(stepNumber, option, redirect, form) {
ga('ec:setAction', 'checkout_option', {
'step': stepNumber,
'option': option
});
if (redirect != null) {
ga('send', 'event', 'Checkout', 'Option', {
hitCallback: function() {
document.location = redirect;
}
});
} else if (form != null) {
ga('send', 'event', 'Checkout', 'Option', {
hitCallback: function() {
form.submit();
}
});
} else {
ga('send', 'event', 'Checkout', 'Option', {});
}
}
</script> </script>
{/literal} {/literal}
{elseif $cookie->id_lang == 3} {elseif $cookie->id_lang == 3}

View File

@ -37,6 +37,16 @@
var msg = "{l s='You must agree to the terms of service before continuing.' js=1}"; var msg = "{l s='You must agree to the terms of service before continuing.' js=1}";
{literal} {literal}
function submitCarrier() {
var cgv = acceptCGV();
if(cgv) {
// carrier = $("input[name='id_carrier']:checked","#form").val();
carrier_name = ""+$("input[name='id_carrier']:checked", "#form").data('name')+"";
onStepComplete(3, carrier_name, null, null);
} else {
return cgv;
}
}
function acceptCGV() function acceptCGV()
{ {
if ($('#cgv').length && !$('input#cgv:checked').length) if ($('#cgv').length && !$('input#cgv:checked').length)
@ -82,7 +92,7 @@
{include file="$tpl_dir./errors.tpl"} {include file="$tpl_dir./errors.tpl"}
<form id="form" action="{$link->getPageLink('order.php', true)}" method="post" onsubmit="return acceptCGV();"> <form id="form" action="{$link->getPageLink('order.php', true)}" method="post" onsubmit="return submitCarrier();return !ga.loaded;">
{else} {else}
<h2>2. {l s='Delivery methods'}</h2> <h2>2. {l s='Delivery methods'}</h2>
<div id="opc_delivery_methods" class="opc-main-block"> <div id="opc_delivery_methods" class="opc-main-block">
@ -128,7 +138,7 @@
{foreach from=$carriers item=carrier name=myLoop} {foreach from=$carriers item=carrier name=myLoop}
<tr class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{/if} {if $smarty.foreach.myLoop.index % 2}alternate_item{else}item{/if}"> <tr class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{/if} {if $smarty.foreach.myLoop.index % 2}alternate_item{else}item{/if}">
<td class="carrier_action radio"> <td class="carrier_action radio">
<input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier{$carrier.id_carrier|intval}" {if $opc}onclick="updateCarrierSelectionAndGift();"{/if} {if !($carrier.is_module AND $opc AND !$isLogged)}{if $carrier.id_carrier == $checked}checked="checked"{/if}{else}disabled="disabled"{/if} /> <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" data-name="{$carrier.name|escape:'htmlall':'UTF-8'}" id="id_carrier{$carrier.id_carrier|intval}" {if $opc}onclick="updateCarrierSelectionAndGift();"{/if} {if !($carrier.is_module AND $opc AND !$isLogged)}{if $carrier.id_carrier == $checked}checked="checked"{/if}{else}disabled="disabled"{/if} />
</td> </td>
<td class="carrier_name"> <td class="carrier_name">
<label for="id_carrier{$carrier.id_carrier|intval}"> <label for="id_carrier{$carrier.id_carrier|intval}">

View File

@ -34,6 +34,25 @@
var txtProduct = "{l s='product'}"; var txtProduct = "{l s='product'}";
var txtProducts = "{l s='products'}"; var txtProducts = "{l s='products'}";
// ]]> // ]]>
function submitPayment(){
$input = $('input[name="paiement-method"]:checked');
if(!$input.length) {
alert(paiementErrorMessage);
}
if ($input.val()) {
// redirect for GA send event
onStepComplete(4, $input.attr('data-module-name') ,$input.val(),null);
} else {
// LOADER POUR PAYPAL
if ($input.attr('data-module-name') == "paypal") {
$('.overlay_bbb').fadeIn();
$('.box_paypal').fadeIn();
}
$form = $input.parent().children('div.hidden').children('form');
// submit form for GA send event
onStepComplete(4, $input.attr('data-module-name'),null,$form);
}
}
</script> </script>
{capture name=path}{l s='Your payment method'}{/capture} {capture name=path}{l s='Your payment method'}{/capture}
@ -72,7 +91,7 @@
{/if} {/if}
<p class="cart_navigation"> <p class="cart_navigation">
<a href="{$link->getPageLink('order.php', true)}?step=2" title="{l s='Previous'}" class="button">{l s='Previous'}</a> <a href="{$link->getPageLink('order.php', true)}?step=2" title="{l s='Previous'}" class="button">{l s='Previous'}</a>
<a class="exclusive submitPayment" title="{l s='Valider ma commande'}" class="button">{l s='Valider ma commande'}</a> <a class="exclusive submitPayment" title="{l s='Valider ma commande'}" class="button" onclick="submitPayment(); return !ga.loaded;">{l s='Valider ma commande'}</a>
</p> </p>
{else} {else}
</div> </div>
@ -103,27 +122,26 @@
$(this).children('.input_radio').children('input[name="paiement-method"]').attr('checked', true); $(this).children('.input_radio').children('input[name="paiement-method"]').attr('checked', true);
}); });
$('.submitPayment').live('click', function(e) { // $('.submitPayment').live('click', function(e) {
e.preventDefault(); // e.preventDefault();
// check if selected // // check if selected
$input = $('input[name="paiement-method"]:checked'); // $input = $('input[name="paiement-method"]:checked');
if(!$input.length) { // if(!$input.length) {
alert(paiementErrorMessage); // alert(paiementErrorMessage);
} // }
// if ($input.val()) {
// window.location = $input.val();
// } else {
// // LOADER POUR PAYPAL
// if ($input.attr('data-module-name') == "paypal") {
// $('.overlay_bbb').fadeIn();
// $('.box_paypal').fadeIn();
// }
// $form = $input.parent().children('div.hidden').children('form');
// $form.submit();
// }
if ($input.val()) { // });
window.location = $input.val();
} else {
// LOADER POUR PAYPAL
if ($input.attr('data-module-name') == "paypal") {
$('.overlay_bbb').fadeIn();
$('.box_paypal').fadeIn();
}
$form = $input.parent().children('div.hidden').children('form');
$form.submit();
}
});
}); });
</script> </script>