PageSourceSearch

https://cleaning-express.com/wp-content/plugins/handl-utm-grabber/js/handl-utm-grabber.js?ver=2.9.14

js cleaning-express.com collected 2026-09-24 12:15:46 UTC 6,381 bytes, 190 lines download raw bytes

1var qvars = getUrlVars()
2var handlConsentGranted = typeof handl_utm_cookie_duration === 'undefined' || handl_utm_cookie_duration[1] === '1'
3
4jQuery(function($) {
5    if (handlConsentGranted) {
6        RunHandL()
7    }
8});
9
10function RunHandL(){
11    handlConsentGranted = true
12    setHandLParams()
13    RunFieldFiller()
14    HandLAppendTrackedLinks()
15    HandLBindNinjaFormsFiller()
16}
17
18// NF inputs (#nf-field-{id}) carry no param name, so the generic selector
19// pass can't reach them; re-fill on nfFormReady ('' when the cookie is absent).
20var handlNfFillerBound = false
21function HandLBindNinjaFormsFiller(){
22    if (handlNfFillerBound) return
23    handlNfFillerBound = true
24
25    jQuery(document).on( 'nfFormReady', function () {
26        if (typeof nfForms === 'undefined') return
27        nfForms.forEach(function (form) {
28            form.fields.map(function (item) {
29                if (item.default) {
30                    var matches = String(item.default).match(/^{(\w+):(\w+)/)
31                    if (matches && matches.length == 3 && matches[1] === 'handl') {
32                        var c = Cookies.get(matches[2])
33                        jQuery('#nf-field-' + item.id).val(c === undefined ? '' : decodeURIComponent(c).replace(/[%]/g,' '))
34                    }
35                }
36            })
37        })
38    })
39}
40
41// IP stays server-side.
42function setHandLParams(){
43    var cookieOptions = { expires: parseInt(handl_utm_cookie_duration[0]) }
44
45    Cookies.set('handl_url', document.location.href, cookieOptions)
46    Cookies.set('handl_ref', document.referrer, cookieOptions)
47
48    if (Cookies.get('handl_landing_page') === undefined) {
49        Cookies.set('handl_landing_page', document.location.href, cookieOptions)
50    }
51
52    if (Cookies.get('handl_original_ref') === undefined) {
53        Cookies.set('handl_original_ref', document.referrer, cookieOptions)
54    }
55}
56
57function HandLAppendTrackedLinks(){
58    jQuery('.utm-out').each(function(){
59        // Only process if this is an anchor tag with href
60        if (this.tagName.toLowerCase() !== 'a' || !this.href) {
61            return;
62        }
63
64        // Sanitize URL parameters and handl_utm object
65        var urlParams = getSearchParams(this.href);
66        var sanitizedParams = {};
67
68        // Only include parameters that exist in handl_utm
69        for(var key in urlParams) {
70            if(handl_utm.hasOwnProperty(key)) {
71                sanitizedParams[key] = encodeURIComponent(urlParams[key]);
72            }
73        }
74
75        // Sanitize handl_utm values
76        var sanitizedHandlUtm = {};
77        for(var key in handl_utm) {
78            sanitizedHandlUtm[key] = encodeURIComponent(handl_utm[key]);
79        }
80
81        // Merge sanitized objects
82        var merged = jQuery.extend({}, sanitizedHandlUtm, sanitizedParams);
83
84        // Reset href and append sanitized parameters
85        this.href = this.href.split('?')[0]; // Keep base URL only
86        if(!jQuery.isEmptyObject(merged)) {
87            this.href += "?" + jQuery.param(merged);
88        }
89    });
90}
91
92// WP Consent API
93document.addEventListener('wp_listen_for_consent_change', function (e) {
94    var changedConsentCategory = e.detail;
95    for (var key in changedConsentCategory) {
96        if (changedConsentCategory.hasOwnProperty(key)) {
97            if (key === 'marketing' && changedConsentCategory[key] === 'allow') {
98                console.log('WP Consent API: Marketing consent granted, running HandL');
99                RunHandL();
100            }
101        }
102    }
103});
104
105function RunFieldFiller(){
106    jQuery.each([ 'utm_source','utm_medium','utm_term', 'utm_content', 'utm_campaign', 'gclid', 'handl_landing_page', 'handl_original_ref', 'handl_ip', 'handl_ref', 'handl_url', 'email', 'username' ], function( i,v ) {
107
108        var cookie_field = GetQVars(v,qvars)
109
110        if ( cookie_field != '' )
111            Cookies.set(v, cookie_field, { expires: 30 });
112
113        var curval = Cookies.get(v)
114
115        if (curval != undefined) {
116            curval = decodeURIComponent(curval).replace(/[%]/g,' ')
117
118            if ([ 'utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign', 'gclid' ].indexOf(v) !== -1) {
119                handl_utm[v] = curval
120            }
121
122            if (v == 'username') {
123                //Maybe this should apply to all... We'll see...
124                curval = curval.replace(/\+/g, ' ')
125            }
126        } else {
127            // No cookie: blank tracked fields (cached pages carry baked values).
128            // skip email/username
129            if ([ 'email', 'username' ].indexOf(v) !== -1) {
130                return
131            }
132            curval = ''
133        }
134
135        {
136            jQuery('input[name=\"'+v+'\"]').val(curval)
137            jQuery('input#'+v).val(curval)
138            jQuery('input.'+v).val(curval)
139            jQuery('input#form-field-'+v).val(curval)
140
141            //for nested input fix
142            jQuery('#'+v).find('input').val(curval)
143            jQuery('.'+v).find('input').val(curval)
144
145            jQuery("[data-original_id='"+v+"']").val(curval)
146            jQuery("[data-name='"+v+"']").val(curval)
147            jQuery("[data-name='"+v.replace(/_/g,'')+"']").val(curval) //Active Campaign
148            jQuery("[placeholder='"+v+"']").val(curval) //Dyanmics 365 + Generic
149
150            if (v.length > 4 && ['email','username'].indexOf(v) == -1){ // this is for making sure wildcards are not hyper sensitive. (email/username are free-only params, V3 never wildcards them)
151                //wildcard selector
152                jQuery("[name*="+v+"]").val(curval)
153                jQuery("[id*="+v+"]").val(curval)
154                jQuery("[class*="+v+"]").val(curval)
155            }
156
157        }
158    });
159}
160
161function getSearchParams(url,k){
162    var p={};
163    var a = document.createElement('a');
164    a.href = url;
165    a.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v})
166    return k?p[k]:p;
167}
168
169function GetQVars(v,qvars){
170    if (qvars[v] != undefined) {
171        return qvars[v]
172    }
173    return ''
174}
175
176function getUrlVars() {
177    var vars = {};
178    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
179        vars[key] = value;
180    });
181    return vars;
182}
183
184jQuery( document ).on( 'elementor/popup/show' , function () {
185    setTimeout(function(){
186        if (handlConsentGranted) {
187            RunFieldFiller()
188        }
189    }, 1000)
190} );

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.