PageSourceSearch

https://www.ispazio.net/wp-content/themes/ispazio-theme/assets/js/adv-track.js?x44257&ver=1790888060

js ispazio.net collected 2026-10-02 02:37:59 UTC 2,822 bytes, 78 lines download raw bytes

1/**
2 * Appvertise tracking (web) — impression + click della card sponsorizzata.
3 *
4 * Impression: una view ogni volta che la card entra in viewport (≥50% per ≥0,8s).
5 *   Riesce a contare anche le riesposizioni (esce e rientra ⇒ nuova view), come
6 *   richiesto. Le "uniche per sessione" le deduplica il server tramite `sid`.
7 * Click: un evento per click su qualsiasi link della card.
8 * Invio: navigator.sendBeacon (non blocca la navigazione) → REST /adv/track.
9 */
10(function () {
11	'use strict';
12	var cfg = window.ISP_ADV || {};
13	if (!cfg.url) return;
14	var cards = document.querySelectorAll('[data-adv-track]');
15	if (!cards.length) return;
16
17	/* sid stabile per sessione (per il conteggio uniche lato server). */
18	var sid = '';
19	try {
20		sid = sessionStorage.getItem('isp_adv_sid');
21		if (!sid) {
22			sid = (Date.now().toString(36) + Math.random().toString(36).slice(2, 10));
23			sessionStorage.setItem('isp_adv_sid', sid);
24		}
25	} catch (e) { sid = 's' + Math.random().toString(36).slice(2, 10); }
26
27	function send(id, event) {
28		if (!id) return;
29		var body = 'advert_id=' + encodeURIComponent(id) +
30			'&event=' + encodeURIComponent(event) +
31			'&platform=web&sid=' + encodeURIComponent(sid);
32		try {
33			if (navigator.sendBeacon) {
34				navigator.sendBeacon(cfg.url, new Blob([body], { type: 'application/x-www-form-urlencoded' }));
35				return;
36			}
37		} catch (e) {}
38		try {
39			fetch(cfg.url, { method: 'POST', keepalive: true, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: body });
40		} catch (e) {}
41	}
42
43	/* Click: un evento per click su un link interno alla card. */
44	[].forEach.call(cards, function (card) {
45		var id = card.getAttribute('data-adv-id');
46		card.addEventListener('click', function (ev) {
47			var a = ev.target.closest('a');
48			if (a && !a.hasAttribute('data-adv-ignore')) send(id, 'click');
49		}, true);
50	});
51
52	/* Impression con dwell di 0,8s e re-conteggio alla ri-entrata. */
53	if (!('IntersectionObserver' in window)) {
54		[].forEach.call(cards, function (card) { send(card.getAttribute('data-adv-id'), 'view'); });
55		return;
56	}
57	var timers = new WeakMap();
58	var counted = new WeakMap();
59	var io = new IntersectionObserver(function (entries) {
60		entries.forEach(function (e) {
61			var card = e.target;
62			if (e.isIntersecting && e.intersectionRatio >= 0.5) {
63				if (counted.get(card)) return;
64				if (timers.get(card)) return;
65				timers.set(card, setTimeout(function () {
66					timers.delete(card);
67					counted.set(card, true);
68					send(card.getAttribute('data-adv-id'), 'view');
69				}, 800));
70			} else {
71				var t = timers.get(card);
72				if (t) { clearTimeout(t); timers.delete(card); }
73				counted.set(card, false); // uscito: la prossima entrata riconta
74			}
75		});
76	}, { threshold: [0, 0.5, 1] });
77	[].forEach.call(cards, function (card) { io.observe(card); });
78})();

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.