1jQuery(document).ready(function($) { 2 3 var $form = $('form[data-formid]'); 4 var formId = $form.data('formid'); 5 6 7 function getUtmParams() { 8 var urlParams = new URLSearchParams(window.location.search); 9 return { 10 utm_source: urlParams.get('utm_source'), 11 utm_medium: urlParams.get('utm_medium'), 12 utm_campaign: urlParams.get('utm_campaign'), 13 utm_content: urlParams.get('utm_content') 14 }; 15 } 16 function setUtmParamWithExpiry(key, value, hours) { 17 var expirationTime = new Date().getTime() + (hours * 60 * 60 * 1000); 18 var item = { 19 value: value, 20 expiration: expirationTime 21 }; 22 localStorage.setItem(key, JSON.stringify(item)); 23 } 24 25 function getUtmParamWithExpiry(key) { 26 var itemStr = localStorage.getItem(key); 27 if (!itemStr) return null; 28 29 var item = JSON.parse(itemStr); 30 var now = new Date().getTime(); 31 32 if (now > item.expiration) { 33 localStorage.removeItem(key); 34 return null; 35 } 36 37 return item.value; 38 } 39 40 41 function storeUtmParams(params) { 42 if (params.utm_source || params.utm_medium || params.utm_campaign || params.utm_content) { 43 setUtmParamWithExpiry('utm_source', params.utm_source, 24); 44 setUtmParamWithExpiry('utm_medium', params.utm_medium, 24); 45 setUtmParamWithExpiry('utm_campaign', params.utm_campaign, 24); 46 setUtmParamWithExpiry('utm_content', params.utm_content, 24); 47 } 48 } 49 50 51 function getUtmParamsFromLocalStorage() { 52 return { 53 utm_source: getUtmParamWithExpiry('utm_source'), 54 utm_medium: getUtmParamWithExpiry('utm_medium'), 55 utm_campaign: getUtmParamWithExpiry('utm_campaign'), 56 utm_content: getUtmParamWithExpiry('utm_content') 57 }; 58 } 59 60 61 var utmParams = getUtmParams(); 62 63 storeUtmParams(utmParams); 64 65 if(formId){ 66 67 var ajaxData = { 68 action: 'get_gf_hidden_field_ids', 69 form_id: formId, 70 utm_source: 'utm_source', 71 utm_medium: 'utm_medium', 72 utm_campaign: 'utm_campaign', 73 utm_content: 'utm_content' 74 }; 75 76 $.ajax({ 77 url: '/wp-admin/admin-ajax.php', 78 type: 'POST', 79 data: ajaxData, 80 success: function(response) { 81 if (response && response.data) { 82 83 var storedParams = getUtmParamsFromLocalStorage(); 84 85 86 if (response.data.utm_source) { 87 $form.find('input[name="input_' + response.data.utm_source + '"]').val(storedParams.utm_source); 88 } 89 if (response.data.utm_medium) { 90 $form.find('input[name="input_' + response.data.utm_medium + '"]').val(storedParams.utm_medium); 91 } 92 if (response.data.utm_campaign) { 93 $form.find('input[name="input_' + response.data.utm_campaign + '"]').val(storedParams.utm_campaign); 94 } 95 if (response.data.utm_content) { 96 $form.find('input[name="input_' + response.data.utm_content + '"]').val(storedParams.utm_content); 97 } 98 } 99 }, 100 error: function(xhr, status, error) { 101 console.error('AJAX error:', status, error); 102 } 103 }); 104 } 105 106});
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.