1/* clear old local storage */ 2localStorage.removeItem('wp_cta_impressions'); 3 4/** 5 * Record Impressions For Each Variation in CTA Object 6 * 7 * @param JSON ctas : a json string of {'cta':'vid'} 8 */ 9function wp_cta_record_impressions(ctas , page_id) { 10 11 /* Add Impressions to loaded varations*/ 12 jQuery.ajax({ 13 type: 'POST', 14 url: cta_variation.admin_url, 15 data: { 16 action: 'wp_cta_record_impressions', 17 cta_impressions: ctas, 18 page_id: page_id, 19 }, 20 success: function(user_id){ 21 _inbound.deBugger( 'cta', 'CTA Impressions Recorded'); 22 }, 23 error: function(MLHttpRequest, textStatus, errorThrown){ 24 25 } 26 27 }); 28 29} 30 31/** 32 * Adds Tracking Classes to Links and Forms to CTAs 33 * @param OBJECT ctas : object containing {'cta','vid'} 34 */ 35function wp_cta_add_tracking_classes(ctas) { 36 37 jQuery.each( ctas, function(cta_id,vid) { 38 var vid = ctas[cta_id]; 39 40 //console.log('CTA '+cta_id+' loads variation:' + vid); 41 jQuery('.wp_cta_'+cta_id+'_variation_'+vid).show(); 42 43 /* add tracking classes to links and forms */ 44 var wp_cta_id = '<input type="hidden" name="wp_cta_id" value="' + cta_id + '">'; 45 var wp_cta_vid = '<input type="hidden" name="wp_cta_vid" value="'+ vid +'">'; 46 jQuery('#wp_cta_'+cta_id+'_variation_'+vid+' form').each(function(){ 47 jQuery(this).addClass('wpl-track-me'); 48 jQuery(this).append(wp_cta_id); 49 jQuery(this).append(wp_cta_vid); 50 }); 51 52 53 /* add click tracking - get lead cookies */ 54 var lead_cpt_id = _inbound.Utils.readCookie("wp_lead_id"); 55 var lead_email = _inbound.Utils.readCookie("wp_lead_email"); 56 var lead_unique_key = _inbound.Utils.readCookie("wp_lead_uid"); 57 58 59 /* add click tracking - setup lead data for click event tracking */ 60 if (typeof (lead_cpt_id) != "undefined" && lead_cpt_id !== null) { 61 string = "&wpl_id=" + lead_cpt_id + "&l_type=wplid"; 62 } else if (typeof (lead_email) != "undefined" && lead_email !== null && lead_email !== "") { 63 string = "&wpl_id=" + lead_email + "&l_type=wplemail";; 64 } else if (typeof (lead_unique_key) != "undefined" && lead_unique_key !== null && lead_unique_key !== "") { 65 string = "&wpl_id=" + lead_unique_key + "&l_type=wpluid"; 66 } else { 67 string = ""; 68 } 69 70 }); 71} 72 73function wp_cta_load_variation( cta_id, vid ) { 74 75 /* get loaded ctas */ 76 var loaded_ctas = _inbound.totalStorage('wp_cta_loaded'); 77 if (loaded_ctas === null) { 78 var loaded_ctas = {}; 79 } 80 81 /* get cta impressions object */ 82 var cta_impressions = _inbound.totalStorage('wp_cta_impressions'); 83 if (cta_impressions === null) { 84 var cta_impressions = {}; 85 } 86 87 /* if variation is pre-defined then immediately load variation*/ 88 if ( typeof vid != 'undefined' && vid != null && vid != '' ) { 89 90 /* reveal variation */ 91 _inbound.debug('CTA '+cta_id+' loads variation:' + vid); 92 jQuery('.wp_cta_'+cta_id+'_variation_'+vid).show(); 93 94 /* set memory and record impression */ 95 loaded_ctas[cta_id] = vid; 96 cta_impressions[cta_id] = vid; 97 _inbound.totalStorage('wp_cta_loaded', loaded_ctas); // store cta data 98 _inbound.totalStorage('wp_cta_impressions', cta_impressions); // store cta data 99 100 /* add tracking classes */ 101 wp_cta_add_tracking_classes( loaded_ctas ); 102 103 } 104 /* if split testing is disabled then update wp_cta_loaded storage object with variation 0 */ 105 else if ( parseInt(cta_variation.split_testing) == 0 ) { 106 107 /* update local storage variable */ 108 loaded_ctas[cta_id] = 0; 109 cta_impressions[cta_id] = 0; 110 111 /* update local storage object */ 112 _inbound.totalStorage('wp_cta_loaded', loaded_ctas); // store cta data 113 _inbound.totalStorage('wp_cta_impressions', cta_impressions); // store cta data 114 _inbound.deBugger('WP CTA Load Object Updated:' + JSON.stringify(loaded_ctas)); 115 116 } 117 /* if variation not set yet or sticky cta setting is on */ 118 else if ( (cta_id in loaded_ctas) && parseInt(cta_variation.sticky_cta) == 1 ) { 119 cta_impressions[cta_id] = loaded_ctas[cta_id]; 120 _inbound.totalStorage('wp_cta_impressions', cta_impressions); // store cta data 121 122 } 123 /* get variation id via AJAX */ 124 else { 125 jQuery.ajax({ 126 type: "POST", 127 url: cta_variation.admin_url, 128 dataType: "html", 129 async: false, /* required atm */ 130 data : { 131 'action' : 'cta_get_variation', 132 'cta_id' : cta_id, 133 'fast_ajax': true,
134 'load_plugins': ["inbound-pro/inbound-pro.php","_inbound-now/inbound-pro.php","cta/calls-to-action.php"] 135 }, 136 success: function(vid) { 137 /* update local storage variable */ 138 loaded_ctas[cta_id] = vid.trim(); 139 140 /* update local storage history and impression objects */ 141 _inbound.totalStorage('wp_cta_loaded', loaded_ctas); // store cta data 142 _inbound.totalStorage('wp_cta_impressions', loaded_ctas); // store cta data 143 _inbound.deBugger( 'cta', 'WP CTA Load Object Updated:' + JSON.stringify(loaded_ctas) ); 144 } 145 }); 146 } 147} 148 149 150 151jQuery(document).ready(function($) { 152 153 var timeout = 500; 154 155 if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { 156 timeout = 500; 157 } 158 159 160 if (cta_variation.cta_id > 0) { 161 wp_cta_load_variation( cta_variation.cta_id , null ); 162 } 163 164 setTimeout( function() { 165 166 var ctas = _inbound.totalStorage('wp_cta_loaded'); 167 168 if(ctas === null || ctas === "undefined") { return false; } 169 170 /* Add Tracking Classes & Reveal CTAs */ 171 wp_cta_add_tracking_classes(ctas); 172 173 /* Record Impressions manually when page_tracking is off */ 174 if (cta_variation.page_tracking == 'off' && inbound_settings.post_type != 'landing-page') { 175 wp_cta_record_impressions(ctas , inbound_settings.post_id); 176 } 177 178 } , timeout ); 179 180});
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.