var gc_googletagmanager_ajax = "https:\/\/waschkultur.shop\/module\/gc_googletagmanager\/ajax?ajax=1"; var gc_eventsListenGt = {"add_to_cart":{"className":"[data-button-action=\"add-to-cart\"], body#cart .btn.bootstrap-touchspin-up","func":true},"go_to_cart":{"className":".cart-content-btn .btn.btn-primary, .blockcart.cart-preview a","event":"click"},"shopping_cart_events":{"className":"","event":"","func":true},"add_promo_code":{"className":"","event":"","func":true},"begin_checkout":{"className":".card.cart-summary .checkout a.btn.btn-primary","event":"click"},"go_to_wishlist":{"className":".wishlist-nav a","event":"click"},"add_to_wishlist":{"className":".wishlist-button-add","event":"click","func":true},"remove_from_wishlist":{"className":".wishlist-button-add, .wishlist-button-remove","event":"click","func":true},"view_item_list":{"className":"#top-menu a","event":"click","func":true},"search":{"className":"#search_widget form","event":"submit","func":true},"step1_link_guest":{"className":"#checkout-personal-information-step a[data-target=\"#checkout-guest-form\"],#checkout-personal-information-step a[href=\"#checkout-guest-form\"]","event":"click"},"step1_link_signin":{"className":"#checkout-personal-information-step a[data-target=\"#checkout-login-form\"],#checkout-personal-information-step a[href=\"#checkout-login-form\"]","event":"click"},"step1_input_firstname":{"className":"#checkout-personal-information-step input[name=\"firstname\"]","event":"change"},"step1_input_lastname":{"className":"#checkout-personal-information-step input[name=\"lastname\"]","event":"change"},"step1_input_email_create":{"className":"#checkout-personal-information-step #checkout-guest-form input[name=\"email\"]","event":"change"},"step1_radio_gender":{"className":"#checkout-personal-information-step input[name=\"id_gender\"]","event":"change"},"step1_input_company":{"className":"#checkout-personal-information-step input[name=\"company\"]","event":"change"},"step1_input_siret":{"className":"#checkout-personal-information-step input[name=\"siret\"]","event":"change"},"step1_input_password_create":{"className":"#checkout-personal-information-step #checkout-guest-form input[name=\"password\"]","event":"change"},"step1_button_continue_create":{"className":"#checkout-personal-information-step #checkout-guest-form button[name=\"continue\"]","event":"click"},"step1_input_birthday":{"className":"#checkout-personal-information-step input[name=\"birthday\"]","event":"change"},"step1_checkbox_optin_on":{"className":"#checkout-personal-information-step input[name=\"optin\"]","event":"change","val":1},"step1_checkbox_optin_off":{"className":"#checkout-personal-information-step input[name=\"optin\"]","event":"change","val":0},"step1_checkbox_privacy_on":{"className":"#checkout-personal-information-step input[name=\"customer_privacy\"]","event":"change","val":1},"step1_checkbox_privacy_off":{"className":"#checkout-personal-information-step input[name=\"customer_privacy\"]","event":"change","val":0},"step1_checkbox_newsletter_on":{"className":"#checkout-personal-information-step input[name=\"newsletter\"]","event":"change","val":1},"step1_checkbox_newsletter_off":{"className":"#checkout-personal-information-step input[name=\"newsletter\"]","event":"change","val":0},"step1_checkbox_psgdpr_on":{"className":"#checkout-personal-information-step input[name=\"psgdpr\"]","event":"change","val":1},"step1_checkbox_psgdpr_off":{"className":"#checkout-personal-information-step input[name=\"psgdpr\"]","event":"change","val":0},"step1_input_email_login":{"className":"#checkout-personal-information-step #checkout-login-form input[name=\"email\"]","event":"change"},"step1_input_password_login":{"className":"#checkout-personal-information-step #checkout-login-form input[name=\"password\"]","event":"change"},"step1_link_forgot_pw":{"className":"#checkout-personal-information-step #checkout-login-form .forgot-password a","event":"click"},"step1_button_continue_login":{"className":"#checkout-personal-information-step #checkout-login-form button[name=\"continue\"]","event":"click"},"step2_radio_id_address_delivery":{"className":"#checkout-addresses-step #delivery-addresses input[name=\"id_address_delivery\"]","event":"change"},"step2_link_edit_address":{"className":"#checkout-addresses-step #delivery-addresses .edit-address","event":"click"},"step2_link_delete_address":{"className":"#checkout-addresses-step #delivery-addresses .delete-address","event":"click"},"step2_add_address":{"className":"#checkout-addresses-step .add-address a","event":"click"},"step2_link_different_invoice_address":{"className":"#checkout-addresses-step a[data-link-action=\"different-invoice-address\"]","event":"click"},"step2_radio_id_address_invoice":{"className":"#checkout-addresses-step #invoice-addresses input[name=\"id_address_invoice\"]","event":"click"},"add_address_info":{"className":"#checkout-addresses-step button[name=\"confirm-addresses\"]","event":"click"},"step3_radio_delivery_option":{"className":"#checkout-delivery-step input[name^=\"delivery_option\"]","event":"change"},"step3_input_delivery_message":{"className":"#checkout-delivery-step textarea[name=\"delivery_message\"]","event":"change"},"add_shipping_info":{"className":"#checkout-delivery-step button[name=\"confirmDeliveryOption\"]","event":"click"},"step4_payment_option":{"className":"#checkout-payment-step input[name^=\"payment-option\"]","event":"change"},"step4_checkbox_conditions_on":{"className":"#checkout-payment-step input[name=\"conditions_to_approve[terms-and-conditions]\"]","event":"change","val":1},"step4_checkbox_conditions_off":{"className":"#checkout-payment-step input[name=\"conditions_to_approve[terms-and-conditions]\"]","event":"change","val":0},"step4_checkbox_gdpr_on":{"className":"#checkout-payment-step input[name=\"conditions_to_approve[gdpr-delivery]\"]","event":"change","val":1},"step4_checkbox_gdpr_off":{"className":"#checkout-payment-step input[name=\"conditions_to_approve[gdpr-delivery]\"]","event":"change","val":0},"step4_link_edit_addresses":{"className":"#order-summary-content .step-to-addresses","event":"click","firstOrderListen":1},"step4_link_edit_shipping":{"className":"#order-summary-content .step-to-delivery","event":"click","firstOrderListen":1},"step4_checkbox_virtual_on":{"className":"#checkout-payment-step input[name=\"conditions_to_approve[virtual-products]\"]","event":"change","val":1},"step4_checkbox_virtual_off":{"className":"#checkout-payment-step input[name=\"conditions_to_approve[virtual-products]\"]","event":"change","val":0},"checkout_steps":{"className":false,"func":true},"add_payment_info":{"className":"#payment-confirmation button[type=\"submit\"]","event":"click"},"share_wishlist":{"className":".wishlist-share-button","event":"click"},"go_to_login":{"className":"header .user-info > a","event":"click"},"login":{"className":"#login-form","event":"submit"},"password_forgotten":{"className":"#login-form .forgot-password a","event":"click"},"create_account":{"className":".no-account a","event":"click"},"sign_up":{"className":".register-form form#customer-form","event":"submit"}}; const gcGoogleActions = { /** * Store current products in the cart */ cacheCartProducts: [], /** * Store query string for search form */ cacheSearchValue: '', getCachedCardProductById: function (idProduct, idProductAttribute = 0, idCustomization = 0) { for (var i = 0; i < gcGoogleActions.cacheCartProducts.length; i++) { if ( gcGoogleActions.cacheCartProducts[i].id_product == idProduct && gcGoogleActions.cacheCartProducts[i].id_product_attribute == idProductAttribute && gcGoogleActions.cacheCartProducts[i].id_customization == idCustomization ) { return gcGoogleActions.cacheCartProducts[i]; } } return false; }, updateCacheCartProducts: function (products) { gcGoogleActions.cacheCartProducts = []; products.forEach(function (p) { gcGoogleActions.cacheCartProducts.push({ id_product: +p.id_product, id_product_attribute: +p.id_product_attribute, id_customization: +p.id_customization, quantity: +p.quantity, }); }); }, setActionAddPromoCode: function (eventGt, className = '') { prestashop.on( 'updateCart', function (event) { let couponName = $('input[name="discount_name"]').val(); if (event && event.reason) { if (event.reason.linkAction == 'add-voucher') { // define coupons var coupons = []; if (typeof event.resp.cart.vouchers.added != 'undefined') { for (var idx in event.resp.cart.vouchers.added) { coupons.push(event.resp.cart.vouchers.added[idx].code); } } dataLayer.push({ 'event': eventGt, 'ecommerce': { value_items: event.resp.cart.subtotals.products.amount, discount: event.resp.cart.subtotals.discounts.amount, value: event.resp.cart.totals.total.amount, coupon: coupons.join('|'), } }); } } } ); }, setActionShoppingCartEvents: function () { // check the current page is cart page if (document.querySelector('body').getAttribute('id') != 'cart') { return; } // set event for all ajax requests $(document).on('ajaxComplete', function(event, xhr, settings) { // check ajax URL if (!!settings.url == false || settings.url.indexOf(prestashop.urls.pages.cart) == -1) { return; } var response = xhr.responseJSON; if (!!response == false) { return; } // check that the action is remove from cart (decrease quantity) var isDownAction = (settings.url.indexOf('update=1') != -1 && settings.url.indexOf('op=down') != -1) || (typeof settings.data == 'string' && settings.data.indexOf('action=update') != -1 && settings.data.indexOf('op=down') != -1); // check that the action is add to cart (increase quantity) var isUpAction = (settings.url.indexOf('update=1') != -1 && settings.url.indexOf('op=up') != -1) || (typeof settings.data == 'string' && settings.data.indexOf('action=update') != -1 && settings.data.indexOf('op=up') != -1); // check that the action is remove from cart (totaly delete product) var isDeleteAction = isDownAction == false && settings.url.indexOf('delete=1') != -1; if (!isDownAction && !isDeleteAction && !isUpAction) { return; } // define item quantity var quantity = 1; if (isDeleteAction) { var product = gcGoogleActions.getCachedCardProductById( response.id_product, response.id_product_attribute, response.id_customization ); if (!product) { return; } quantity = product.quantity; } // clear the previous ecommerce object dataLayer.push({"ecommerce": null}); var eventGt = 'remove_from_cart'; if (isUpAction) { eventGt = 'add_to_cart'; } gcGoogleActions.ajaxProcess(eventGt, { requestParams: { action: 'presentProductForEcommerce', event: eventGt, id_product: response.id_product, id_product_attribute: response.id_product_attribute, qty: quantity, id_customization: response.id_customization, } }, function (response) { if (!!response && response.status == 200) gcGoogleActions.updateCacheCartProducts(prestashop.cart.products); }); }); }, setActionAddToCart: function (eventGt) { // handle add to cart button prestashop.on( 'updateCart', function (event) { if (event && event.reason) { if (event.reason.linkAction == 'add-to-cart' && event.resp.success) { // clear the previous ecommerce object dataLayer.push({"ecommerce": null}); // handle add to cart event gcGoogleActions.ajaxProcess(eventGt, { jsNameVariablePage: [ 'gcGoogleActions.cacheCartProducts' // 'prestashop.cart.products' ] }); // update products cache gcGoogleActions.updateCacheCartProducts(prestashop.cart.products); } } } ); }, setActionSearch: function (eventGt, className) { $('body').on('submit', className, function (e) { dataLayer.push({ 'event': 'search', 'search_term': $(className + ' input[name="s"]').val().trim(), }); }); $('body').on('keyup', className + ' input[name="s"]', function (e) { gcGoogleActions.cacheSearchValue = this.value; }); $('body').on('click', '.ui-autocomplete.searchbar-autocomplete a', function (e) { dataLayer.push({ 'event': 'search', 'search_term': gcGoogleActions.cacheSearchValue, // get product name from search list and set as search_term 'search_item_name': e.target.innerText.trim(), }); }); }, setActionCheckoutSteps: function (eventGt, selector) { // define current step var currentStep = document.querySelector('.checkout-step.-current'); if (!currentStep) { return; } $('body').on('click', '#checkout-personal-information-step .step-title', function () { var eventName = 'step2_link_edit_personal_info'; if (currentStep.getAttribute('id') == 'checkout-delivery-step') { eventName = 'step3_link_edit_personal_info'; } else if (currentStep.getAttribute('id') == 'checkout-payment-step') { eventName = 'step4_link_edit_personal_info'; } // update current step currentStep = document.querySelector('.checkout-step.-current'); // push GA event dataLayer.push({'event': eventName}); }); $('body').on('click', '#checkout-addresses-step .step-title', function () { var eventName = 'step3_link_edit_address_info'; if (currentStep.getAttribute('id') == 'checkout-payment-step') { eventName = 'step4_link_edit_address_info'; } // update current step currentStep = document.querySelector('.checkout-step.-current'); // push GA event dataLayer.push({'event': eventName}); }); $('body').on('click', '#checkout-delivery-step .step-title', function () { // update current step currentStep = document.querySelector('.checkout-step.-current'); // push GA event dataLayer.push({'event': 'step4_link_edit_shipping_info'}); }); }, setActionViewItemList: function (eventGt, className = '') { let bodyTag = document.getElementsByTagName('body'); if (!bodyTag || bodyTag[0].getAttribute('id') != 'category') { const isElementLoaded = async selector => { while (document.querySelector(selector) === null) { await new Promise(resolve => requestAnimationFrame(resolve)) } return document.querySelector(selector); }; isElementLoaded(className).then((selector) => { var elementEvent = document.querySelectorAll(className); elementEvent.forEach(function (element) { element.addEventListener("click", (event) => { dataLayer.push({'event': eventGt}); }); }); }); } // declare handler for products filter on the category page // to handle products filtering prestashop.on('updateProductList', (event) => { // if products not found if (typeof event.products == 'undefined' || event.products.length == 0) { // reset items list for the event view_item_list dataLayer.push({ 'event': eventGt, 'ecommerce': {items: null} }); return; } // clear the previous ecommerce object dataLayer.push({"ecommerce": null}); let id_category = 0; let category_body_class = bodyTag[0].getAttribute('class').match(/category-id-([0-9]{1,})/g); if (category_body_class) { id_category = category_body_class[0].replace('category-id-', ''); } // handle add to cart event gcGoogleActions.ajaxProcess(eventGt, { requestParams: { id_category: id_category, products: event.products.map((product) => { return { id_product: product.id_product, }; }), } }); }); }, setActionAddToWishlist: function (eventGt, className = '') { $(document).on('click', className, function () { if ($(this).attr('data-id-wishlist') == 0) { dataLayer.push({'event': eventGt}); } }); }, setActionRemoveFromWishlist: function (eventGt, className = '') { $(document).on('click', className, function () { if ( $(this).attr('data-id-wishlist') > 0 || $(this).hasClass('wishlist-button-remove') ) { dataLayer.push({'event': eventGt}); } }); }, setActionViewPromotion: function (eventGt) { var banners = [ { used: false, module: 'ps_imageslider', selector: '#carousel.carousel', activeSlideSelector: '.carousel-item.active', slideSelector: '.carousel-item', imageSelector: 'img', urlSelector: 'a', nameSelector: 'figcaption h2', promotionId: false, }, { used: false, module: 'gc_banner', selector: '.gcbanner-container.slider, #gcbanner-container', activeSlideSelector: '.banner_item.gcbanner1_on, .carousel-item.active', slideSelector: '.carousel-item', imageSelector: 'img', urlSelector: 'a', nameSelector: '.caption h2, figcaption h2', promotionId: false, }, { used: false, module: 'ps_banner', selector: '.page-home a.banner', activeSlideSelector: false, slideSelector: false, imageSelector: 'img', urlSelector: false, nameSelector: false, promotionId: 'PS Home Banner', }, ]; function promotions () { for (var i = 0; i < banners.length; i++) { // ignore used banners if (banners[i].used) continue; var element = $(banners[i].selector); // ignore not found banners if (element.length == 0) continue; if (gcGoogleActions.isElementVisible(element)) { // lock banner banners[i].used = true; if (banners[i].slideSelector) { element.find(banners[i].slideSelector).each(function (index) { // console.log(arguments); var slide = $(this); var imageName = slide.find(banners[i].imageSelector).first(); imageName = imageName.length ? imageName.attr('src').substr((imageName.attr('src').lastIndexOf("/") + 1)).split('?')[0] : 'unknown'; dataLayer.push({ event: eventGt, ecommerce: null, // clear the ecommerce object creative_name: imageName, creative_slot: banners[i].module, promotion_id: (index + 1), promotion_url: banners[i].urlSelector ? slide.find(banners[i].urlSelector).attr('href') : (slide.attr('href') ? slide.attr('href') : false), promotion_name: banners[i].nameSelector ? slide.find(banners[i].nameSelector).text() : (slide.attr('title') ? slide.attr('title') : ''), items: [], }); }); } else { var imageName = element.find(banners[i].imageSelector).first(); // push event dataLayer.push({ event: eventGt, ecommerce: null, // clear the ecommerce object creative_name: (imageName.length ? imageName.attr('src').substr((imageName.attr('src').lastIndexOf("/") + 1)).split('?')[0] : 'unknown'), creative_slot: banners[i].module, promotion_id: banners[i].promotionId, promotion_url: (element.attr('href') ? element.attr('href') : false), promotion_name: (element.attr('title') ? element.attr('title') : ''), items: [], }); } // flush the promotion options to prevent their imitation in future events dataLayer.push({ creative_name: null, creative_slot: null, promotion_id: null, promotion_url: null, promotion_name: null, items: [], }); } } } // set scroll event for window document.addEventListener('scroll', promotions); promotions(); }, setActionViewPromotionList: function (eventGt) { // search products with discount var discountProducts = []; $(".discount-percentage.discount-product").each(function () { var wraper = $(this).closest('.product-miniature'); if (wraper.length == 0) return; // ignore duplicated products if (discountProducts.map(function (p) { return p.id_product; }).indexOf(wraper.data('id-product')) != -1) return; discountProducts.push({ id_product: wraper.data('id-product'), id_product_attribute: wraper.data('id-product-attribute'), }); }); gcGoogleActions.ajaxProcess(eventGt, { requestParams: { action: 'buildItemsListForEcommerce', event: eventGt, products: discountProducts } }, function (response) { // clear the previous ecommerce object dataLayer.push({ecommerce: null}); // push event response.items.length > 0 && dataLayer.push({ event: eventGt, items: response.items, }); }); }, ajaxProcess: function (eventGt, ajaxParams, callback) { if (typeof gc_googletagmanager_ajax === 'undefined') { Console.log('ERROR! Not find ajax url') } let paramRequest = { action: eventGt, }; if (typeof ajaxParams.jsNameVariablePage !== 'undefined') { ajaxParams.jsNameVariablePage.forEach((variable) => { let globalVar = null; let variables = Array.isArray(variable) ? variable : variable.split('.'); variables.forEach((variabled) => { if (!globalVar) { globalVar = window[variabled]; return; } if (globalVar[variabled]) { globalVar = globalVar[variabled]; } else { Console.log('ERROR! Not find global variable: ' + variabled) } }); if (globalVar) { let keyName = variable.replaceAll('.', '_') paramRequest[keyName] = globalVar; } }) } else if (typeof ajaxParams.requestParams != 'undefined') { paramRequest = Object.assign({}, paramRequest, ajaxParams.requestParams); } $.ajax({ url: gc_googletagmanager_ajax, type: "POST", dataType: 'json', data: paramRequest, success: function success(response) { typeof response.dataLayer != 'undefined' && dataLayer.push(response.dataLayer); if (typeof callback == 'function') callback(response); }, error: function error(err) { console.log(err); } }); }, setDefault: function (eventGt, parameters) { var functionName = 'on'; if (typeof parameters.firstOrderListen !== 'undefined' && parameters.firstOrderListen === 1) { functionName = 'bindFirst'; } $('body')[functionName](parameters.event, parameters.className, function (event) { if (typeof parameters.val !== 'undefined') { let val = null; if ($(this).prop('type') == 'checkbox') { val = $(this).is(':checked') ? 1 : 0; } else { val = $(this).val() } if (parameters.val === val) { dataLayer.push({'event': eventGt}); } return; } if (typeof parameters.ajax !== 'undefined') { let ajaxParams = (typeof parameters.ajaxParams !== 'undefined') ? parameters.ajaxParams : false; gcGoogleActions.ajaxProcess(eventGt, ajaxParams); return; } dataLayer.push({'event': eventGt}); }); }, isElementVisible: function (element, fully) { var w = $(window); var wTop = w.scrollTop(); var wBottom = wTop + w.height(); var eTop = element.offset().top; var eBottom = eTop + element.height(); return (fully === true) ? ((wTop < eTop) && (wBottom > eBottom)) : ((eTop <= wBottom) && (eBottom >= wTop)) ; }, } window.addEventListener('load', function () { $.fn.bindFirst = function (name, className, fn) { this.find(className).each((key, element) => { $(element).bind(name, fn); var handlers = $._data(element, "events")[name.split('.')[0]]; var handler = handlers.pop(); handlers.splice(0, 0, handler); }); }; if (typeof gc_eventsListenGt !== 'undefined') { Object.entries(gc_eventsListenGt).forEach(([eventGt, parameters]) => { if (typeof parameters.func !== 'undefined' && parameters.func) { var functionName = 'setAction' + eventGt.split(/_/).map(word => word[0].toUpperCase() + word.substring(1)).join(''); if (typeof gcGoogleActions[functionName] !== 'undefined') { gcGoogleActions[functionName](eventGt, parameters.className); } } else { gcGoogleActions.setDefault(eventGt, parameters); } }); } // define GA as global variable window['gcGoogleActions'] = gcGoogleActions; // set current car products gcGoogleActions.updateCacheCartProducts(prestashop.cart.products); if (typeof gc_googletagmanager_confirmation !== 'undefined') { window.dataLayer = window.dataLayer || []; dataLayer.push(gc_googletagmanager_confirmation); } }); window.dataLayer = window.dataLayer || []; dataLayer.push({ "currencyCode": "EUR", "ecommerce": {}, "event": null, "google_tag_params": {}, "pageCategory": null, "purchase": null, "userGroups": [], "userId": 0, "userLogged": false, "transactionId": null, "transactionAffiliation": null, "transactionTotal": null, "transactionTax": null, "transactionShipping": null, "transactionProducts": null });