Changeset 2760263
- Timestamp:
- 07/22/2022 12:59:40 PM (4 years ago)
- Location:
- newsmanapp/trunk
- Files:
-
- 3 edited
-
includes/class-wc-newsman-remarketing-js.php (modified) (15 diffs)
-
newsmanapp.php (modified) (1 diff)
-
wc-newsman-remarketing.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
newsmanapp/trunk/includes/class-wc-newsman-remarketing-js.php
r2743446 r2760263 160 160 161 161 $ga_snippet_head = " 162 //Newsman remarketing tracking code 162 163 //Newsman remarketing tracking code REPLACEABLE 164 165 var remarketingid = '$remarketingid'; 166 var _nzmPluginInfo = '2.3.8:woocommerce'; 167 168 //Newsman remarketing tracking code REPLACEABLE 169 170 //Newsman remarketing tracking code 171 163 172 var endpoint = 'https://retargeting.newsmanapp.com'; 164 173 var remarketingEndpoint = endpoint + '/js/retargeting/track.js'; 165 var remarketingid = '$remarketingid'; 166 167 var _nzmPluginInfo = '2.3.7:woocommerce'; 174 168 175 var _nzm = _nzm || []; 169 176 var _nzm_config = _nzm_config || []; … … 193 200 //Newsman remarketing tracking code 194 201 202 //Newsman remarketing auto events REPLACEABLE 203 204 var ajaxurl = 'https://' + document.location.hostname + '?newsman=getCart.json'; 205 206 //Newsman remarketing auto events REPLACEABLE 207 195 208 //Newsman remarketing auto events 196 209 197 let _nzmIsProd = true;210 var isProd = true; 198 211 199 212 let lastCart = sessionStorage.getItem('lastCart'); 200 213 if (lastCart === null) 201 lastCart = {};214 lastCart = {}; 202 215 203 216 var lastCartFlag = false; … … 205 218 var bufferedXHR = false; 206 219 var unlockClearCart = true; 207 var ajaxurl = '" . get_site_url() . "?newsman=getCart.json';208 var documentComparer = '" . get_site_url() . "/';220 var isError = false; 221 var documentComparer = document.location.hostname; 209 222 var documentUrl = document.URL; 210 223 var sameOrigin = (documentUrl.indexOf(documentComparer) !== -1); 211 224 212 let startTime, endTime; 213 let retryS = 5; 214 var errorFirstLoad = true; 225 let startTime, endTime; 215 226 216 227 function startTimePassed() { … … 221 232 222 233 function endTimePassed() { 223 224 var flag = true; 234 var flag = false; 225 235 226 236 endTime = new Date(); … … 231 241 var seconds = Math.round(timeDiff); 232 242 233 if (errorFirstLoad)234 returntrue;235 236 if (seconds < retryS)237 flag = false;243 if (firstLoad) 244 flag = true; 245 246 if (seconds >= 5) 247 flag = true; 238 248 239 249 return flag; … … 247 257 } 248 258 259 function timestamp(min, max) { 260 min = Math.ceil(min); 261 max = Math.floor(max); 262 return Math.floor(Math.random() * (max - min + 1)) + min; 263 } 264 249 265 function NewsmanAutoEvents() { 250 266 251 267 if (!endTimePassed()) 252 {253 if (!_nzmIsProd)254 console.log('newsman remarketing: endTimePassed false, exit execution');255 256 268 return; 269 270 if (isError && isProd == true) { 271 console.log('newsman remarketing: an error occurred, set isProd = false in console, script execution stopped;'); 272 273 return; 257 274 } 258 275 … … 261 278 if (bufferedXHR || firstLoad) { 262 279 263 xhr.open('GET', ajaxurl, true); 280 var paramChar = '?t='; 281 282 if (ajaxurl.indexOf('?') >= 0) 283 paramChar = '&t='; 284 285 var timestamp = paramChar + Date.now() + this.timestamp(999, 999999999); 286 287 xhr.open('GET', ajaxurl + timestamp, true); 264 288 265 289 startTimePassed(); … … 269 293 if (xhr.status == 200 || xhr.status == 201) { 270 294 271 try {295 try { 272 296 var response = JSON.parse(xhr.responseText); 297 } catch (error) { 298 if (!isProd) 299 console.log('newsman remarketing: error occured json parsing response'); 300 301 isError = true; 302 303 return; 273 304 } 274 catch(ex)275 {276 retryS += 5;277 278 errorFirstLoad = false;279 280 if (!_nzmIsProd)281 {282 console.log('newsman remarketing: error occurred on parsing xhr');283 console.log('newsman remarketing: error: ' + ex);284 }285 286 return;287 }288 305 289 306 lastCart = JSON.parse(sessionStorage.getItem('lastCart')); … … 295 312 if (lastCart.length > 0 && lastCart != null && lastCart != undefined && response.length > 0 && response != null && response != undefined) { 296 313 if (JSON.stringify(lastCart) === JSON.stringify(response)) { 297 if (! _nzmIsProd)314 if (!isProd) 298 315 console.log('newsman remarketing: cache loaded, cart is unchanged'); 299 316 … … 302 319 lastCartFlag = false; 303 320 304 if (! _nzmIsProd)321 if (!isProd) 305 322 console.log('newsman remarketing: cache loaded, cart is changed'); 306 323 } … … 317 334 clearCart(); 318 335 319 if (! _nzmIsProd)336 if (!isProd) 320 337 console.log('newsman remarketing: clear cart sent'); 321 338 322 339 } else { 323 340 324 if (! _nzmIsProd)341 if (!isProd) 325 342 console.log('newsman remarketing: request not sent'); 326 343 327 344 } 328 345 346 firstLoad = false; 347 bufferedXHR = false; 348 349 } else { 350 if (!isProd) 351 console.log('newsman remarketing: response http status code is not 200'); 352 353 isError = true; 329 354 } 330 355 331 firstLoad = false;332 bufferedXHR = false;333 errorFirstLoad = false;334 335 356 } 336 357 … … 338 359 339 360 } else { 340 if (! _nzmIsProd)341 console.log('newsman remarketing: !buffered xhr || !first load');361 if (!isProd) 362 console.log('newsman remarketing: !buffered xhr || first load'); 342 363 } 343 364 … … 358 379 359 380 _nzm.run('ec:setAction', 'clear_cart'); 360 361 try{ 362 363 _nzm.run('send', 'event', 'detail view', 'click', 'clearCart', null, _nzm.createFunctionWithTimeout(function() { 364 365 for (var item in response) { 366 367 _nzm.run('ec:addProduct', 368 response[item] 369 ); 370 371 } 372 373 _nzm.run('ec:setAction', 'add'); 374 _nzm.run('send', 'event', 'UX', 'click', 'add to cart'); 375 376 sessionStorage.setItem('lastCart', JSON.stringify(response)); 377 unlockClearCart = true; 378 379 if (!_nzmIsProd) 380 console.log('newsman remarketing: cart sent'); 381 382 })); 383 384 } 385 catch(ex){ 386 387 retryS += 5; 388 389 errorFirstLoad = false; 390 391 if (!_nzmIsProd) 392 { 393 console.log('newsman remarketing: add to cart failed, error loading tracking code (adblock, or other problem)'); 394 console.log('newsman remarketing: error: ' + ex); 381 _nzm.run('send', 'event', 'detail view', 'click', 'clearCart', null, _nzm.createFunctionWithTimeout(function() { 382 383 for (var item in response) { 384 385 _nzm.run('ec:addProduct', 386 response[item] 387 ); 388 395 389 } 396 390 397 } 391 _nzm.run('ec:setAction', 'add'); 392 _nzm.run('send', 'event', 'UX', 'click', 'add to cart'); 393 394 sessionStorage.setItem('lastCart', JSON.stringify(response)); 395 unlockClearCart = true; 396 397 if (!isProd) 398 console.log('newsman remarketing: cart sent'); 399 400 })); 398 401 399 402 } … … 416 419 //own request exclusion 417 420 if ( 418 pointer.responseURL.indexOf('getCart.json') >= 0 ||419 //magento 2-2.3.x420 pointer.responseURL.indexOf('/static/') >= 0 ||421 pointer.responseURL.indexOf('/pub/static') >= 0 ||422 pointer.responseURL.indexOf('/customer/section') >= 0 ||423 //opencart 1424 pointer.responseURL.indexOf('getCart=true') >= 0421 pointer.responseURL.indexOf('getCart.json') >= 0 || 422 //magento 2.x 423 pointer.responseURL.indexOf('/static/') >= 0 || 424 pointer.responseURL.indexOf('/pub/static') >= 0 || 425 pointer.responseURL.indexOf('/customer/section') >= 0 || 426 //opencart 1 427 pointer.responseURL.indexOf('getCart=true') >= 0 425 428 ) { 426 429 validate = false; … … 433 436 bufferedXHR = true; 434 437 435 if (! _nzmIsProd)438 if (!isProd) 436 439 console.log('newsman remarketing: ajax request fired and catched from same domain'); 437 440 -
newsmanapp/trunk/newsmanapp.php
r2743446 r2760263 5 5 Plugin URI: https://github.com/Newsman/WP-Plugin-NewsmanApp 6 6 Description: NewsmanApp for Wordpress (sign up widget, subscribers sync, create and send newsletters from blog posts) 7 Version: 2.3. 77 Version: 2.3.8 8 8 Author: Newsman 9 9 Author URI: https://www.newsman.com -
newsmanapp/trunk/wc-newsman-remarketing.php
r2743446 r2760263 6 6 * Author: Newsman 7 7 * Author URI: https://newsman.com 8 * Version: 2.3. 78 * Version: 2.3.8 9 9 * WC requires at least: 2.1 10 10 * WC tested up to: 4.1 … … 80 80 81 81 } 82 83 $this->_json($prod); 84 return; 82 83 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); 84 header("Cache-Control: post-check=0, pre-check=0", false); 85 header("Pragma: no-cache"); 86 header('Content-Type:application/json'); 87 echo json_encode($prod, JSON_PRETTY_PRINT); 88 exit; 85 89 86 90 break;
Note: See TracChangeset
for help on using the changeset viewer.