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