1/* 2 * The following section of code inserts values like category, formats, active language etc to 3 * Ninjaform fields. 4*/ 5jQuery(() => { 6 jQuery('#dataUTM').attr('data-geolocation', country_code_nf); 7 jQuery('#dataUTM').attr('data-pardot-id', pardotId); 8 jQuery('#dataUTM').attr('data-google-analytics-id', google_analytics_id); 9}) 10jQuery(document).on('nfFormReady', 11 (e, layoutView) => { 12 var utm_source = jQuery('#dataUTM').attr("data-utm-source"); 13 var utm_medium = jQuery('#dataUTM').attr("data-utm-medium"); 14 var utm_campaign = jQuery('#dataUTM').attr("data-utm-campaign"); 15 var utm_content = jQuery('#dataUTM').attr("data-utm-content"); 16 var utm_term = jQuery('#dataUTM').attr("data-utm-term"); 17 var active_lang = jQuery('#dataUTM').attr("data-language"); 18 19 var data_products = $('#dataUTM').attr("data-products"); 20 var data_section = $('#dataUTM').attr("data-section"); 21 var data_category = $('#dataUTM').attr("data-category"); 22 var data_formats = $('#dataUTM').attr("data-formats"); 23 var data_industry = $('#dataUTM').attr("data-industry"); 24 var data_media = $('#dataUTM').attr("data-media"); 25 var data_related_tags = $('#dataUTM').attr("data-related-tags"); 26 27 jQuery('input[value=\"$active_lang\"]').val(active_lang); 28 jQuery('input[value=\"$geolocation\"]').val(country_code_nf); 29 jQuery('input[value=\"$pardot_id\"]').val(pardotId); 30 jQuery('input[value=\"$google_id\"]').val(google_analytics_id); 31 32 jQuery('input[value=\"$utm_source\"]').val(utm_source); 33 jQuery('input[value=\"$utm_medium\"]').val(utm_medium); 34 jQuery('input[value=\"$utm_campaign\"]').val(utm_campaign); 35 jQuery('input[value=\"$utm_content\"]').val(utm_content); 36 jQuery('input[value=\"$utm_term\"]').val(utm_term); 37 38 jQuery('input[value=\"$page_category\"]').val(data_category); 39 jQuery('input[value=\"$page_format\"]').val(data_formats); 40 jQuery('input[value=\"$page_industry\"]').val(data_industry); 41 jQuery('input[value=\"$page_media_type\"]').val(data_media); 42 jQuery('input[value=\"$page_related_tags\"]').val(data_related_tags); 43 jQuery('input[value=\"$page_referrer_url\"]').val(document.referrer); 44 45 } 46); 47 48/* 49 * The following section of code add Nielsen styles to Ninjaform Radio list 50*/ 51function hide_unhide() { 52 function visibility_handler() { 53 function hide_onload(item, ind) { 54 var y = null; 55 y = item.nextElementSibling; 56 y.classList.add("invisible"); 57 } 58 function hide_onclick(item, ind) { 59 var y = null; 60 y = item.nextElementSibling; 61 item.onclick = () => { 62 (y.classList.contains("invisible")) ? y.classList.remove("invisible") : y.classList.add("invisible"); 63 } 64 } 65 var x = document.querySelectorAll(".field-wrap.listradio-wrap .nf-field-label"); 66 x.forEach(hide_onload); 67 x.forEach(hide_onclick); 68 } 69 70 var delayInMilliseconds = 2000; 71 setTimeout(visibility_handler, delayInMilliseconds); 72} 73document.addEventListener("DOMContentLoaded", hide_unhide); 74 75/** 76 * Get the UTM cookie value 77 * @return {string} utm_all_2 cookie or 'no_utm_cookie' 78 */ 79let getCookie = (cookieName='utm_all_2') => {
80 let cookieString = document.cookie.split('; ').find(cookie => cookie.includes(cookieName)); 81 return cookieString ? cookieString.substring(cookieString.indexOf('=')+1) : 'no_cookie-'+cookieName; 82} 83/** 84 * Modify form field value whihch contains "$utm_cookie" or "$custom_lead_id" or "$one_trust_cookie" 85 * and insert the utm cookie or the lead id 86 * @return {string} fieldData - return the modified fieldData 87 */ 88let leadIdUtmCookieGenerator = Marionette.Object.extend({ 89 fieldType: 'hidden', 90 initialize: function () { 91 Backbone.Radio.channel(this.fieldType).reply('get:submitData', this.getSubmitData); 92 }, 93 getSubmitData: function (fieldData) { 94 if (fieldData.value.startsWith('$custom_lead_id')) { // insert lead id 95 let dateTime = new Date(); 96 let timeStamp = dateTime.toISOString().replace('T', ' ').substring(0, 19); 97 let randomNumber = Math.floor(Math.random() * 1000000); 98 fieldData.value = `${randomNumber} | ${timeStamp}`; 99 } else if (fieldData.value === '$utm_cookie') { // insert utm cookie 100 fieldData.value = getCookie('utm_all_2'); 101 } else if (fieldData.value === '$one_trust_cookie') { //insert One Trust Cookie (OptanonConsent) 102 let cookieValue = decodeURIComponent(getCookie('OptanonConsent')); 103 let start = cookieValue.indexOf('groups'); 104 let end = cookieValue.indexOf('&',start); 105 if (start === -1){ 106 fieldData.value = 'no_one_trust_group_cookie'; 107 } 108 else { 109 if (end === -1) { 110 fieldData.value = cookieValue.substring(start); 111 } 112 else { 113 fieldData.value = cookieValue.substring(start,end); 114 } 115 } 116 } 117 return fieldData; 118 } 119 120}); 121 122$(function () { 123 new leadIdUtmCookieGenerator(); 124})
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.