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]);
}
@ -619,9 +619,25 @@ 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);
@ -633,6 +649,8 @@ function confirmation(idProduct, idCombination, quantity) {
}
$('.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');}
});

View File

@ -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}