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);
if(!jsonData.errors) {
confirmation(idProduct, idCombination, quantity);
confirmation(idProduct, idCombination, quantity, jsonData);
} else if (jsonData.popup_error_cart){
cannotAdd(idProduct, idCombination, quantity, jsonData.errors[0]);
}
@ -411,7 +411,7 @@ var ajaxCart = {
if (this.id != undefined)
{
//create a container for listing the products and hide the 'no product in the cart' message (only if the cart was empty)
if ($('div#cart_block dl.products').length == 0)
if ($('div#cart_block dl.products').length == 0)
$('p#cart_block_no_products').hide('fast', 0, function(){
}).before('<dl class="products"></dl>');
@ -420,7 +420,7 @@ var ajaxCart = {
var domIdProductAttribute = this.id + '_' + (this.idCombination ? this.idCombination : '0');
if($('#cart_block dt#cart_block_product_'+ domIdProduct ).length == 0)
{
var productId = parseInt(this.id);
var productId = parseInt(this.id);
var productAttributeId = (this.hasAttributes ? parseInt(this.attributes) : 0);
var name = (this.name.length > 40 ? this.name.substring(0, 10) + '...' : this.name);
var content = '<dt class="hidden" id="cart_block_product_' + domIdProduct + '">';
@ -619,20 +619,38 @@ var ajaxCart = {
}
};
function confirmation(idProduct, idCombination, quantity) {
function confirmation(idProduct, idCombination, quantity, json) {
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
if($('#quantity_sel').length > 0){
$('#quantity_sel').html(quantity);
if(quantity > 1){
var price = $('#price_add_to_cart').html();
var price_float = price.replace(",", ".");
var price_float = price.replace(",", ".");
var new_price = parseFloat(price_float) * quantity;
$('#price_add_to_cart').html(new_price);
}
$('.overlay_bbb').fadeIn();
$('.box_add_to_cart').fadeIn();
// send add product to cart information to GA
addToCartToGA(productToGA);
}
// AJOUT PANIER ACHAT EXPRESS
else{
@ -647,6 +665,8 @@ function confirmation(idProduct, idCombination, quantity) {
window.parent.jQuery('body').append(jsonData);
window.parent.$('.overlay_bbb').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');}
});
@ -656,20 +676,20 @@ function confirmation(idProduct, idCombination, quantity) {
function cannotAdd(idProduct, idCombination, quantity, error_text){
$.ajax({
type: 'POST',
url: baseDir + 'modules/blockcartex/ajax.php',
async: true,
cache: false,
dataType : "html",
data: 'id_product=' + idProduct +'&idCombination='+ idCombination +'&quantity='+quantity,
success: function(jsonData) {
window.parent.jQuery('body').append(jsonData);
window.parent.$('#box_error_cart_text').text(error_text);
window.parent.$('.overlay_bbb').fadeIn();
window.parent.$('#box_error_cart').fadeIn();
},
error: function() {alert('ERROR: unable to delete the product');}
});
type: 'POST',
url: baseDir + 'modules/blockcartex/ajax.php',
async: true,
cache: false,
dataType : "html",
data: 'id_product=' + idProduct +'&idCombination='+ idCombination +'&quantity='+quantity,
success: function(jsonData) {
window.parent.jQuery('body').append(jsonData);
window.parent.$('#box_error_cart_text').text(error_text);
window.parent.$('.overlay_bbb').fadeIn();
window.parent.$('#box_error_cart').fadeIn();
},
error: function() {alert('ERROR: unable to delete the product');}
});
}
function removeAllCart() {

View File

@ -90,7 +90,7 @@
float: left;
}
#quantity_wanted_p {
padding:0;
padding:0;
}
#quantity_wanted {
text-align: right;
@ -489,7 +489,7 @@
<input type="hidden" name="add" value="1" />
<input type="hidden" name="id_product_attribute" id="idCombination" value="" />
</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="center_element">
@ -606,6 +606,7 @@
var idProduct = $('#buy_block_footer input[name="id_product"]').val();
var idAttribute = $('#buy_block_footer input[name="id_product_attribute"]').val();
var quantity = $('#buy_block_footer #quantity_wanted').val();
if ($(this).attr('disabled') != 'disabled' && $('#buy_block_footer #quantity_wanted:visible').length > 0){
$.ajax({
type: 'POST',
@ -620,6 +621,20 @@
if (jsonData.hasError !== true) {
window.parent.$('.ajax_add_to_cart_product_footer_button').removeClass('active');
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();
setTimeout(function() {
$('.product_added_to_cart').hide();

View File

@ -86,7 +86,20 @@
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');
{/literal}
@ -154,6 +167,17 @@
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>
{/literal}
{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}";
{literal}
// Function to submit carrier and send the information to GA
function submitCarrier() {
var cgv = acceptCGV();
if(cgv) {

View File

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