PageSourceSearch

https://apester.com/wp-content/plugins/dt-apester-utms//dt-apester-utms.js?ver=1790238685

js apester.com collected 2026-09-24 08:41:58 UTC 5,108 bytes, 134 lines download raw bytes

1document.addEventListener('DOMContentLoaded', function(){
2
3    // --- Read cookie ---
4    function dt_get_cookie(name) {
5        let matches = document.cookie.match(
6            new RegExp("(?:^|; )" + name.replace('/([.$?*|{}()[]/+^])/g', '$1') + "=([^;]*)")
7        );
8        return matches ? decodeURIComponent(matches[1]) : undefined;
9    }
10
11    // --- Set cookie ---
12    function dt_set_cookie(name, value, options = {}) {
13        options = { path: '/', ...options };
14
15        if (options.expires instanceof Date) {
16            options.expires = options.expires.toUTCString();
17        }
18
19        let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
20
21        for (let optionKey in options) {
22            updatedCookie += "; " + optionKey;
23            let optionValue = options[optionKey];
24            if (optionValue !== true) {
25                updatedCookie += "=" + optionValue;
26            }
27        }
28
29        document.cookie = updatedCookie;
30    }
31
32    // --- Safe GET parameter ---
33    function dt_get_url_parameter_by_name(name, url = window.location.href) {
34        try {
35            let u = new URL(url);
36            return u.searchParams.get(name);
37        } catch(e){
38            return null;
39        }
40    }
41
42    // --- Read incoming UTM ---
43    var dt_utm_campaign = dt_get_url_parameter_by_name('utm_campaign');
44    var dt_utm_term     = dt_get_url_parameter_by_name('utm_term');
45    var dt_utm_content  = dt_get_url_parameter_by_name('utm_content');
46    var dt_utm_source   = dt_get_url_parameter_by_name('utm_source');
47    var dt_utm_medium   = dt_get_url_parameter_by_name('utm_medium');
48
49    // --- Cookie expiration for 10 years ---
50    var today = new Date();
51    var expires_date = new Date(today.getFullYear() + 10, today.getMonth(), today.getDate());
52
53    if (dt_utm_campaign !== null) dt_set_cookie('dt_utm_campaign', dt_utm_campaign, { expires: expires_date });
54    if (dt_utm_term     !== null) dt_set_cookie('dt_utm_term', dt_utm_term, { expires: expires_date });
55    if (dt_utm_content  !== null) dt_set_cookie('dt_utm_content', dt_utm_content, { expires: expires_date });
56    if (dt_utm_source   !== null) dt_set_cookie('dt_utm_source', dt_utm_source, { expires: expires_date });
57    if (dt_utm_medium   !== null) dt_set_cookie('dt_utm_medium', dt_utm_medium, { expires: expires_date });
58
59    // --- Build params object ---
60    var query_params = {};
61
62    var sId = dt_get_url_parameter_by_name('sId');
63    if (sId !== null) query_params.sId = sId;
64
65    var dt_exists_utm_campaign = dt_get_cookie('dt_utm_campaign');
66    var dt_exists_utm_term     = dt_get_cookie('dt_utm_term');
67    var dt_exists_utm_content  = dt_get_cookie('dt_utm_content');
68    var dt_exists_utm_source   = dt_get_cookie('dt_utm_source');
69    var dt_exists_utm_medium   = dt_get_cookie('dt_utm_medium');
70
71    if (dt_exists_utm_campaign !== undefined) query_params.utm_campaign = dt_exists_utm_campaign;
72    if (dt_exists_utm_term     !== undefined) query_params.utm_term     = dt_exists_utm_term;
73    if (dt_exists_utm_content  !== undefined) query_params.utm_content  = dt_exists_utm_content;
74    if (dt_exists_utm_source   !== undefined) query_params.utm_source   = dt_exists_utm_source;
75    if (dt_exists_utm_medium   !== undefined) query_params.utm_medium   = dt_exists_utm_medium;
76
77
78    // ------------------------------------------------------------------
79    // 🔥 INTERCEPT CLICK ON HASH LINKS AND FIX URL
80    // ------------------------------------------------------------------
81    if (Object.keys(query_params).length > 0) {
82
83        document.addEventListener('click', function(e){
84            let a = e.target.closest('a[href]');
85
86            if (!a) return;
87
88            let href = a.getAttribute('href');
89
90            // process only hash links (#something)
91            if (!href || !href.startsWith('#')) return;
92
93            e.preventDefault(); // stop default broken behavior
94
95            let hash = href; // "#anchor"
96
97            let u = new URL(window.location.origin + window.location.pathname);
98
99            // add params
100            for (const key in query_params) {
101                u.searchParams.set(key, query_params[key]);
102            }
103
104            let finalUrl = u.toString() + hash;
105
106            console.log("Redirect to:", finalUrl);
107
108            window.location.href = finalUrl;
109        });
110    }
111
112
113    // ------------------------------------------------------------------
114    // 🔥 Also fix normal /auth/signup links
115    // ------------------------------------------------------------------
116    if (Object.keys(query_params).length > 0) {
117
118        const portal_signup_buttons = Array.from(document.querySelectorAll('a[href]'))
119            .filter(a => a.href.includes(window.location.hostname + '/auth/signup'));
120
121        portal_signup_buttons.forEach(a => {
122            let u = new URL(a.href);
123            let hash = u.hash;
124            u.hash = "";
125
126            for (const key in query_params) {
127                u.searchParams.set(key, query_params[key]);
128            }
129
130            a.href = u.toString() + hash;
131        });
132    }
133
134});

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.