1/* 2for $current_rel_uri see hp-shared.js 3for the php functions, see assets/php/_classes/tracking.php $hpTracking 4 5===== 6functions/detections: 7 8detections -- click, blur, etc 9pageinout() 10set_track() 11track() 12track_post() 13===== 14*/ 15 16try {//This loads in ../../functions.php just after jQuery, so be sure not to let it break, which can cause other scripts to fail!!! 17 18/** 19* detections -- click, blur, etc 20* to stop input|textarea from tracking, on the element, set data-track="false" 21*/ 22jQuery(document).ready(function($) { 23 $('.pagecontainer').on('click',function($e){ 24 set_track($e,'click'); 25 }); 26 $('input').on('focus',function($e){ 27 $(this).on('blur',function($e){ 28 // set_track($e,'blur'); 29 if (phpjs.empty($(this).attr('data-track'))) {set_track($e,'blur');} 30 }); 31 }); 32 $('textarea').on('focus',function($e){ 33 $(this).on('blur',function($e){ 34 // set_track($e,'blur'); 35 if (phpjs.empty($(this).attr('data-track'))) {set_track($e,'blur');} 36 }); 37 }); 38});// /jQuery(document).ready(function($) { 39 40/** 41 * pageinout() 42 * detections -- on visibilitychange 43 * i.e. tab/page loses focus by looking at another tab or navigating to another page 44 * 45 * see: 46 * https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon 47 * 48 * if the below is not good enough, see also 49 * https://nerdsway.herokuapp.com/blog/best-way-to-implement-time-on-page-in-vanilla-javascript-using-sendbeacon-vvwptpu/ 50 * 51 * $hpTracking->pageinout() 52 * logout tracked at $oLoginout->logout_member() 53 */ 54pageinout(); 55document.addEventListener('visibilitychange',function(){pageinout()}); 56function pageinout() { 57 // console.log('$current_rel_uri',$current_rel_uri); 58 59 var $pageinout = 'in'; 60 if (document.visibilityState === 'hidden') {$pageinout = 'out';} 61 // console.log('$pageinout',$pageinout); 62 63 var $skip = [ 64 '404', 65 '/admintools/', 66 '/sign-in/', 67 ]; 68 for(var $n = 0; $n < $skip.length;$n++) { 69 if ($current_rel_uri == $skip[$n]) {return false;} 70 } 71 72 // var $url = $jsphp_vars['parent_theme_file_uri']+'/assets/php/_classes/tracking.php?process=pageinout'; 73 var $url = $jsphp_vars['stylesheet_directory_uri']+'/assets/php/_classes/tracking.php'; 74 75 var $formdata = new FormData(); 76 $formdata.append('process','pageinout'); 77 $formdata.append('current_rel_uri',$current_rel_uri); 78 $formdata.append('pageinout',$pageinout); 79 80 if(navigator.sendBeacon) {navigator.sendBeacon($url,$formdata);} 81}// /function pageinout() { 82 83/** 84* set_track() 85* sets args from the detections above for $this->track() 86*/ 87function set_track($e,$obj_type) { 88 jQuery(document).ready(function($) { 89 90 var $obj = $($e.target);//console.log('$obj:',$obj); 91 92 // do NOT track empty blur objects, like text and textarea ===== 93 if ($obj_type == 'blur' && $obj.val() == '') {return false;} 94 // /do NOT track empty blur objects, like text and textarea ===== 95 96 var $obj_id = ''; 97 if (typeof $obj.attr('id') != 'undefined') {$obj_id = '#'+phpjs.trim($obj.attr('id'));} 98 else if (typeof $obj.attr('class') != 'undefined') {$obj_id = '.'+phpjs.trim($obj.attr('class')).replace(' ','.');} 99 if ($obj_id == '' && $obj_type != 'page-view') {return false;} 100 101 if ($obj_type == 'click') { 102 // do NOT bother to track blur objects on click ===== 103 if ($obj.is("input")) {return false;} 104 if ($obj.is("textarea")) {return false;} 105 // /do NOT bother to track blur objects on click ===== 106 107 // do not bother to track these EXACT $obj_id's ===== 108 var $skip_ids = [ 109 '#', 110 '.entry-title', 111 '.pagecontainer', 112 '.panel', 113 '.panel_wrapper', 114 '.wp-block-button', 115 '.wp-block-button__link', 116 '.wp-block-column', 117 '.wp-block-column-inner', 118 '.wp-block-columns', 119 '.wp-block-embed', 120 '.wp-block-embed__wrapper', 121 '.wp-block-group', 122 '.wp-block-group__inner-container', 123 '.wp-block-image', 124 ]; 125 var $skip_ids_pos = [ 126 '.wp-block-button.', 127 '.wp-block-columns.', 128 '.wp-block-group.', 129 '.wp-block-group__inner-container.', 130 '.wp-image-', 131 ]; 132 133 for (var $n = 0; $n < $skip_ids.length; $n++) { 134 if (phpjs.trim($obj_id) == phpjs.trim($skip_ids[$n])) {return false;} 135 } 136 for (var $n = 0; $n < $skip_ids_pos.length; $n++) { 137 if (phpjs.strpos(phpjs.trim($obj_id),phpjs.trim($skip_ids_pos[$n])) !== false) {return false;} 138 } 139 // /do not bother to track these EXACT $obj_id's ===== 140 141console.log('track - CLICK'); 142 if (typeof $obj.attr('href') != 'undefined') { 143 $obj_type = 'click-href'; 144 if ( 145 $obj.attr('href') != '' 146 && $obj.attr('href') != '#' 147 && (typeof $obj.attr('target') == 'undefined' || $obj.attr('target') != '_blank') 148 ) { 149 $e.preventDefault(); 150 } 151 } 152 } 153 if ($obj_type == 'blur') { 154console.log('track - BLUR'); 155 } 156 157 track($e,$obj,$obj_type,$obj_id); 158 159 });// /jQuery(document).ready(function($) { 160}// /function set_track() { 161 162/** track() 163* accessible by other scripts throughout the site, so jQuery involked INSIDE the function 164* sets up the vars for the ajax post 165*/ 166function track($e,$obj,$obj_type,$obj_id) { 167 jQuery(document).ready(function($) { 168 /* 169 console.log('$obj:',$obj); 170 console.log('$obj_type:',$obj_type); 171 console.log('$obj_id:',$obj_id); 172 */ 173 //var $test = true; 174 var $test = false; 175 176 //var $url = window.location.protocol+'//'+window.location.hostname+'/wp-content/themes/hotpepper_v4/assets/php/_classes/tracking.php'; 177 var $url = $jsphp_vars['parent_theme_file_uri']+'/assets/php/_classes/tracking.php'; 178 179 if (typeof $current_rel_uri === 'undefined') {$current_rel_uri = '';} 180 if ($test) {console.log('$current_rel_uri:',$current_rel_uri);} 181 182 var $post = { 183 'process':'track', 184 'obj_type':$obj_type, 185 'obj_id':$obj_id, 186 'url':$current_rel_uri, 187 'ajax':true, 188 }; 189 // to track all page-views, uncomment this: 190 // if ($obj_type == 'page-view') {$post['track_all'] = true;} 191 192 //console.log('$post:',$post); 193 194 track_post($e,$obj,$url,$post,$test); 195 });// /jQuery(document).ready(function($) { 196}// /function track() { 197 198/** 199* track_post() 200* ajax and a small bit of post processing 201* only triggered by $this->track() 202*/ 203function track_post($e,$obj,$url,$post,$test) { 204 jQuery(document).ready(function($) { 205 //console.log('$obj:',$obj); 206 //console.log('$url:',$url); 207 //console.log('$post:',$post); 208 //console.log('$test:',$test); 209 $.post($url,$post,function($data){
210 console.log('track:',$data); 211 if ($data == '' || $data == 0) { 212 //alert('Tracking failed.'); 213 console.log('track:','Tracking failed.'); 214 } 215 //console.log('$obj.attr(\'href\'):',$obj.attr('href')); 216 if ( 217 $obj != '' 218 && typeof $obj.attr('href') != 'undefined' 219 && $obj.attr('href') != '' 220 && $obj.attr('href') != '#' 221 && (typeof $obj.attr('target') == 'undefined' || $obj.attr('target') != '_blank') 222 ) { 223 window.location = $obj.attr('href'); 224 } 225 }); 226 });// /jQuery(document).ready(function($) { 227}// /function track_post() { 228 229} catch($err) { 230 console.log('tracking.js $err:',$err); 231}
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.