PageSourceSearch

https://manodelfriki.com/modules/alcagtmplus/views/js/front.js

js manodelfriki.com collected 2026-10-04 13:24:44 UTC 15,020 bytes, 461 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			let done = (isNaN(this.readyState) && isNaN(XMLHttpRequest.DONE) && this.readyState == XMLHttpRequest.DONE)
62				? true
63				: (this.readyState == 4
64					? true
65					: false
66				);
67			if(done) {
68				if (!this.responseType ||
69					this.responseType === 'text'
70				) {
71					try {
72						var data = JSON.parse(this.response);
73					} catch {
74						var data = this.responseText;
75					}
76				} else if (this.responseType === 'document') {
77					var data = this.responseXML;
78				} else {
79					var data = this.response;
80				}
81				if (typeof callback != 'undefined') {
82					eval(callback + '(params, data)');
83				}
84			}
85		});
86		let formData = new FormData();
87		Object.keys(data).forEach(function(k) {
88			formData.append(k, data[k]);
89		});
90		xhr.send(formData);
91	},
92	getUrlParams(url) {
93		let params = {};
94		if (url.match(/\?.*/gm)) {
95			url = url.split('?')[1];
96		}
97		if (url.match(/&.*/gm)) {
98			url.split('&').forEach(function (pair) {
99				pair = (pair + '=').split('=').map(decodeURIComponent);
100				if (pair[0].length) {
101					params[pair[0]] = pair[1];
102				}
103			});
104		} else if (url.match(/=.*/gm)) {
105			pair = url.split('=').map(decodeURIComponent);
106			if (pair[0].length) {
107				params[pair[0]] = pair[1];
108			}
109		}
110		return params;
111	},
112	setConfig: function() {
113		// Universal Analytics property.
114		if (alcagtmplus_params.config.google_ua_enabled == 1 && alcagtmplus_params.config.google_ua_id != '') {
115			gtag('config', alcagtmplus_params.config.google_ua_id);
116			console.log('gtag|config|ua');
117			// Anonymize
118			if (alcagtmplus_params.config.google_anonymize_ip == 1) {
119				gtag('config', alcagtmplus_params.config.google_ua_id, {
120					'anonymize_ip': true
121				});
122				console.log('gtag|config|anonymize ip');
123			}
124			// Optimize
125			if (alcagtmplus_params.config.google_optimize_enabled == 1 && alcagtmplus_params.config.google_optimize_id != '') {
126				gtag('config', alcagtmplus_params.config.google_ua_id, {
127					'optimize_id': alcagtmplus_params.config.google_optimize_id
128				});
129				console.log('gtag|config|optimize');
130			}
131			// Customer ID
132			if (alcagtmplus_params.config.google_customer_id == 1 && alcagtmplus_params.id_customer) {
133				gtag('config', alcagtmplus_params.config.google_ua_id, {
134					'user_id': alcagtmplus_params.id_customer
135				});
136				console.log('gtag|config|customer');
137			}
138			document.addEventListener('click', function (e) {
139				if (e.target.hasAttribute('id') && e.target.getAttribute('id') == 'quantity_wanted') {
140					// Only for PS 1.6
141					if (alcagtmplus_params.config.google_ga4_begin_checkout == 1 && document.getElementById('cart_summary') && document.getElementById('cgv').checked == true) {
142						var params = {
143							'action': 'getCheckout',
144							'event': 'begin_checkout',
145							'retrieve': 'checkout'
146						};
147						alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
148					}
149				}
150			});
151		}
152		// Google Analytics 4 property.
153		if (alcagtmplus_params.config.google_ga4_enabled == 1 && alcagtmplus_params.config.google_ga4_id != '') {
154			gtag('config', alcagtmplus_params.config.google_ga4_id);
155			console.log('gtag|config|ga4');
156		}
157		// Google Ads
158		if (alcagtmplus_params.config.google_ads_enabled == 1 && alcagtmplus_params.config.google_ads_id != '') {
159			gtag('config', 'AW-' + alcagtmplus_params.config.google_ads_id);
160			console.log('gtag|config|ads');
161		}
162	},
163	evalEvents: function(url, params, response) {
164        // Is a add_to_cart event
165		if (( // PS 1.7
166				(typeof prestashop != 'undefined' && url == prestashop.urls.pages.cart) &&
167				typeof params.action != 'undefined'&&
168				params.action == 'update' &&
169				typeof params.id_product != 'undefined'&&
170				params.id_product > 0 &&
171				typeof params.qty != 'undefined'&&
172				params.qty > 0 &&
173				typeof response.success != 'undefined'&&
174				response.success
175			) ||
176			( // PS 1.6
177				params.controller == 'cart' && typeof params.add != 'undefined' && params.qty != 'undefined' && params.qty > 0
178			)
179		) {
180			if (typeof params.controller != 'undefined') {
181				delete params.controller;
182			}
183			params.action = 'getCart';
184			params.event = 'add_to_cart';
185			params.retrieve = 'cart';
186			alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
187		}
188		// Is a register_newsletter event
189		if (typeof params.email != 'undefined' &&
190			params.email != '' &&
191			typeof response.nw_error != 'undefined' &&
192			!response.nw_error
193		) {
194			var params = {
195				'event': 'register_newsletter',
196				'retrieve': 'value'
197			};
198			this.triggerEvent(params, response);
199		}
200    },
201	triggerEvent: function(params, data) {
202		if (typeof data[params.retrieve] != 'undefined') {
203			gtag('event', params.event, data[params.retrieve]);
204			console.log('gtag|event|' + params.event);
205			console.log(data[params.retrieve]);
206			// Google Ads Events
207			if (alcagtmplus_params.config.google_ads_enabled == 1 &&
208				alcagtmplus_params.config.google_ads_id != '' &&
209				typeof data[params.retrieve] != 'undefined' &&
210				data[params.retrieve]
211			) {
212				if (params.event == 'purchase' && alcagtmplus_params.config.google_ads_purchase != '') {
213					var conversion = {
214						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_purchase,
215						'value': data[params.retrieve].value,
216						'currency': data[params.retrieve].currency,
217						'transaction_id': data[params.retrieve].transaction_id
218					};
219				} else if (params.event == 'add_to_cart' && alcagtmplus_params.config.google_ads_add_to_cart != '') {
220					var conversion = {
221						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_add_to_cart,
222						'value': data[params.retrieve].value,
223						'currency': data[params.retrieve].currency
224					};
225				} else if (params.event == 'view_item' && alcagtmplus_params.config.google_ads_view_product != '') {
226					var conversion = {
227						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_view_product,
228						'value': data[params.retrieve].value,
229						'currency': data[params.retrieve].currency
230					};
231				} else if (params.event == 'begin_checkout' && alcagtmplus_params.config.google_ads_begin_checkout != '') {
232					var conversion = {
233						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_begin_checkout,
234						'value': data[params.retrieve].value,
235						'currency': data[params.retrieve].currency
236					};
237				} else if (params.event == 'register_customer' && alcagtmplus_params.config.google_ads_create_account != '') {
238					var conversion = {
239						'send_to': 'AW-' + alcagtmplus_params.config.google_ads_id + '/' + alcagtmplus_params.config.google_ads_create_account,
240						'value': 1,
241						'currency': data[params.retrieve].currency
242					};
243				}
244				if (typeof conversion != 'undefined') {
245					gtag('event', 'conversion', conversion);
246					console.log('ads|conversion|'+params.event);
247					console.log(conversion);
248				}
249			}
250		}
251		// Pending events
252		if (typeof data.pending != 'undefined') {
253			let sended = [];
254			for (k in data.pending) {
255				try {
256					data.pending[k].forEach(function(obj) {
257						alcagtmplus.triggerEvent(
258							{'event': k,'retrieve': 'order'},
259							obj
260						);
261					});
262					sended.push(k);
263				} catch (error) {
264					console.error("Alcagtmplus event " + k + " error:", error.message);
265				}
266			}
267			if (sended.length > 0) {
268				alcagtmplus.ajaxCall({
269					'action': 'sendedEvents',
270					'events': sended
271				});
272			}
273		}
274	},
275	dataLayerPush: function(params, data) {
276		if (typeof dataLayer != 'undefined' && typeof data.order != 'undefined') {
277			dataLayer.push(data.order);
278			console.log('gtag|datalayer|add');
279		}
280	},
281	triggerEvents: function() {
282		// Events setted on head variables
283		if (typeof alcagtmplus_events != 'undefined' && Object.keys(alcagtmplus_events).length > 0) {
284			Object.keys(alcagtmplus_events).forEach(function (name) {
285				if (name == 'datalayer') {
286					var params = {};
287					var response = {'order': alcagtmplus_events[name]};
288					alcagtmplus.dataLayerPush(params, response);
289				} else {
290					gtag('event', name, alcagtmplus_events[name]);
291					console.log('gtag|event|' + name);
292				}
293			});
294		// Events evaluated by conditions
295		} else {
296			// Is product page
297			if (document.getElementById('product') &&
298				document.getElementById('product').nodeName.toLowerCase() == 'body' &&
299				document.getElementsByName('id_product') &&
300				alcagtmplus_params.config.google_ga4_view_item == 1
301			) {
302				var id_product = document.getElementsByName('id_product')[0].value;
303				var id_product_attribute = alcagtmplus_params.id_product_attribute;
304				var params = {
305					'action': 'getProduct',
306					'id_product': id_product,
307					'id_product_attribute': id_product_attribute,
308					'event': 'view_item',
309					'retrieve': 'product'
310				};
311				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
312			}
313			// Is category page
314			if (document.getElementById('category') &&
315				document.getElementById('category').nodeName.toLowerCase() == 'body' &&
316				alcagtmplus_params.id_category &&
317				alcagtmplus_params.config.google_ga4_view_item_list == 1
318			) {
319				var page = alcagtmplus_params.page ? alcagtmplus_params.page : 1;
320				var params = {
321					'action': 'getCategory',
322					'id_category': alcagtmplus_params.id_category,
323					'page': page,
324					'event': 'view_item_list',
325					'retrieve': 'category'
326				};
327				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
328			}
329			// Is cart page
330			if (alcagtmplus_params.config.google_ga4_view_cart == 1 &&
331				(
332					( // PS 1.7
333						document.getElementById('cart') &&
334						document.getElementById('cart').nodeName.toLowerCase() == 'body'
335					) ||
336					( // PS 1.6
337						document.getElementById('cart_summary')
338					)
339				)
340			) {
341				var params = {
342					'action': 'getCart',
343					'event': 'view_cart',
344					'retrieve': 'cart'
345				};
346				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
347			}
348			// Is checkout page
349			if (document.getElementById('checkout') &&
350				document.getElementById('checkout').nodeName.toLowerCase() == 'body' &&
351				alcagtmplus_params.config.google_ga4_begin_checkout == 1
352			) {
353				var params = {
354					'action': 'getCheckout',
355					'event': 'begin_checkout',
356					'retrieve': 'checkout'
357				};
358				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
359			}
360			// Is order confirmation page
361			if (document.getElementById('order-confirmation') &&
362				document.getElementById('order-confirmation').nodeName.toLowerCase() == 'body' &&
363				(alcagtmplus_params.id_order || alcagtmplus_params.id_cart)
364			) {
365				if (alcagtmplus_params.config.google_ga4_purchase) {
366					var params = {
367						'action': 'getOrder',
368						'event': 'purchase',
369						'retrieve': 'order',
370						'id_order': alcagtmplus_params.id_order,
371						'id_cart': alcagtmplus_params.id_cart
372					};
373					alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
374				}
375				if (alcagtmplus_params.config.google_gtm_enabled) {
376					var params = {
377						'action': 'getDatalayerOrder',
378						'retrieve': 'order',
379						'id_order': alcagtmplus_params.id_order,
380						'id_cart': alcagtmplus_params.id_cart
381					};
382					alcagtmplus.ajaxCall(params, 'alcagtmplus.dataLayerPush');
383				}
384			}
385			// Is new customer
386			if (alcagtmplus_params.new_customer) {
387				var params = {
388					'action': 'getCustomer',
389					'event': 'register_customer',
390					'retrieve': 'customer'
391				};
392				alcagtmplus.ajaxCall(params, 'alcagtmplus.triggerEvent');
393			}
394		}
395	},
396    registerConversion: function (label, data) {
397		let event = {
398			'send_to': label,
399			'value': data.value,
400			'currency': data.currency
401		};
402		gtag('event', 'conversion', event);
403		console.log('gtag|conversion');
404	}
405};
406
407var domLoaded = function() {
408	XMLHttpRequest.prototype._send = XMLHttpRequest.prototype.send;
409	XMLHttpRequest.prototype.send = function(data) {
410		try {
411			if (this.readyState == 1) {
412				let params = {};
413				if (typeof data == 'string') {
414					params = alcagtmplus.getUrlParams(data);
415				} else if (typeof data == 'object' && data && data.length) {
416					data.forEach(function(value, key) {
417						params[key] = value;
418					});
419				}
420				this.responseParams = params;
421			}
422			this.addEventListener('readystatechange', function() {
423				if (this.readyState == XMLHttpRequest.DONE) {
424					if (!this.responseType ||
425						this.responseType === 'text'
426					) {
427						try {
428							var response = JSON.parse(this.response);
429						} catch {
430							var response = this.responseText;
431						}
432					} else if (this.responseType === 'document') {
433						var response = this.responseXML;
434					} else {
435						var response = this.response;
436					}
437					alcagtmplus.evalEvents(this.responseURL, this.responseParams, response);
438				}
439            }, false);
440		} catch (error) {
441			console.log(error);
442		}
443		this._send(data);
444	};
445	alcagtmplus.setConfig();
446	alcagtmplus.triggerEvents();
447}
448
449if (typeof jQuery !== 'undefined') {
450	$(document).ready(function() {
451		domLoaded();
452	});
453} else {
454	if (document.readyState !== 'loading') {
455		domLoaded();
456	} else {
457		document.addEventListener('DOMContentLoaded', function () {
458			domLoaded();
459		});
460	}
461}

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.