1202 lines
42 KiB
JavaScript
1202 lines
42 KiB
JavaScript
/*
|
|
* 2012-2022 Patryk Marek PrestaDev.pl
|
|
*
|
|
* Patryk Marek PrestaDev.pl - PD Google Analytycs 4.0 Pro 1.6.x and 1.7.x Module © All rights reserved.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit, modify or copy this file.
|
|
* If you wish to customize it, contact us at info@prestadev.pl.
|
|
*
|
|
* @author Patryk Marek <info@prestadev.pl>
|
|
* @copyright 2012-2022 Patryk Marek @ PrestaDev.pl
|
|
* @license Do not edit, modify or copy this file, if you wish to customize it, contact us at info@prestadev.pl.
|
|
* @link http://prestadev.pl
|
|
* @package PD Google Analytycs 4.0 Pro 1.6.x and 1.7.x Module
|
|
* @version 1.0.2
|
|
* @date 01-05-2021
|
|
*/
|
|
|
|
$(document).ready(function() {
|
|
|
|
let pdgoogleanalytycs4pro_quantity_wanted = 1,
|
|
PdDelayFunction = (function () {
|
|
var timer = 0;
|
|
return function (callback, ms) {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(callback, ms);
|
|
};
|
|
})();
|
|
|
|
// supercheckout send carrier and payment default selections events
|
|
if ($("body#module-supercheckout-supercheckout").length > 0) {
|
|
|
|
PdDelayFunction(function () {
|
|
|
|
let id_carrier = parseInt($('input.delivery_option_radio:checked').val());
|
|
if (typeof(id_carrier) !== 'undefined'){
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addDeliveryInfo', 'id_carrier': id_carrier, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
let payment_module = $('input[name=payment_method]:checked').data('module-name');
|
|
if (typeof(payment_module) !== 'undefined'){
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addPaymentInfo', 'payment_module': payment_module, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
}, 1500);
|
|
}
|
|
|
|
// supercheckout
|
|
$("body#module-supercheckout-supercheckout").on("click", "input.delivery_option_radio:checked", function() {
|
|
let id_carrier = parseInt(this.value);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addDeliveryInfo', 'id_carrier': id_carrier, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// supercheckout
|
|
$("body#module-supercheckout-supercheckout").on("click", "input[name=payment_method]:checked", function() {
|
|
let payment_module = $(this).data('module-name');
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addPaymentInfo', 'payment_module': payment_module, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
// thecheckout send carrier and payment default selections events
|
|
if ($("body#module-thecheckout-order").length > 0) {
|
|
|
|
PdDelayFunction(function () {
|
|
|
|
let id_carrier = parseInt($('input[type=radio][name^=delivery_option]:checked').val());
|
|
|
|
if (typeof(id_carrier) !== 'undefined'){
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addDeliveryInfo', 'id_carrier': id_carrier, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
let payment_module = $('input[name=payment-option]:checked').data('module-name');
|
|
|
|
if (typeof(payment_module) !== 'undefined'){
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addPaymentInfo', 'payment_module': payment_module, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
}, 1000);
|
|
}
|
|
|
|
$("body#module-thecheckout-order").on("click", "input[type=radio][name^=delivery_option]:checked", function() {
|
|
let id_carrier = parseInt(this.value);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addDeliveryInfo', 'id_carrier': id_carrier, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$("body#module-thecheckout-order").on("click", "input[name=payment-option]:checked", function() {
|
|
let payment_module = $(this).data('module-name');
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addPaymentInfo', 'payment_module': payment_module, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$("body#checkout").on( "change", '.delivery-options input[type="radio"]:checked', function() {
|
|
let id_carrier = parseInt(this.value);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addDeliveryInfo', 'id_carrier': id_carrier, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
let paymentRequestLock = false;
|
|
|
|
$("body#checkout").on("change", '.module_payment_container input[name="method_payment"]', function() {
|
|
if (paymentRequestLock) return; // blokuj powtórne wywołanie
|
|
paymentRequestLock = true;
|
|
setTimeout(() => paymentRequestLock = false, 1000); // odblokuj po sekundzie
|
|
|
|
let payment_module = $(this).val();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {
|
|
action: 'addPaymentInfo',
|
|
payment_module: payment_module,
|
|
secure_key: pdgoogleanalytycs4pro_secure_key,
|
|
ajax: true
|
|
},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// opc steasycheckout
|
|
$("body.module-steasycheckout-default").on("click", 'input[type=radio][name^=delivery_option]:checked', function() {
|
|
let id_carrier = parseInt(this.value);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addDeliveryInfo', 'id_carrier': id_carrier, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// opc steasycheckout
|
|
$("body.module-steasycheckout-default").on("click", 'input[name="payment-option"]:checked', function() {
|
|
let payment_module = $(this).data('module-name');
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'addPaymentInfo', 'payment_module': payment_module, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
if (data) {
|
|
$('#hook-display-before-carrier').append(data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
if (typeof(prestashop) !== 'undefined') {
|
|
|
|
//prestashop.on('changedCheckoutStep', function(params) {
|
|
// if (typeof(params.event.currentTarget.id) !== 'undefined') {
|
|
// let step = params.event.currentTarget.id,
|
|
// step_call_elm = params.event.target.id;
|
|
|
|
// if (step == 'checkout-payment-step' && step_call_elm != 'conditions_to_approve[terms-and-conditions]') {
|
|
|
|
// let payment_module = $('input[name="payment-option"]:checked').data('module-name');
|
|
|
|
// $.ajax({
|
|
// type: "POST",
|
|
// url: pdgoogleanalytycs4pro_ajax_link,
|
|
// data: {'action': 'addPaymentInfo', 'payment_module': payment_module, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax: true},
|
|
// dataType: "json",
|
|
// success: function(data) {
|
|
// if (data) {
|
|
// $('#hook-display-before-carrier').append(data);
|
|
// }
|
|
// }
|
|
// });
|
|
// }
|
|
// }
|
|
//});
|
|
|
|
if (pd_google_analitycs_controller != 'cart') {
|
|
prestashop.on('updateProduct', function(params) {
|
|
if (typeof(params) !== 'undefined') {
|
|
pdgoogleanalytycs4pro_quantity_wanted = $(params.event.currentTarget).val();
|
|
}
|
|
});
|
|
}
|
|
|
|
if (pd_google_analitycs_controller != 'cart') {
|
|
prestashop.on('updateCart', function(params) {
|
|
if (typeof(params) !== 'undefined' && typeof(prestashop.cart) !== 'undefined') {
|
|
|
|
let iso_code = prestashop.currency.iso_code,
|
|
product_id = params.reason.idProduct,
|
|
product_id_product_attribute = params.reason.idProductAttribute;
|
|
|
|
if (typeof(product_id) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined' && typeof(pdgoogleanalytycs4pro_quantity_wanted) !== 'undefined') {
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'updateCart', 'product_id': product_id, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: add_to_cart');
|
|
gtag('event', 'add_to_cart', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: pdgoogleanalytycs4pro_quantity_wanted
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// qty up > thecheckout module opc
|
|
$('body').on("click", "a.cart-line-product-quantity-up", function(e) {
|
|
|
|
let qty_input = $(this).parent().find('input.cart-line-product-quantity'),
|
|
updat_url = qty_input.attr('data-update-url'),
|
|
url_params = PdParseQuery(updat_url),
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
if (typeof(url_params.id_product) !== 'undefined' && typeof(url_params.id_product_attribute) !== 'undefined') {
|
|
var product_id_product = url_params.id_product;
|
|
var product_id_product_attribute = url_params.id_product_attribute;
|
|
}
|
|
|
|
if (typeof(product_id_product) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined') {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'updateCart', 'product_id': product_id_product, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: add_to_cart');
|
|
gtag('event', 'add_to_cart', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: 1
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// qty up > thecheckout module opc user entered value
|
|
$('body').on("keyup", "input.cart-line-product-quantity", function(e) {
|
|
|
|
PdDelayFunction(function () {
|
|
|
|
let qty_input = $('input.cart-line-product-quantity'),
|
|
qty_input_val = parseInt($('input.cart-line-product-quantity').val()),
|
|
updat_url = qty_input.attr('data-update-url'),
|
|
url_params = PdParseQuery(updat_url),
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
if (typeof(url_params.id_product) !== 'undefined' && typeof(url_params.id_product_attribute) !== 'undefined') {
|
|
var product_id_product = url_params.id_product;
|
|
var product_id_product_attribute = url_params.id_product_attribute;
|
|
}
|
|
|
|
if (typeof(product_id_product) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined' && qty_input_val > 0) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'updateCart', 'product_id': product_id_product, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: add_to_cart');
|
|
gtag('event', 'add_to_cart', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: qty_input_val
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}, 800);
|
|
});
|
|
|
|
// down qty > thecheckout module opc
|
|
$('body').on("click", "a.cart-line-product-quantity-down", function(e) {
|
|
|
|
let qty_input = $(this).parent().find('input.cart-line-product-quantity'),
|
|
updat_url = qty_input.attr('data-update-url'),
|
|
url_params = PdParseQuery(updat_url),
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
if (typeof(url_params.id_product) !== 'undefined' && typeof(url_params.id_product_attribute) !== 'undefined') {
|
|
var product_id_product = url_params.id_product;
|
|
var product_id_product_attribute = url_params.id_product_attribute;
|
|
}
|
|
|
|
if (typeof(product_id_product) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined') {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'updateCart', 'product_id': product_id_product, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: remove_from_cart');
|
|
gtag('event', 'remove_from_cart', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: 1
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
|
|
// qty up > stadard theme ps 17
|
|
$('body').on("click", "button.bootstrap-touchspin-up", function(e) {
|
|
|
|
let qty_input = $(this).parent().parent().find('input.cart-line-product-quantity'),
|
|
updat_url = qty_input.attr('data-update-url'),
|
|
url_params = PdParseQuery(updat_url),
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
|
|
if (typeof(url_params.id_product) !== 'undefined' && typeof(url_params.id_product_attribute) !== 'undefined') {
|
|
var product_id_product = url_params.id_product;
|
|
var product_id_product_attribute = url_params.id_product_attribute;
|
|
}
|
|
|
|
if (typeof(product_id_product) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined') {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'updateCart', 'product_id': product_id_product, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: add_to_cart');
|
|
gtag('event', 'add_to_cart', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: 1
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// qty down > stadard theme ps 17
|
|
$( 'body' ).on( "click", "button.bootstrap-touchspin-down", function(e) {
|
|
|
|
let qty_input = $(this).parent().parent().find('input.cart-line-product-quantity'),
|
|
updat_url = qty_input.attr('data-update-url'),
|
|
url_params = PdParseQuery(updat_url),
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
if (typeof(url_params.id_product) !== 'undefined' && typeof(url_params.id_product_attribute) !== 'undefined') {
|
|
var product_id_product = url_params.id_product;
|
|
var product_id_product_attribute = url_params.id_product_attribute;
|
|
}
|
|
|
|
if (typeof(product_id_product) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined') {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'productClick', 'product_id': product_id_product, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: remove_from_cart');
|
|
gtag('event', 'remove_from_cart', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: 1
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
$('body').on("click", ".js-product-miniature a.product_img_link", function(e) {
|
|
let product_container = $(this).parents('article'),
|
|
product_url = $(this).attr('href').trim(),
|
|
product_id = product_container.attr('data-id-product'),
|
|
product_id_product_attribute = product_container.attr('data-id-product-attribute');
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
if (typeof(product_id) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined' && typeof(product_url) !== 'undefined') {
|
|
e.preventDefault();
|
|
setTimeout(function () {
|
|
document.location = product_url;
|
|
}, 700);
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'productClick', 'product_id': product_id, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: select_item');
|
|
gtag('event', 'select_item', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: 1
|
|
}],
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// standard theme ps 1.7 select item
|
|
$('body').on("click", ".js-product-miniature a.thumbnail, .js-product-miniature .product-title a", function(e) {
|
|
|
|
|
|
let product_container = $(this).parents('article'),
|
|
product_url = $(this).attr('href').trim(),
|
|
product_id = product_container.attr('data-id-product'),
|
|
product_id_product_attribute = product_container.attr('data-id-product-attribute');
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
if (typeof(product_id) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined' && typeof(product_url) !== 'undefined') {
|
|
e.preventDefault();
|
|
|
|
setTimeout(function () {
|
|
document.location = product_url;
|
|
}, 700);
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'productClick', 'product_id': product_id, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: select_item');
|
|
gtag('event', 'select_item', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: 1
|
|
}],
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
|
|
// Transformer theme add to cart butons on product lists
|
|
$('body').on("click", ".ajax_add_to_cart_button", function(e) {
|
|
|
|
let article = $(this).parents('article.js-product-miniature'),
|
|
product_qty = parseInt(article.find('input[name=pro_quantity]').val()),
|
|
product_id = parseInt(article.attr('data-id-product')),
|
|
product_id_product_attribute = parseInt(article.attr('data-id-product-attribute')),
|
|
iso_code = prestashop.currency.iso_code;
|
|
|
|
|
|
if (typeof(product_id) !== 'undefined' && typeof(product_id_product_attribute) !== 'undefined') {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'updateCart', 'product_id': product_id, 'product_id_product_attribute' : product_id_product_attribute, 'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: add_to_cart');
|
|
gtag('event', 'add_to_cart', {
|
|
currency: iso_code,
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: '',
|
|
discount: data.content_discount,
|
|
index: '1',
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
affiliation: data.http_referer,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: product_qty ? product_qty : pdgoogleanalytycs4pro_quantity_wanted
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
prestashop.on('updateProduct', function(params) {
|
|
|
|
|
|
if (typeof(params) !== 'undefined' && params.eventType == 'updatedProductCombination') {
|
|
let iso_code = prestashop.currency.iso_code,
|
|
product_id = parseInt(document.getElementsByName('id_product')[0].value),
|
|
groups = [],
|
|
select_groups = document.getElementsByClassName('form-control-select'),
|
|
input_color_group = document.getElementsByClassName('input-color'),
|
|
input_radio_group = document.querySelector('.input-radio:checked');
|
|
|
|
if (typeof(select_groups) != 'undefined' && select_groups != null) {
|
|
for (select_count = 0; select_count < select_groups.length; select_count++) {
|
|
groups.push(select_groups[select_count].value);
|
|
}
|
|
}
|
|
|
|
if (typeof(input_color_group) != 'undefined' && input_color_group != null) {
|
|
for (color_count = 0; color_count < input_color_group.length; color_count++) {
|
|
if (input_color_group[color_count].checked) {
|
|
groups.push(input_color_group[color_count].value);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (typeof(input_radio_group) != 'undefined' && input_radio_group != null) {
|
|
for (radio_count = 0; radio_count < input_radio_group.length; radio_count++) {
|
|
if (input_radio_group[radio_count].checked) {
|
|
groups.push(input_radio_group[radio_count].value);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (typeof groups !== 'undefined' && groups.length > 0 && typeof product_id !== 'undefined') {
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: pdgoogleanalytycs4pro_ajax_link,
|
|
data: {'action': 'updateProduct', 'product_id': product_id, 'attributes_groups': groups,'secure_key': pdgoogleanalytycs4pro_secure_key, ajax : true},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log('Fired up event GA4: view_item on combination change');
|
|
PdSetEventFireUpDelay(250);
|
|
gtag('event', 'view_item', {
|
|
items: [{
|
|
item_id: data.content_ids,
|
|
item_name: data.content_name,
|
|
coupon: "",
|
|
discount: data.content_discount,
|
|
affiliation: data.http_referer,
|
|
item_list_name: pd_google_analitycs_controller,
|
|
item_list_id: pd_google_analitycs_controller,
|
|
item_brand: data.content_manufacturer,
|
|
item_category: data.content_category,
|
|
item_category2: (data.content_category2.length) ? data.content_category2 : '',
|
|
item_category3: (data.content_category3.length) ? data.content_category3 : '',
|
|
item_category4: (data.content_category4.length) ? data.content_category4 : '',
|
|
item_category5: (data.content_category5.length) ? data.content_category5 : '',
|
|
item_variant: data.content_variant,
|
|
price: data.content_value,
|
|
currency: iso_code,
|
|
quantity: 1
|
|
}],
|
|
value: data.content_value
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function PdSetEventFireUpDelay(ms) {
|
|
var cur_d = new Date();
|
|
var cur_ticks = cur_d.getTime();
|
|
var ms_passed = 0;
|
|
while(ms_passed < ms) {
|
|
var d = new Date();
|
|
var ticks = d.getTime();
|
|
ms_passed = ticks - cur_ticks;
|
|
}
|
|
}
|
|
|
|
function PdParseQuery(str) {
|
|
|
|
if(typeof str != "string" || str.length == 0) return {};
|
|
var s = str.split("&");
|
|
var s_length = s.length;
|
|
var bit, query = {}, first, second;
|
|
for(var i = 0; i < s_length; i++) {
|
|
bit = s[i].split("=");
|
|
first = decodeURIComponent(bit[0]);
|
|
if(first.length == 0) continue;
|
|
second = decodeURIComponent(bit[1]);
|
|
if(typeof query[first] == "undefined") query[first] = second;
|
|
else if(query[first] instanceof Array) query[first].push(second);
|
|
else query[first] = [query[first], second];
|
|
}
|
|
return query;
|
|
}
|
|
});
|
|
|
|
/* GA4: view_item_list + select_item (homepage + PDP) — finalna wersja */
|
|
(function (window, document) {
|
|
'use strict';
|
|
|
|
if (window.__ga4ItemListInit) return;
|
|
window.__ga4ItemListInit = true;
|
|
|
|
// === Funkcje wspólne ===
|
|
function isHomepage() {
|
|
var b = document.body;
|
|
return b && (b.id === 'index' || b.classList.contains('page-index') || b.classList.contains('index'));
|
|
}
|
|
function isProductPage() {
|
|
var b = document.body;
|
|
return b && (b.id === 'product' || b.classList.contains('page-product'));
|
|
}
|
|
function parsePrice(str) {
|
|
if (!str) return;
|
|
var s = String(str).replace(/\u00A0/g, ' ')
|
|
.replace(/zł|PLN/gi, '')
|
|
.trim()
|
|
.replace(/\s/g, '')
|
|
.replace(',', '.');
|
|
var p = parseFloat(s);
|
|
return isNaN(p) ? undefined : p;
|
|
}
|
|
function getPathSegment(url, idx) {
|
|
try {
|
|
var u = new URL(url, window.location.origin);
|
|
var seg = u.pathname.split('/').filter(Boolean);
|
|
return seg[idx] || undefined;
|
|
} catch (e) {
|
|
return;
|
|
}
|
|
}
|
|
function gtagEvent(name, params) {
|
|
if (typeof window.gtag === 'function') {
|
|
window.gtag('event', name, params || {});
|
|
} else {
|
|
window.dataLayer = window.dataLayer || [];
|
|
window.dataLayer.push({
|
|
'gtag_event_name': name,
|
|
'gtag_event_params': params || {}
|
|
});
|
|
}
|
|
}
|
|
function collectItems(section, cfg) {
|
|
var nodes = section.querySelectorAll(cfg.cardSelector);
|
|
var items = [];
|
|
nodes.forEach(function (card, i) {
|
|
var id = card.getAttribute('data-id-product');
|
|
var varId = card.getAttribute('data-id-product-attribute');
|
|
var nameEl = card.querySelector(cfg.nameSelector);
|
|
var name = nameEl ? nameEl.textContent.trim() : undefined;
|
|
var urlEl = card.querySelector(cfg.urlSelector);
|
|
var url = urlEl ? urlEl.getAttribute('href') : undefined;
|
|
var priceEl = card.querySelector(cfg.priceSelector);
|
|
var price = parsePrice(priceEl ? priceEl.textContent : '');
|
|
var item_category = url ? decodeURIComponent(getPathSegment(url, 0) || '') : undefined;
|
|
|
|
var item = {
|
|
item_id: id || undefined,
|
|
item_name: name || undefined,
|
|
index: i + 1,
|
|
item_list_id: cfg.list_id,
|
|
item_list_name: cfg.list_name,
|
|
price: price,
|
|
currency: 'PLN'
|
|
};
|
|
if (item_category) item.item_category = item_category;
|
|
if (varId && varId !== '0') item.item_variant = varId;
|
|
items.push(item);
|
|
});
|
|
return items;
|
|
}
|
|
function sendViewItemList(items, cfg) {
|
|
gtagEvent('view_item_list', {
|
|
item_list_id: cfg.list_id,
|
|
item_list_name: cfg.list_name,
|
|
items: items
|
|
});
|
|
}
|
|
function wireSelectItem(section, cfg) {
|
|
section.addEventListener('click', function (e) {
|
|
var anchor = e.target.closest(cfg.clickAnchorSelector);
|
|
if (!anchor) return;
|
|
var card = anchor.closest(cfg.cardSelector);
|
|
if (!card) return;
|
|
var nodes = section.querySelectorAll(cfg.cardSelector);
|
|
var idx = Array.prototype.indexOf.call(nodes, card);
|
|
if (idx < 0) return;
|
|
var items = collectItems(section, cfg);
|
|
var item = items[idx];
|
|
if (!item) return;
|
|
gtagEvent('select_item', {
|
|
item_list_id: cfg.list_id,
|
|
item_list_name: cfg.list_name,
|
|
items: [item]
|
|
});
|
|
});
|
|
}
|
|
|
|
// === Inicjalizacja sekcji ===
|
|
function initSection(cfg) {
|
|
if (cfg.when && !cfg.when()) return;
|
|
var section = document.querySelector(cfg.sectionSelector);
|
|
if (!section || section.__viewItemListSent) return;
|
|
|
|
var send = function () {
|
|
if (section.__viewItemListSent) return;
|
|
var items = collectItems(section, cfg);
|
|
if (items.length) {
|
|
sendViewItemList(items, cfg);
|
|
section.__viewItemListSent = true;
|
|
}
|
|
};
|
|
|
|
// homepage — dopiero po widoczności; PDP — od razu
|
|
if (cfg.deferByScroll) {
|
|
if ('IntersectionObserver' in window) {
|
|
var io = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting && entry.intersectionRatio >= 0.5) {
|
|
send();
|
|
io.disconnect();
|
|
}
|
|
});
|
|
}, { threshold: [0.5] });
|
|
io.observe(section);
|
|
} else {
|
|
if (document.readyState === 'loading')
|
|
document.addEventListener('DOMContentLoaded', send);
|
|
else send();
|
|
}
|
|
} else {
|
|
// natychmiast
|
|
send();
|
|
}
|
|
|
|
wireSelectItem(section, cfg);
|
|
}
|
|
|
|
// === Konfiguracje sekcji ===
|
|
var COMMON = {
|
|
cardSelector: '.product-miniature.js-product-miniature',
|
|
urlSelector: 'a.thumbnail.product-thumbnail',
|
|
priceSelector: '.product-price-and-shipping [itemprop="price"].price, .product-price-and-shipping .price',
|
|
clickAnchorSelector: '.product-miniature a'
|
|
};
|
|
|
|
// Homepage — "Super oferty" (tylko po widoczności)
|
|
var cfgFeatured = Object.assign({}, COMMON, {
|
|
when: isHomepage,
|
|
sectionSelector: 'section.featured-products',
|
|
list_name: 'Super oferty',
|
|
list_id: 'featured-products',
|
|
nameSelector: '[itemprop="name"]',
|
|
deferByScroll: true
|
|
});
|
|
|
|
// PDP — "Zobacz także" (natychmiast)
|
|
var cfgAccessories = Object.assign({}, COMMON, {
|
|
when: isProductPage,
|
|
sectionSelector: 'section.product-accessories',
|
|
list_name: 'Zobacz także',
|
|
list_id: 'product-accessories',
|
|
nameSelector: '[itemprop="name"]',
|
|
deferByScroll: false
|
|
});
|
|
|
|
// PDP — "Podobne produkty z tej samej kategorii" (natychmiast)
|
|
var cfgCategoryRelated = Object.assign({}, COMMON, {
|
|
when: isProductPage,
|
|
sectionSelector: 'section.category-products',
|
|
list_name: 'Podobne produkty z tej samej kategorii',
|
|
list_id: 'category-related',
|
|
nameSelector: '.product-title, [itemprop="name"]',
|
|
deferByScroll: false
|
|
});
|
|
|
|
// === Start ===
|
|
function start() {
|
|
initSection(cfgFeatured);
|
|
initSection(cfgAccessories);
|
|
initSection(cfgCategoryRelated);
|
|
}
|
|
|
|
if (document.readyState === 'loading')
|
|
document.addEventListener('DOMContentLoaded', start);
|
|
else
|
|
start();
|
|
|
|
})(window, document);
|
|
|
|
/* GA4: view_promotion + select_promotion dla #bonslick (homepage) */
|
|
(function (window, document) {
|
|
'use strict';
|
|
|
|
if (window.__ga4PromoInit) return;
|
|
window.__ga4PromoInit = true;
|
|
|
|
function isHomepage() {
|
|
var b = document.body;
|
|
return !!b && (b.id === 'index' || b.classList.contains('page-index') || b.classList.contains('index'));
|
|
}
|
|
if (!isHomepage()) return;
|
|
|
|
// gtag fallback do dataLayer, gdyby gtag nie był gotowy
|
|
function gtagEvent(name, params) {
|
|
if (typeof window.gtag === 'function') {
|
|
window.gtag('event', name, params || {});
|
|
} else {
|
|
window.dataLayer = window.dataLayer || [];
|
|
window.dataLayer.push({
|
|
'gtag_event_name': name,
|
|
'gtag_event_params': params || {}
|
|
});
|
|
}
|
|
}
|
|
|
|
var ROOT_SEL = '#bonslick';
|
|
var LINK_SEL = 'li.slick-slide:not(.slick-cloned) a.link-bonslick';
|
|
var ANY_LINK = 'a.link-bonslick';
|
|
var LOCATION = 'homepage_bonslick';
|
|
var sentView = false;
|
|
|
|
// Pomocnicze: wydłub nazwę kreatywu z <img> albo z src
|
|
function getCreativeName(imgEl) {
|
|
if (!imgEl) return undefined;
|
|
var alt = imgEl.getAttribute('alt');
|
|
if (alt && alt.trim()) return alt.trim();
|
|
var src = imgEl.getAttribute('data-src') || imgEl.getAttribute('src') || '';
|
|
if (!src) return undefined;
|
|
try {
|
|
var base = src.split('/').pop();
|
|
return base ? base.split('?')[0] : undefined;
|
|
} catch (e) { return undefined; }
|
|
}
|
|
|
|
// Zbierz unikalne slajdy (bez .slick-cloned) -> items[] do view_promotion
|
|
function collectPromoItems(container) {
|
|
var items = [];
|
|
var seenKey = Object.create(null);
|
|
|
|
var links = container.querySelectorAll(LINK_SEL);
|
|
links.forEach(function (a, i) {
|
|
var href = a.getAttribute('href') || '';
|
|
var title = a.getAttribute('title') || '';
|
|
var img = a.querySelector('img');
|
|
var creative = getCreativeName(img);
|
|
|
|
// klucz unikalności (href + creative)
|
|
var key = (href || '') + '|' + (creative || '');
|
|
if (seenKey[key]) return;
|
|
seenKey[key] = true;
|
|
|
|
items.push({
|
|
promotion_id: href || undefined, // ID jako docelowy URL
|
|
promotion_name: (title || creative || '').trim() || undefined,
|
|
creative_name: creative || undefined,
|
|
creative_slot: String(i + 1), // pozycja w sliderze (bez klonów)
|
|
location_id: LOCATION
|
|
});
|
|
});
|
|
|
|
return items;
|
|
}
|
|
|
|
// Przy kliknięciu w JEDEN slajd => select_promotion z 1 itemem
|
|
function buildClickedItem(anchor) {
|
|
var href = anchor.getAttribute('href') || '';
|
|
var title = anchor.getAttribute('title') || '';
|
|
var img = anchor.querySelector('img');
|
|
var creative = getCreativeName(img);
|
|
|
|
// Ustal slot z indeksu slajdu (bez klonów jeśli się da)
|
|
var li = anchor.closest('li.slick-slide');
|
|
var slot = undefined;
|
|
if (li) {
|
|
var container = anchor.closest(ROOT_SEL) || document;
|
|
var list = Array.prototype.slice.call(container.querySelectorAll(LINK_SEL));
|
|
var idx = list.indexOf(anchor);
|
|
if (idx >= 0) slot = String(idx + 1);
|
|
}
|
|
|
|
return [{
|
|
promotion_id: href || undefined,
|
|
promotion_name: (title || creative || '').trim() || undefined,
|
|
creative_name: creative || undefined,
|
|
creative_slot: slot,
|
|
location_id: LOCATION
|
|
}];
|
|
}
|
|
|
|
function fireViewPromotion(container) {
|
|
if (sentView) return;
|
|
var items = collectPromoItems(container);
|
|
if (!items.length) return;
|
|
gtagEvent('view_promotion', { items: items });
|
|
sentView = true;
|
|
}
|
|
|
|
function init() {
|
|
var root = document.querySelector(ROOT_SEL);
|
|
if (!root) return;
|
|
|
|
// 1) view_promotion: gdy slider wejdzie >=50% w viewport (po wyświetleniu)
|
|
if ('IntersectionObserver' in window) {
|
|
var io = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting && entry.intersectionRatio >= 0.5) {
|
|
fireViewPromotion(root);
|
|
io.disconnect();
|
|
}
|
|
});
|
|
}, { threshold: [0.5] });
|
|
io.observe(root);
|
|
} else {
|
|
// Fallback: wyślij po DOMContentLoaded (slider zwykle jest nad foldem)
|
|
fireViewPromotion(root);
|
|
}
|
|
|
|
// 2) select_promotion: delegacja kliknięcia (obsłuży także klony)
|
|
root.addEventListener('click', function (e) {
|
|
var a = e.target.closest(ANY_LINK);
|
|
if (!a || !root.contains(a)) return;
|
|
var items = buildClickedItem(a);
|
|
if (!items || !items.length) return;
|
|
gtagEvent('select_promotion', { items: items });
|
|
});
|
|
|
|
// 3) Gdy slick doda slajdy asynchronicznie — lekki watchdog z MutationObserver
|
|
if ('MutationObserver' in window) {
|
|
var mo = new MutationObserver(function () {
|
|
// jeśli jeszcze nie poszło, a pojawiły się slajdy — spróbuj wysłać
|
|
if (!sentView) {
|
|
var hasSlides = root.querySelector(LINK_SEL);
|
|
if (hasSlides && !('IntersectionObserver' in window)) {
|
|
fireViewPromotion(root);
|
|
}
|
|
}
|
|
});
|
|
mo.observe(root, { childList: true, subtree: true });
|
|
// rozłącz po wysłaniu
|
|
var stopWhenSent = setInterval(function(){
|
|
if (sentView) { mo.disconnect(); clearInterval(stopWhenSent); }
|
|
}, 1500);
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
|
|
})(window, document); |