Merge branch 'ticket-GAnalytics' into develop

This commit is contained in:
Marion Muszynski 2016-09-21 16:09:14 +02:00
commit 338da7eb3f
5 changed files with 87 additions and 24 deletions

View File

@ -220,7 +220,7 @@ var ajaxCart = {
ajaxCart.updateCartInformation(jsonData, addedFromProductPage); ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
if(!jsonData.errors) { if(!jsonData.errors) {
confirmation(idProduct, idCombination, quantity); confirmation(idProduct, idCombination, quantity, jsonData);
} else if (jsonData.popup_error_cart){ } else if (jsonData.popup_error_cart){
cannotAdd(idProduct, idCombination, quantity, jsonData.errors[0]); cannotAdd(idProduct, idCombination, quantity, jsonData.errors[0]);
} }
@ -619,9 +619,25 @@ var ajaxCart = {
} }
}; };
function confirmation(idProduct, idCombination, quantity) { function confirmation(idProduct, idCombination, quantity, json) {
top.document.ajaxCart.refresh(); top.document.ajaxCart.refresh();
// send add product to cart information to GA
for (i=0;i < json.products.length; i++) {
if (json.products[i].id == idProduct) {
var prod_price = json.products[i].unit_price;
prod_price = prod_price.replace(",",".");
prod_price = prod_price.replace("€","");
productToGA = {
"id" : idProduct,
"variant" : idCombination,
"name" : ""+json.products[i].name+"",
"price" : prod_price.trim(),
"qty" : quantity
};
}
}
// AJOUT PANIER PAGE PRODUIT // AJOUT PANIER PAGE PRODUIT
if($('#quantity_sel').length > 0){ if($('#quantity_sel').length > 0){
$('#quantity_sel').html(quantity); $('#quantity_sel').html(quantity);
@ -633,6 +649,8 @@ function confirmation(idProduct, idCombination, quantity) {
} }
$('.overlay_bbb').fadeIn(); $('.overlay_bbb').fadeIn();
$('.box_add_to_cart').fadeIn(); $('.box_add_to_cart').fadeIn();
// send add product to cart information to GA
addToCartToGA(productToGA);
} }
// AJOUT PANIER ACHAT EXPRESS // AJOUT PANIER ACHAT EXPRESS
else{ else{
@ -647,6 +665,8 @@ function confirmation(idProduct, idCombination, quantity) {
window.parent.jQuery('body').append(jsonData); window.parent.jQuery('body').append(jsonData);
window.parent.$('.overlay_bbb').fadeIn(); window.parent.$('.overlay_bbb').fadeIn();
window.parent.$('.box_add_to_cart').fadeIn(); window.parent.$('.box_add_to_cart').fadeIn();
// send add product to cart information to GA
window.parent.addToCartToGA(productToGA);
}, },
error: function() {alert('ERROR: unable to delete the product');} error: function() {alert('ERROR: unable to delete the product');}
}); });
@ -656,20 +676,20 @@ function confirmation(idProduct, idCombination, quantity) {
function cannotAdd(idProduct, idCombination, quantity, error_text){ function cannotAdd(idProduct, idCombination, quantity, error_text){
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: baseDir + 'modules/blockcartex/ajax.php', url: baseDir + 'modules/blockcartex/ajax.php',
async: true, async: true,
cache: false, cache: false,
dataType : "html", dataType : "html",
data: 'id_product=' + idProduct +'&idCombination='+ idCombination +'&quantity='+quantity, data: 'id_product=' + idProduct +'&idCombination='+ idCombination +'&quantity='+quantity,
success: function(jsonData) { success: function(jsonData) {
window.parent.jQuery('body').append(jsonData); window.parent.jQuery('body').append(jsonData);
window.parent.$('#box_error_cart_text').text(error_text); window.parent.$('#box_error_cart_text').text(error_text);
window.parent.$('.overlay_bbb').fadeIn(); window.parent.$('.overlay_bbb').fadeIn();
window.parent.$('#box_error_cart').fadeIn(); window.parent.$('#box_error_cart').fadeIn();
}, },
error: function() {alert('ERROR: unable to delete the product');} error: function() {alert('ERROR: unable to delete the product');}
}); });
} }
function removeAllCart() { function removeAllCart() {

View File

@ -489,7 +489,7 @@
<input type="hidden" name="add" value="1" /> <input type="hidden" name="add" value="1" />
<input type="hidden" name="id_product_attribute" id="idCombination" value="" /> <input type="hidden" name="id_product_attribute" id="idCombination" value="" />
</p> </p>
<h1>{$product->name}</h1> <h1 class="product_footer_title">{$product->name}</h1>
<div class="border-separator"></div> <div class="border-separator"></div>
<div class="border-separator"></div> <div class="border-separator"></div>
<div class="center_element"> <div class="center_element">
@ -606,6 +606,7 @@
var idProduct = $('#buy_block_footer input[name="id_product"]').val(); var idProduct = $('#buy_block_footer input[name="id_product"]').val();
var idAttribute = $('#buy_block_footer input[name="id_product_attribute"]').val(); var idAttribute = $('#buy_block_footer input[name="id_product_attribute"]').val();
var quantity = $('#buy_block_footer #quantity_wanted').val(); var quantity = $('#buy_block_footer #quantity_wanted').val();
if ($(this).attr('disabled') != 'disabled' && $('#buy_block_footer #quantity_wanted:visible').length > 0){ if ($(this).attr('disabled') != 'disabled' && $('#buy_block_footer #quantity_wanted:visible').length > 0){
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
@ -620,6 +621,20 @@
if (jsonData.hasError !== true) { if (jsonData.hasError !== true) {
window.parent.$('.ajax_add_to_cart_product_footer_button').removeClass('active'); window.parent.$('.ajax_add_to_cart_product_footer_button').removeClass('active');
window.parent.$('a.close_popup_footer').remove(); window.parent.$('a.close_popup_footer').remove();
// send add to cart information to GA
var prod_price = $('#our_price_display').text();
prod_price = prod_price.replace(",",".");
prod_price = prod_price.replace("€","");
productToGA = {
"id" : idProduct,
"variant" : idAttribute,
"name" : ""+$('.product_footer_title').text()+"",
"price" : prod_price.trim(),
"qty" : quantity
};
window.parent.addToCartToGA(productToGA);
$('.product_added_to_cart').show(); $('.product_added_to_cart').show();
setTimeout(function() { setTimeout(function() {
$('.product_added_to_cart').hide(); $('.product_added_to_cart').hide();

View File

@ -86,7 +86,20 @@
ga('create', 'UA-30665119-1', 'auto'); ga('create', 'UA-30665119-1', 'auto');
{/literal}{if isset($page_name) && $page_name == 'order'}{literal} {/literal}{if isset($page_name) && $page_name == 'category'}{literal}
ga('require', 'ec');
{/literal}{else if isset($page_name) && $page_name == 'product'}{literal}
ga('require', 'ec');
ga('ec:addProduct', {
'id': {/literal}{$product->id}{literal},
'name': "{/literal}{$product->name|escape:'htmlall':'UTF-8'}{literal}",
'category': "{/literal}{$sale->title[$cookie->id_lang]}{literal}"
});
ga('ec:setAction', 'detail');
{/literal}{else if isset($page_name) && $page_name == 'order'}{literal}
ga('require', 'ec'); ga('require', 'ec');
{/literal} {/literal}
@ -154,6 +167,17 @@
ga('send', 'event', 'Checkout', 'Option', {}); ga('send', 'event', 'Checkout', 'Option', {});
} }
} }
function addToCartToGA(product) {
ga('ec:addProduct', {
'id': product.id,
'name': product.name,
'variant' : product.variant,
'price': product.price,
'quantity': product.qty
});
ga('ec:setAction', 'add');
ga('send', 'event', 'UX', 'click', 'add to cart');
}
</script> </script>
{/literal} {/literal}
{elseif $cookie->id_lang == 3} {elseif $cookie->id_lang == 3}

View File

@ -37,6 +37,7 @@
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 to submit carrier and send the information to GA
function submitCarrier() { function submitCarrier() {
var cgv = acceptCGV(); var cgv = acceptCGV();
if(cgv) { if(cgv) {

View File

@ -34,13 +34,15 @@
var txtProduct = "{l s='product'}"; var txtProduct = "{l s='product'}";
var txtProducts = "{l s='products'}"; var txtProducts = "{l s='products'}";
// ]]> // ]]>
{literal}
// Function to submit payment and send the information to GA
function submitPayment(){ function submitPayment(){
$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()) { if ($input.val()) {
// redirect for GA send event // redirect by GA send event
onStepComplete(4, $input.attr('data-module-name') ,$input.val(),null); onStepComplete(4, $input.attr('data-module-name') ,$input.val(),null);
} else { } else {
// LOADER POUR PAYPAL // LOADER POUR PAYPAL
@ -49,10 +51,11 @@
$('.box_paypal').fadeIn(); $('.box_paypal').fadeIn();
} }
$form = $input.parent().children('div.hidden').children('form'); $form = $input.parent().children('div.hidden').children('form');
// submit form for GA send event // submit form by GA send event
onStepComplete(4, $input.attr('data-module-name'),null,$form); onStepComplete(4, $input.attr('data-module-name'),null,$form);
} }
} }
{/literal}
</script> </script>
{capture name=path}{l s='Your payment method'}{/capture} {capture name=path}{l s='Your payment method'}{/capture}