PageSourceSearch

https://montessoriparatodos.es/modules/alcagtmplus/views/js/front.js

js montessoriparatodos.es collected 2026-10-03 23:15:00 UTC 14,532 bytes, 441 lines download raw bytes

1/**
2* 2007-2021 PrestaShop
3*
4* NOTICE OF LICENSE
5*
6* This source file is subject to the Academic Free License (AFL 3.0)
7* that is bundled with this package in the file LICENSE.txt.
8* It is also available through the world-wide-web at this URL:
9* http://opensource.org/licenses/afl-3.0.php
10* If you did not receive a copy of the license and are unable to
11* obtain it through the world-wide-web, please send an email
12* to [email protected] so we can send you a copy immediately.
13*
14* DISCLAIMER
15*
16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17* versions in the future. If you wish to customize PrestaShop for your
18* needs please refer to http://www.prestashop.com for more information.
19*
20*  @author    PrestaShop SA <[email protected]>
21*  @copyright 2007-2021 PrestaShop SA
22*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
23*  International Registered Trademark & Property of PrestaShop SA
24*
25* Don't forget to prefix your containers with your own identifier
26* to avoid any conflicts with others containers.
27*/
28
29
30var alcagtmplus = {
31
32	response: null,
33	pcommon: {
34		'ajax': 1,
35		'module_name': 'alcagtmplus',
36		'configure': 'alcagtmplus',
37		'token': alcagtmplus_params.token,
38		'rand': new Date().getTime()
39	},
40
41	ajaxCall: function(params, callback) {
42		if (typeof params.data != 'undefined') {
43			var contentType = false;
44			var processData = false;
45			var data = params.data;
46			delete params.data;
47			Object.assign(params, this.pcommon);
48			params.each(function(index, value) {
49				data.append(index, value);
50			});
51		} else {
52			var data = {};
53			Object.assign(data, this.pcommon, params);
54			if (typeof data.token != undefined) {
55				data.token = this.pcommon.token;
56			}
57		}
58		let xhr = new XMLHttpRequest;
59		xhr.open('POST', alcagtmplus_params.link + '&r=' + this.pcommon.rand, true);
60		xhr.addEventListener('readystatechange', function() {
61			if(this.readyState == XMLHttpRequest.DONE) {
62				if (!this.responseType ||
63					this.responseType === 'text'
64				) {
65					try {
66						var data = JSON.parse(this.response);
67					} catch {
68						var data = this.responseText;
69					}
70				} else if (this.responseType === 'document') {
71					var data = this.responseXML;
72				} else {
73					var data = this.response;
74				}
75				if (typeof callback != 'undefined') {
76					eval(callback + '(params, data)');
77				}
78			}
79		});
80		let formData = new FormData();
81		Object.keys(data).forEach(function(k) {
82			formData.append(k, data[k]);
83		});
84		xhr.send(formData);
85	},
86	getUrlParams(url) {
87		let params = {};
88		if (url.match(/\?.*/gm)) {
89			url = url.split('?')[1];
90		}
91		if (url.match(/&.*/gm)) {
92			url.split('&').forEach(function (pair) {
93				pair = (pair + '=').split('=').map(decodeURIComponent);
94				if (pair[0].length) {
95					params[pair[0]] = pair[1];
96				}
97			});
98		} else if (url.match(/=.*/gm)) {
99			pair = url.split('=').map(decodeURIComponent);
100			if (pair[0].length) {
101				params[pair[0]] = pair[1];
102			}
103		}
104		return params;
105	},
106	setConfig: function() {
107		// Universal Analytics property.
108		if (alcagtmplus_params.config.google_ua_enabled == 1 && alcagtmplus_params.config.google_ua_id != '') {
109			gtag('config', alcagtmplus_params.config.google_ua_id);
110			console.log('gtag|config|ua');
111			// Anonymize
112			if (alcagtmplus_params.config.google_anonymize_ip == 1) {
113				gtag('config', alcagtmplus_params.config.google_ua_id, {
114					'anonymize_ip': true
115				});
116				console.log('gtag|config|anonymize ip');
117			}
118			// Optimize
119			if (alcagtmplus_params.config.google_optimize_enabled == 1 && alcagtmplus_params.config.google_optimize_id != '') {
120				gtag('config', alcagtmplus_params.config.google_ua_id, {
121					'optimize_id': alcagtmplus_params.config.google_optimize_id
122				});
123				console.log('gtag|config|optimize');
124			}
125			// Customer ID
126			if (alcagtmplus_params.config.google_customer_id == 1 && alcagtmplus_params.id_customer) {
127				gtag('config', alcagtmplus_params.config.google_ua_id, {
128					'user_id': alcagtmplus_params.id_customer
129				});
130				console.log('gtag|config|customer');
131			}
132			document.addEventListener('click', function (e) {
133				if (e.target.hasAttribute('id') && e.target.getAttribute('id') == 'quantity_wanted') {
134					// Only for PS 1.6
135					if (alcagtmplus_params.config.google_ga4_begin_checkout == 1 && document.getElementById('cart_summary') && document.getElementById('cgv').checked == true) {
136						var params = {
137							'action': 'getCheckout',
138							'event': 'begin_checkout',
139							'retrieve': 'checkout'
140						};
141						alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
142					}
143				}
144			});
145		}
146		// Google Analytics 4 property.
147		if (alcagtmplus_params.config.google_ga4_enabled == 1 && alcagtmplus_params.config.google_ga4_id != '') {
148			gtag('config', alcagtmplus_params.config.google_ga4_id);
149			console.log('gtag|config|ga4');
150		}
151		// Google Ads
152		if (alcagtmplus_params.config.google_ads_enabled == 1 && alcagtmplus_params.config.google_ads_id != '') {
153			gtag('config', 'AW-' + alcagtmplus_params.config.google_ads_id);
154			console.log('gtag|config|ads');
155		}
156	},
157	evalEvents: function(url, params, response) {
158        // Is a add_to_cart event
159		if (( // PS 1.7
160				(typeof prestashop != 'undefined' && url == prestashop.urls.pages.cart) &&
161				typeof params.action != 'undefined'&&
162				params.action == 'update' &&
163				typeof params.id_product != 'undefined'&&
164				params.id_product > 0 &&
165				typeof params.qty != 'undefined'&&
166				params.qty > 0 &&
167				typeof response.success != 'undefined'&&
168				response.success
169			) ||
170			( // PS 1.6
171				params.controller == 'cart' && typeof params.add != 'undefined' && params.qty != 'undefined' && params.qty > 0
172			)
173		) {
174			if (typeof params.controller != 'undefined') {
175				delete params.controller;
176			}
177			params.action = 'getCart';
178			params.event = 'add_to_cart';
179			params.retrieve = 'cart';
180			alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
181		}
182		// Is a register_newsletter event
183		if (typeof params.email != 'undefined' &&
184			params.email != '' &&
185			typeof response.nw_error != 'undefined' &&
186			!response.nw_error
187		) {
188			var params = {
189				'event': 'register_newsletter',
190				'retrieve': 'value'
191			};
192			this.triggerEvent(params, response);
193		}
194    },
195	triggerEvent: function(params, data) {
196		if (typeof data[params.retrieve] != 'undefined') {
197			gtag('event', params.event, data[params.retrieve]);
198			console.log('gtag|event|' + params.event);
199			// Pending events
200			if (typeof data.pending != 'undefined') {
201				let sended = [];
202				for (k in data.pending) {
203					sended.push(k);
204					data.pending[k].forEach(function(obj) {
205						alcagtmplus.triggerEvent(
206							{'event': k,'retrieve': 'order'},
207							obj
208						);
209					});
210				}
211				if (sended.length > 0) {
212					alcagtmplus.ajaxCall({
213						'action': 'sendedEvents',
214						'events': sended
215					});
216				}
217			}
218			// Google Ads Events
219			if (alcagtmplus_params.config.google_ads_enabled == 1 &&
220				alcagtmplus_params.config.google_ads_id != ''
221			) {
222				if (params.event == 'purchase' && alcagtmplus_params.config.google_ads_purchase != '') {
223					var conversion = {
224						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_purchase,
225						'value': data[params.retrieve].value,
226						'currency': data[params.retrieve].currency,
227						'transaction_id': data[params.retrieve].transaction_id
228					};
229				} else if (params.event == 'add_to_cart' && alcagtmplus_params.config.google_ads_add_to_cart != '') {
230					var conversion = {
231						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_add_to_cart,
232						'value': data[params.retrieve].value,
233						'currency': data[params.retrieve].currency
234					};
235				} else if (params.event == 'view_item' && alcagtmplus_params.config.google_ads_view_product != '') {
236					var conversion = {
237						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_view_product,
238						'value': data[params.retrieve].value,
239						'currency': data[params.retrieve].currency
240					};
241				} else if (params.event == 'begin_checkout' && alcagtmplus_params.config.google_ads_begin_checkout != '') {
242					var conversion = {
243						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_begin_checkout,
244						'value': data[params.retrieve].value,
245						'currency': data[params.retrieve].currency
246					};
247				} else if (params.event == 'register_customer' && alcagtmplus_params.config.google_ads_create_account != '') {
248					var conversion = {
249						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_create_account,
250						'value': 1,
251						'currency': data[params.retrieve].currency
252					};
253				}
254				if (typeof conversion != 'undefined') {
255					gtag('event', 'conversion', conversion);
256					console.log('ads|conversion|'+params.event);
257				}
258			}
259		}
260	},
261	dataLayerPush: function(params, data) {
262		if (typeof dataLayer != 'undefined' && typeof data.order != 'undefined') {
263			dataLayer.push(data.order);
264			console.log('gtag|datalayer|add');
265		}
266	},
267	triggerEvents: function() {
268		// Events setted on head variables
269		if (typeof alcagtmplus_events != 'undefined' && Object.keys(alcagtmplus_events).length > 0) {
270			Object.keys(alcagtmplus_events).forEach(function (name) {
271				if (name == 'datalayer') {
272					var params = {};
273					var response = {'order': alcagtmplus_events[name]};
274					alcagtmplus.dataLayerPush(params, response);
275				} else {
276					gtag('event', name, alcagtmplus_events[name]);
277					console.log('gtag|event|' + name);
278				}
279			});
280		// Events evaluated by conditions
281		} else {
282			// Is product page
283			if (document.getElementById('product') &&
284				document.getElementById('product').nodeName.toLowerCase() == 'body' &&
285				document.getElementsByName('id_product') &&
286				alcagtmplus_params.config.google_ga4_view_item == 1
287			) {
288				var id_product = document.getElementsByName('id_product')[0].value;
289				var id_product_attribute = alcagtmplus_params.id_product_attribute;
290				var params = {
291					'action': 'getProduct',
292					'id_product': id_product,
293					'id_product_attribute': id_product_attribute,
294					'event': 'view_item',
295					'retrieve': 'product'
296				};
297				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
298			}
299			// Is category page
300			if (document.getElementById('category') &&
301				document.getElementById('category').nodeName.toLowerCase() == 'body' &&
302				alcagtmplus_params.id_category &&
303				alcagtmplus_params.config.google_ga4_view_item_list == 1
304			) {
305				var page = alcagtmplus_params.page ? alcagtmplus_params.page : 1;
306				var params = {
307					'action': 'getCategory',
308					'id_category': alcagtmplus_params.id_category,
309					'page': page,
310					'event': 'view_item_list',
311					'retrieve': 'category'
312				};
313				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
314			}
315			// Is cart page
316			if (alcagtmplus_params.config.google_ga4_view_cart == 1 &&
317				(
318					( // PS 1.7
319						document.getElementById('cart') &&
320						document.getElementById('cart').nodeName.toLowerCase() == 'body'
321					) ||
322					( // PS 1.6
323						document.getElementById('cart_summary')
324					)
325				)
326			) {
327				var params = {
328					'action': 'getCart',
329					'event': 'view_cart',
330					'retrieve': 'cart'
331				};
332				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
333			}
334			// Is checkout page
335			if (document.getElementById('checkout') &&
336				document.getElementById('checkout').nodeName.toLowerCase() == 'body' &&
337				alcagtmplus_params.config.google_ga4_begin_checkout == 1
338			) {
339				var params = {
340					'action': 'getCheckout',
341					'event': 'begin_checkout',
342					'retrieve': 'checkout'
343				};
344				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
345			}
346			// Is order confirmation page
347			if (document.getElementById('order-confirmation') &&
348				document.getElementById('order-confirmation').nodeName.toLowerCase() == 'body' &&
349				(alcagtmplus_params.id_order || alcagtmplus_params.id_cart)
350			) {
351				if (alcagtmplus_params.config.google_ga4_purchase) {
352					var params = {
353						'action': 'getOrder',
354						'event': 'purchase',
355						'retrieve': 'order',
356						'id_order': alcagtmplus_params.id_order,
357						'id_cart': alcagtmplus_params.id_cart
358					};
359					alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
360				}
361				if (alcagtmplus_params.config.google_gtm_enabled) {
362					var params = {
363						'action': 'getDatalayerOrder',
364						'retrieve': 'order',
365						'id_order': alcagtmplus_params.id_order,
366						'id_cart': alcagtmplus_params.id_cart
367					};
368					alcagtmplus.ajaxCall(params, 'alcagtmplus.dataLayerPush');
369				}
370			}
371			// Is new customer
372			if (alcagtmplus_params.new_customer) {
373				var params = {
374					'action': 'getCustomer',
375					'event': 'register_customer',
376					'retrieve': 'customer'
377				};
378				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
379			}
380		}
381	},
382    registerConversion: function (label, data) {
383		let event = {
384			'send_to': label,
385			'value': data.value,
386			'currency': data.currency
387		};
388		gtag('event', 'conversion', event);
389		console.log('gtag|conversion');
390	}
391};
392
393var domLoaded = function() {
394	XMLHttpRequest.prototype._send = XMLHttpRequest.prototype.send;
395	XMLHttpRequest.prototype.send = function(data) {
396		try {
397			if (this.readyState == 1) {
398				let params = {};
399				if (typeof data == 'string') {
400					params = alcagtmplus.getUrlParams(data);
401				} else if (typeof data == 'object' && data && data.length) {
402					data.forEach(function(value, key) {
403						params[key] = value;
404					});
405				}
406				this.responseParams = params;
407			}
408			this.addEventListener('readystatechange', function() {
409				if (this.readyState == XMLHttpRequest.DONE) {
410					if (!this.responseType ||
411						this.responseType === 'text'
412					) {
413						try {
414							var response = JSON.parse(this.response);
415						} catch {
416							var response = this.responseText;
417						}
418					} else if (this.responseType === 'document') {
419						var response = this.responseXML;
420					} else {
421						var response = this.response;
422					}
423					alcagtmplus.evalEvents(this.responseURL, this.responseParams, response);
424				}
425            }, false);
426		} catch (error) {
427			console.log(error);
428		}
429		this._send(data);
430	};
431	alcagtmplus.setConfig();
432	alcagtmplus.triggerEvents();
433}
434
435if (document.readyState !== 'loading') {
436    domLoaded();
437} else {
438    document.addEventListener('DOMContentLoaded', function () {
439        domLoaded();
440    });
441}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.