PageSourceSearch

https://www.rosier.de/wp-content/themes/breakdance-zero/js/utm_store.js?ver=1.0.7

js rosier.de collected 2026-10-02 18:03:33 UTC 3,574 bytes, 119 lines download raw bytes

1(function() {
2    'use strict';
3
4    // Liste der UTM-Parameter, die gespeichert werden sollen
5    const utmParams = [
6        'utm_source',
7        'utm_medium',
8        'utm_campaign',
9        'utm_term',
10        'utm_content'
11    ];
12
13    // URL-Parameter auslesen
14    const urlParams = new URLSearchParams(window.location.search);
15
16    // Prüfen, ob mindestens ein UTM-Parameter in der URL vorhanden ist
17    let hasNewUtmParams = false;
18
19    utmParams.forEach(function(param) {
20        if (urlParams.has(param)) {
21            hasNewUtmParams = true;
22        }
23    });
24
25    // Wenn neue UTM-Parameter vorhanden sind, alle überschreiben
26    if (hasNewUtmParams) {
27        // Alte UTM-Daten löschen
28        utmParams.forEach(function(param) {
29            sessionStorage.removeItem(param);
30        });
31        sessionStorage.removeItem('utm_data');
32
33        // Neue UTM-Daten speichern
34        const utmData = {};
35        utmParams.forEach(function(param) {
36            const value = urlParams.get(param);
37            if (value) {
38                sessionStorage.setItem(param, value);
39                utmData[param] = value;
40            }
41        });
42
43        if (Object.keys(utmData).length > 0) {
44            sessionStorage.setItem('utm_data', JSON.stringify(utmData));
45        }
46    }
47
48    // Gespeicherte UTM-Daten aus der Session laden
49    function getStoredUtmData() {
50        const stored = sessionStorage.getItem('utm_data');
51        if (!stored) {
52            return {};
53        }
54        try {
55            return JSON.parse(stored) || {};
56        } catch (e) {
57            return {};
58        }
59    }
60
61    // Prüft, ob ein Link intern ist (gleicher Host, http/https)
62    function isInternalLink(anchor) {
63        // href kann leer, ein Anker (#), mailto:, tel: usw. sein
64        const href = anchor.getAttribute('href');
65        if (!href) {
66            return false;
67        }
68        // Nur echte http(s)-Links (schließt mailto:, tel:, javascript:, #anker aus)
69        if (!/^https?:/i.test(anchor.protocol)) {
70            return false;
71        }
72        return anchor.hostname === window.location.hostname;
73    }
74
75    // Hängt die gespeicherten UTM-Parameter an einen Link an,
76    // ohne bereits vorhandene Parameter zu überschreiben.
77    function appendUtmToAnchor(anchor, utmData) {
78        try {
79            const url = new URL(anchor.href);
80            let changed = false;
81
82            Object.keys(utmData).forEach(function(param) {
83                if (!url.searchParams.has(param)) {
84                    url.searchParams.set(param, utmData[param]);
85                    changed = true;
86                }
87            });
88
89            if (changed) {
90                anchor.href = url.toString();
91            }
92        } catch (e) {
93            // Ungültige URL - ignorieren
94        }
95    }
96
97    // Alle internen Links mit den gespeicherten UTM-Parametern versehen
98    function decorateInternalLinks() {
99        const utmData = getStoredUtmData();
100        console.log('Decorating internal links with UTM data:', utmData);
101        if (Object.keys(utmData).length === 0) {
102            return;
103        }
104
105        const anchors = document.querySelectorAll('a[href]');
106        anchors.forEach(function(anchor) {
107            if (isInternalLink(anchor)) {
108                appendUtmToAnchor(anchor, utmData);
109            }
110        });
111    }
112
113    // Beim Laden des DOM ausführen
114    if (document.readyState === 'loading') {
115        document.addEventListener('DOMContentLoaded', decorateInternalLinks);
116    } else {
117        decorateInternalLinks();
118    }
119})();

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.