1/* global pysOptions */ 2 3// https://bitbucket.org/pixelyoursite/pys_pro_7/issues/7/possible-ie-11-error 4// https://tc39.github.io/ecma262/#sec-array.prototype.includes 5if (!Array.prototype.includes) { 6 Object.defineProperty(Array.prototype, 'includes', { 7 value: function (searchElement, fromIndex) { 8 9 if (this == null) { 10 throw new TypeError('"this" is null or not defined'); 11 } 12 13 // 1. Let O be ? ToObject(this value). 14 var o = Object(this); 15 16 // 2. Let len be ? ToLength(? Get(O, "length")). 17 var len = o.length >>> 0; 18 19 // 3. If len is 0, return false. 20 if (len === 0) { 21 return false; 22 } 23 24 // 4. Let n be ? ToInteger(fromIndex). 25 // (If fromIndex is undefined, this step produces the value 0.) 26 var n = fromIndex | 0; 27 28 // 5. If n ⥠0, then 29 // a. Let k be n. 30 // 6. Else n < 0, 31 // a. Let k be len + n. 32 // b. If k < 0, let k be 0. 33 var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); 34 35 function sameValueZero(x, y) { 36 return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); 37 } 38 39 // 7. Repeat, while k < len 40 while (k < len) { 41 // a. Let elementK be the result of ? Get(O, ! ToString(k)). 42 // b. If SameValueZero(searchElement, elementK) is true, return true. 43 if (sameValueZero(o[k], searchElement)) { 44 return true; 45 } 46 // c. Increase k by 1. 47 k++; 48 } 49 50 // 8. Return false 51 return false; 52 } 53 }); 54} 55 56!function ($, options) { 57 58 if (options.debug) { 59 console.log('PYS:', options); 60 } 61 62 var dummyPinterest = function () { 63 64 /** 65 * Public API 66 */ 67 return { 68 69 isEnabled: function () { 70 }, 71 72 disable: function () { 73 }, 74 75 loadPixel: function () { 76 }, 77 78 fireEvent: function (name, data) { 79 return false; 80 }, 81 82 onCommentEvent: function () { 83 }, 84 85 onDownloadEvent: function (params) { 86 }, 87 88 onFormEvent: function (params) { 89 }, 90 91 onWooAddToCartOnButtonEvent: function (product_id) { 92 }, 93 94 onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, is_external, $form) { 95 }, 96 97 onWooRemoveFromCartEvent: function (cart_item_hash) { 98 }, 99 100 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 101 }, 102 103 onEddRemoveFromCartEvent: function (item) { 104 }, 105 onPageScroll: function (event) {}, 106 onTime: function (event) { 107 108 }, 109 110 } 111 112 }(); 113 114 var dummyBing = function () { 115 116 /** 117 * Public API 118 */ 119 return { 120 121 isEnabled: function () { 122 }, 123 124 disable: function () { 125 }, 126 127 loadPixel: function () { 128 }, 129 130 fireEvent: function (name, data) { 131 return false; 132 }, 133 134 onAdSenseEvent: function () { 135 }, 136 137 onClickEvent: function (params) { 138 }, 139 140 onWatchVideo: function (params) { 141 }, 142 143 onCommentEvent: function () { 144 }, 145 146 onFormEvent: function (params) { 147 }, 148 149 onDownloadEvent: function (params) { 150 }, 151 152 onWooAddToCartOnButtonEvent: function (product_id) { 153 }, 154 155 onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, is_external, $form) { 156 }, 157 158 onWooRemoveFromCartEvent: function (cart_item_hash) { 159 }, 160 161 onWooAffiliateEvent: function (product_id) { 162 }, 163 164 onWooPayPalEvent: function () { 165 }, 166 167 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 168 }, 169 170 onEddRemoveFromCartEvent: function (item) { 171 }, 172 173 onPageScroll: function (event) { 174 }, 175 176 onTime: function (event) { 177 }, 178 179 } 180 181 }(); 182 183 var Utils = function (options) { 184 185 var Pinterest = dummyPinterest; 186 187 var Bing = dummyBing; 188 189 var gtag_loaded = false;
190 191 let isNewSession = checkSession(); 192 193 var utmTerms = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']; 194 195 var utmId = ['fbadid', 'gadid', 'padid', 'bingid']; 196 197 function validateEmail(email) { 198 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 199 return re.test(email); 200 } 201 function getDomain(url) { 202 203 url = url.replace(/(https?:\/\/)?(www.)?/i, ''); 204 205 if (url.indexOf('/') !== -1) { 206 return url.split('/')[0]; 207 } 208 209 return url; 210 } 211 function loadPixels() { 212 213 if (!options.gdpr.all_disabled_by_api) { 214 215 if (!options.gdpr.facebook_disabled_by_api) { 216 Facebook.loadPixel(); 217 } 218 219 if (!options.gdpr.analytics_disabled_by_api) { 220 Analytics.loadPixel(); 221 } 222 223 if (!options.gdpr.pinterest_disabled_by_api) { 224 Pinterest.loadPixel(); 225 } 226 227 if (!options.gdpr.bing_disabled_by_api) { 228 Bing.loadPixel(); 229 } 230 } 231 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 232 if (typeof CS_Data.cs_google_analytics_consent_mode !== "undefined" && CS_Data.cs_google_analytics_consent_mode == 1) { 233 Analytics.loadPixel(); 234 } 235 } 236 237 } 238 239 function checkSession() { 240 if( Cookies.get('pys_start_session') === undefined || 241 Cookies.get('pys_session_limit') === undefined) { 242 firstVisit = true; 243 return true 244 } 245 return false 246 247 } 248 249 function getTrafficSource() { 250 251 try { 252 253 let referrer = document.referrer.toString(), 254 source; 255 256 let direct = referrer.length === 0; 257 let internal = direct ? false : referrer.indexOf(options.siteUrl) === 0; 258 let external = !direct && !internal; 259 260 if (external === false) { 261 source = 'direct'; 262 } else { 263 source = referrer; 264 } 265 266 if (source !== 'direct') { 267 // leave only domain (Issue #70) 268 return getDomain(source); 269 } else { 270 return source; 271 } 272 273 } catch (e) { 274 console.error(e); 275 return 'direct'; 276 } 277 278 } 279 280 /** 281 * Return query variables object with where property name is query variable 282 * and property value is query variable value. 283 */ 284 function getQueryVars() { 285 286 try { 287 288 var result = {}, 289 tmp = []; 290 291 window.location.search 292 .substr(1) 293 .split("&") 294 .forEach(function (item) { 295 296 tmp = item.split('='); 297 298 if (tmp.length > 1) { 299 result[tmp[0]] = tmp[1]; 300 } 301 302 }); 303 304 return result; 305 306 } catch (e) { 307 console.error(e); 308 return {}; 309 } 310 311 } 312 313 314 function getLandingPageValue() { 315 let name = "pys_landing_page" 316 if(options.visit_data_model === "last_visit") { 317 name = "last_pys_landing_page" 318 } 319 if(Cookies.get(name) && Cookies.get(name) !== "undefined") { 320 return Cookies.get(name); 321 } 322 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficLanding){ 323 return options.tracking_analytics.TrafficLanding; 324 } else{ 325 return ""; 326 } 327 } 328 function getTrafficSourceValue() { 329 let name = "pysTrafficSource" 330 if(options.visit_data_model === "last_visit") { 331 name = "last_pysTrafficSource" 332 } 333 if(Cookies.get(name) && Cookies.get(name) !== "undefined") { 334 return Cookies.get(name); 335 } 336 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficSource){ 337 return options.tracking_analytics.TrafficSource; 338 } else{ 339 return ""; 340 } 341 } 342 343 function getUTMId(useLast = false) { 344 try { 345 let cookiePrefix = 'pys_' 346 let terms = []; 347 if (useLast) { 348 cookiePrefix = 'last_pys_' 349 } 350 $.each(utmId, function (index, name) { 351 if (Cookies.get(cookiePrefix + name)) { 352 terms[name] = Cookies.get(cookiePrefix + name) 353 } 354 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficUtmsId[name]) { 355 terms[name] = filterEmails(options.tracking_analytics.TrafficUtmsId[name]) 356 } 357 }); 358 return terms; 359 } catch (e) { 360 console.error(e); 361 return []; 362 } 363 } 364 /** 365 * Return UTM terms from request query variables or from cookies. 366 */ 367 function getUTMs(useLast = false) { 368 369 try { 370 let cookiePrefix = 'pys_' 371 if(useLast) { 372 cookiePrefix = 'last_pys_' 373 } 374 let terms = []; 375 $.each(utmTerms, function (index, name) { 376 if (Cookies.get(cookiePrefix + name)) { 377 let value = Cookies.get(cookiePrefix + name); 378 terms[name] = filterEmails(value); // do not allow email in request params (Issue #70) 379 } 380 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficUtms[name]) { 381 terms[name] = filterEmails(options.tracking_analytics.TrafficUtms[name]) 382 } 383 }); 384 385 return terms; 386 387 } catch (e) { 388 console.error(e); 389 return []; 390 } 391 392 } 393 394 function getDateTime() { 395 var dateTime = new Array(); 396 var date = new Date(), 397 days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], 398 months = ['January', 'February', 'March', 'April', 'May', 'June', 399 'July', 'August', 'September', 'October', 'November', 'December' 400 ], 401 hours = ['00-01', '01-02', '02-03', '03-04', '04-05', '05-06', '06-07', '07-08', 402 '08-09', '09-10', '10-11', '11-12', '12-13', '13-14', '14-15', '15-16', '16-17', 403 '17-18', '18-19', '19-20', '20-21', '21-22', '22-23', '23-24' 404 ]; 405 dateTime.push(hours[date.getHours()]); 406 dateTime.push(days[date.getDay()]); 407 dateTime.push(months[date.getMonth()]); 408 return dateTime; 409 } 410 411 function filterEmails(value) { 412 return validateEmail(value) ? undefined : value; 413 } 414 415 /** 416 * PUBLIC API 417 */ 418 return { 419 PRODUCT_SIMPLE : 0, 420 PRODUCT_VARIABLE : 1, 421 PRODUCT_BUNDLE : 2, 422 PRODUCT_GROUPED : 3, 423 utmTerms : utmTerms, 424 utmId : utmId, 425 fireEventForAllPixel:function(functionName,events){ 426 if (events.hasOwnProperty(Facebook.tag())) 427 Facebook[functionName](events[Facebook.tag()]); 428 if (events.hasOwnProperty(Analytics.tag())) 429 Analytics[functionName](events[Analytics.tag()]); 430 if (events.hasOwnProperty(Pinterest.tag())) 431 Pinterest[functionName](events[Pinterest.tag()]); 432 if (events.hasOwnProperty(Bing.tag())) 433 Bing[functionName](events[Bing.tag()]); 434 }, 435 436 setupPinterestObject: function () { 437 Pinterest = window.pys.Pinterest || Pinterest; 438 return Pinterest; 439 }, 440 441 setupBingObject: function () { 442 Bing = window.pys.Bing || Bing; 443 return Bing; 444 }, 445 446 // Clone all object members to another and return it 447 copyProperties: function (from, to) { 448 for (var key in from) { 449 if("function" == typeof from[key]) { 450 continue; 451 } 452 to[key] = from[key]; 453 } 454 return to; 455 }, 456 457 manageCookies: function () { 458 459 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 460 if (Cookiebot.consented === false && !Cookiebot.consent['marketing'] && !Cookiebot.consent['statistics']) { 461 return; 462 } 463 } 464 let cm_consent_not_expressed = false;
465 if ( options.gdpr.consent_magic_integration_enabled && window.CS_Data !== undefined && window.CS_Data.cs_refresh_after_consent == 1 ) { 466 if ( Cookies.get( 'cs_viewed_cookie_policy' ) === undefined ) { 467 cm_consent_not_expressed = true; 468 } 469 } 470 471 if( !cm_consent_not_expressed && isNewSession && !options.cookie.disabled_all_cookie && !options.cookie.disabled_start_session_cookie) { 472 let duration = options.last_visit_duration * 60000 473 var now = new Date(); 474 now.setTime(now.getTime() + duration); 475 Cookies.set('pys_session_limit', true,{ expires: now }) 476 Cookies.set('pys_start_session', true); 477 } 478 if (options.gdpr.ajax_enabled && !options.gdpr.consent_magic_integration_enabled) { 479 480 // retrieves actual PYS GDPR filters values which allow to avoid cache issues 481 $.get({ 482 url: options.ajaxUrl, 483 dataType: 'json', 484 data: { 485 action: 'pys_get_gdpr_filters_values' 486 }, 487 success: function (res) { 488 489 if (res.success) { 490 491 options.gdpr.all_disabled_by_api = res.data.all_disabled_by_api; 492 options.gdpr.facebook_disabled_by_api = res.data.facebook_disabled_by_api; 493 options.gdpr.tiktok_disabled_by_api = res.data.tiktok_disabled_by_api; 494 options.gdpr.analytics_disabled_by_api = res.data.analytics_disabled_by_api; 495 options.gdpr.google_ads_disabled_by_api = res.data.google_ads_disabled_by_api; 496 options.gdpr.pinterest_disabled_by_api = res.data.pinterest_disabled_by_api; 497 options.gdpr.bing_disabled_by_api = res.data.bing_disabled_by_api; 498 499 options.cookie.externalID_disabled_by_api = res.data.externalID_disabled_by_api; 500 options.cookie.disabled_all_cookie = res.data.disabled_all_cookie; 501 options.cookie.disabled_advanced_form_data_cookie = res.data.disabled_advanced_form_data_cookie; 502 options.cookie.disabled_landing_page_cookie = res.data.disabled_landing_page_cookie; 503 options.cookie.disabled_first_visit_cookie = res.data.disabled_first_visit_cookie; 504 options.cookie.disabled_trafficsource_cookie = res.data.disabled_trafficsource_cookie; 505 options.cookie.disabled_utmTerms_cookie = res.data.disabled_utmTerms_cookie; 506 options.cookie.disabled_utmId_cookie = res.data.disabled_utmId_cookie; 507 508 } 509 } 510 }); 511 } 512 if (options.ajaxForServerEvent && !Cookies.get('pbid')) { 513 if(Facebook.advancedMatching() && Facebook.advancedMatching().external_id && !(options.cookie.disabled_all_cookie || options.cookie.externalID_disabled_by_api)){ 514 let expires = parseInt(options.external_id_expire || 180); 515 Cookies.set('pbid', Facebook.advancedMatching().external_id, { expires: expires, path: '/' }); 516 } 517 else{ 518 jQuery.ajax({ 519 url: options.ajaxUrl, 520 dataType: 'json', 521 data: { 522 action: 'pys_get_pbid' 523 }, 524 success: function (res) { 525 if (res.data && res.data.pbid != false && options.send_external_id) { 526 if(!(options.cookie.disabled_all_cookie || options.cookie.externalID_disabled_by_api)){ 527 var expires = parseInt(options.external_id_expire || 180); 528 Cookies.set('pbid', res.data.pbid, { expires: expires, path: '/' }); 529 } 530 531 if(options.hasOwnProperty('facebook')) { 532 options.facebook.advancedMatching = { 533 ...options.facebook.advancedMatching, // ÑаÑпÑлÑем ÑекÑÑие знаÑÐµÐ½Ð¸Ñ advancedMatching 534 external_id: res.data.pbid 535 }; 536 } 537 } 538 } 539 }); 540 } 541 542 } 543 let expires = parseInt(options.cookie_duration); // days 544 let queryVars = getQueryVars(); 545 let landing = window.location.href.split('?')[0]; 546 try { 547 // save data for first visit 548 if(Cookies.get('pys_first_visit') === undefined && (!options.cookie.disabled_all_cookie)) { 549 550 if(!options.cookie.disabled_first_visit_cookie) 551 { 552 Cookies.set('pys_first_visit', true, { expires: expires }); 553 } 554 else { 555 Cookies.remove('pys_first_visit') 556 } 557 558 if(!options.cookie.disabled_trafficsource_cookie) 559 { 560 Cookies.set('pysTrafficSource', getTrafficSource(), { expires: expires }); 561 } 562 else { 563 Cookies.remove('pysTrafficSource') 564 } 565 566 if(!options.cookie.disabled_landing_page_cookie) 567 { 568 Cookies.set('pys_landing_page',landing,{ expires: expires }); 569 } 570 else { 571 Cookies.remove('pys_landing_page') 572 } 573 574 if(!options.cookie.disabled_utmTerms_cookie) 575 { 576 $.each(utmTerms, function (index, name) { 577 if (queryVars.hasOwnProperty(name)) { 578 Cookies.set('pys_' + name, queryVars[name], { expires: expires }); 579 } else { 580 Cookies.remove('pys_' + name) 581 } 582 }); 583 } 584 else { 585 $.each(utmTerms, function (index, name) { 586 Cookies.remove('pys_' + name) 587 }); 588 } 589 590 if(!options.cookie.disabled_utmId_cookie) 591 { 592 $.each(utmId,function(index,name) { 593 if (queryVars.hasOwnProperty(name)) { 594 Cookies.set('pys_' + name, queryVars[name], { expires: expires }); 595 } else { 596 Cookies.remove('pys_' + name) 597 } 598 }) 599 } 600 else { 601 $.each(utmId, function (index, name) { 602 Cookies.remove('pys_' + name) 603 }); 604 } 605 } 606 607 // save data for last visit if it new session 608 if(isNewSession && (!options.cookie.disabled_all_cookie)) { 609 if(!options.cookie.disabled_trafficsource_cookie) 610 { 611 Cookies.set('last_pysTrafficSource', getTrafficSource(), { expires: expires }); 612 } 613 else { 614 Cookies.remove('last_pysTrafficSource') 615 } 616 617 if(!options.cookie.disabled_landing_page_cookie) 618 { 619 Cookies.set('last_pys_landing_page',landing,{ expires: expires }); 620 } 621 else { 622 Cookies.remove('last_pys_landing_page') 623 } 624 625 if(!options.cookie.disabled_utmTerms_cookie) 626 { 627 $.each(utmTerms, function (index, name) { 628 if (queryVars.hasOwnProperty(name)) { 629 Cookies.set('last_pys_' + name, queryVars[name], { expires: expires }); 630 } else { 631 Cookies.remove('last_pys_' + name) 632 } 633 }); 634 } 635 else { 636 $.each(utmTerms, function (index, name) { 637 Cookies.remove('last_pys_' + name) 638 }); 639 } 640 641 if(!options.cookie.disabled_utmId_cookie) 642 { 643 $.each(utmId,function(index,name) { 644 if (queryVars.hasOwnProperty(name)) { 645 Cookies.set('last_pys_' + name, queryVars[name], { expires: expires }); 646 } else { 647 Cookies.remove('last_pys_' + name) 648 } 649 }) 650 } 651 else { 652 $.each(utmId, function (index, name) { 653 Cookies.remove('last_pys_' + name) 654 }); 655 } 656 657 } 658 if(options.cookie.disabled_start_session_cookie) { 659 Cookies.remove('pys_start_session') 660 Cookies.remove('pys_session_limit') 661 } 662 if(options.cookie.disabled_all_cookie) 663 { 664 Cookies.remove('pys_first_visit') 665 Cookies.remove('pysTrafficSource') 666 Cookies.remove('pys_landing_page') 667 Cookies.remove('last_pys_landing_page') 668 Cookies.remove('last_pysTrafficSource') 669 Cookies.remove('pys_start_session') 670 Cookies.remove('pys_session_limit') 671 $.each(Utils.utmTerms, function (index, name) { 672 Cookies.remove('pys_' + name) 673 }); 674 $.each(Utils.utmId,function(index,name) { 675 Cookies.remove('pys_' + name) 676 }) 677 $.each(Utils.utmTerms, function (index, name) { 678 Cookies.remove('last_pys_' + name) 679 }); 680 $.each(Utils.utmId,function(index,name) { 681 Cookies.remove('last_pys_' + name) 682 }); 683 } 684 } catch (e) { 685 console.error(e); 686 } 687 }, 688 // clone object 689 clone: function(obj) { 690 var copy; 691 692 // Handle the 3 simple types, and null or undefined 693 if (null == obj || "object" != typeof obj) return obj; 694 695 // Handle Date 696 if (obj instanceof Date) { 697 copy = new Date(); 698 copy.setTime(obj.getTime()); 699 return copy; 700 } 701 702 // Handle Array 703 if (obj instanceof Array) { 704 copy = []; 705 for (var i = 0, len = obj.length; i < len; i++) { 706 if("function" == typeof obj[i]) { 707 continue; 708 } 709 copy[i] = Utils.clone(obj[i]); 710 } 711 return copy; 712 } 713 714 // Handle Object 715 if (obj instanceof Object) { 716 copy = {}; 717 for (var attr in obj) { 718 if (obj.hasOwnProperty(attr)) { 719 if("function" == typeof obj[attr]) { 720 continue; 721 } 722 copy[attr] = Utils.clone(obj[attr]); 723 } 724 } 725 return copy; 726 } 727 728 return obj; 729 }, 730 731 // Returns array of elements with given tag name 732 getTagsAsArray: function (tag) { 733 return [].slice.call(document.getElementsByTagName(tag)); 734 }, 735
736 getRequestParams: function () { 737 return []; 738 }, 739 740 /** 741 * CUSTOM EVENTS 742 */ 743 744 setupMouseOverClickEvents: function (eventId, triggers) { 745 746 // Non-default binding used to avoid situations when some code in external js 747 // stopping events propagation, eg. returns false, and our handler will never called 748 document.addEventListener('mouseover', function(event) { 749 var matchedElements = Array.from(document.querySelectorAll(triggers)); 750 if (matchedElements.includes(event.target)) { 751 if (event.target.classList.contains('pys-mouse-over-' + eventId)) { 752 return true; 753 } else { 754 event.target.classList.add('pys-mouse-over-' + eventId); 755 } 756 757 Utils.fireTriggerEvent(eventId); 758 } 759 }); 760 761 }, 762 763 setupCSSClickEvents: function (eventId, triggers) { 764 // Non-default binding used to avoid situations when some code in external js 765 // stopping events propagation, eg. returns false, and our handler will never called 766 document.addEventListener('click', function(event) { 767 var matchedElements = Array.from(document.querySelectorAll(triggers)); 768 if (matchedElements.includes(event.target)) { 769 console.log(event.target) 770 Utils.fireTriggerEvent(eventId); 771 } 772 }, true); 773 }, 774 775 setupURLClickEvents: function () { 776 777 // Non-default binding used to avoid situations when some code in external js 778 // stopping events propagation, eg. returns false, and our handler will never called 779 $('a[data-pys-event-id]').onFirst('click', function (evt) { 780 781 $(this).attr('data-pys-event-id').split(',').forEach(function (eventId) { 782 783 eventId = parseInt(eventId); 784 785 if (isNaN(eventId) === false) { 786 Utils.fireTriggerEvent(eventId); 787 } 788 789 }); 790 791 }); 792 793 794 }, 795 796 setupScrollPosEvents: function (eventId, triggers) { 797 798 var scrollPosThresholds = {}, 799 docHeight = $(document).height() - $(window).height(); 800 801 // convert % to absolute positions 802 $.each(triggers, function (index, scrollPos) { 803 804 // convert % to pixels 805 scrollPos = docHeight * scrollPos / 100; 806 scrollPos = Math.round(scrollPos); 807 808 scrollPosThresholds[scrollPos] = eventId; 809 810 }); 811 812 $(document).on("scroll",function () { 813 814 var scrollPos = $(window).scrollTop(); 815 816 $.each(scrollPosThresholds, function (threshold, eventId) { 817 818 // position has not reached yes 819 if (scrollPos <= threshold) { 820 return true; 821 } 822 823 // fire event only once 824 if (eventId === null) { 825 return true; 826 } else { 827 scrollPosThresholds[threshold] = null; 828 } 829 830 Utils.fireTriggerEvent(eventId); 831 832 }); 833 834 }); 835 836 837 }, 838 setupCommentEvents : function (eventId,triggers) { 839 $('form.comment-form').on("submit",function () { 840 Utils.fireTriggerEvent(eventId); 841 }); 842 }, 843 844 /** 845 * Events 846 */ 847 848 fireTriggerEvent: function (eventId) { 849 850 if (!options.triggerEvents.hasOwnProperty(eventId)) { 851 return; 852 } 853 854 var event = {}; 855 var events = options.triggerEvents[eventId]; 856 857 if (events.hasOwnProperty('facebook')) { 858 event = events.facebook; 859 Facebook.fireEvent(event.name, event); 860 } 861 862 if (events.hasOwnProperty('ga')) { 863 event = events.ga; 864 Analytics.fireEvent(event.name, event); 865 } 866 867 if (events.hasOwnProperty('pinterest')) { 868 event = events.pinterest; 869 Pinterest.fireEvent(event.name, event); 870 } 871 872 if (events.hasOwnProperty('bing')) { 873 event = events.bing; 874 Bing.fireEvent(event.name, event); 875 } 876 }, 877 878 fireStaticEvents: function (pixel) { 879 880 if (options.staticEvents.hasOwnProperty(pixel)) { 881 882 $.each(options.staticEvents[pixel], function (eventName, events) { 883 $.each(events, function (index, eventData) { 884 885 eventData.fired = eventData.fired || false; 886 887 if (!eventData.fired) { 888 889 var fired = false;
890 891 // fire event 892 if ('facebook' === pixel) { 893 fired = Facebook.fireEvent(eventData.name, eventData); 894 } else if ('ga' === pixel) { 895 fired = Analytics.fireEvent(eventData.name, eventData); 896 } else if ('pinterest' === pixel) { 897 fired = Pinterest.fireEvent(eventData.name, eventData); 898 } else if ('bing' === pixel) { 899 fired = Bing.fireEvent(eventData.name, eventData); 900 } 901 902 // prevent event double event firing 903 eventData.fired = fired; 904 905 } 906 907 }); 908 }); 909 910 } 911 912 }, 913 914 /** 915 * Load tag's JS 916 * 917 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/ 918 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets 919 */ 920 loadGoogleTag: function (id) { 921 922 if (!gtag_loaded) { 923 924 (function (window, document, src) { 925 var a = document.createElement('script'), 926 m = document.getElementsByTagName('script')[0]; 927 a.async = 1; 928 a.src = src; 929 m.parentNode.insertBefore(a, m); 930 })(window, document, '//www.googletagmanager.com/gtag/js?id=' + id); 931 932 window.dataLayer = window.dataLayer || []; 933 window.gtag = window.gtag || function gtag() { 934 dataLayer.push(arguments); 935 }; 936 937 gtag('js', new Date()); 938 939 if ( options.google_consent_mode ) { 940 let data = {}; 941 data[ 'analytics_storage' ] = options.gdpr.analytics_storage.enabled ? options.gdpr.analytics_storage.value : 'granted'; 942 data[ 'ad_storage' ] = options.gdpr.ad_storage.enabled ? options.gdpr.ad_storage.value : 'granted'; 943 data[ 'ad_user_data' ] = options.gdpr.ad_user_data.enabled ? options.gdpr.ad_user_data.value : 'granted'; 944 data[ 'ad_personalization' ] = options.gdpr.ad_personalization.enabled ? options.gdpr.ad_personalization.value : 'granted'; 945 946 gtag( 'consent', 'default', data ); 947 } 948 949 gtag_loaded = true; 950 951 } 952 953 }, 954 955 /** 956 * GDPR 957 */ 958 959 loadPixels: function () { 960 961 if (options.gdpr.ajax_enabled && !options.gdpr.consent_magic_integration_enabled) { 962 963 // retrieves actual PYS GDPR filters values which allow to avoid cache issues 964 $.get({ 965 url: options.ajaxUrl, 966 dataType: 'json', 967 data: { 968 action: 'pys_get_gdpr_filters_values' 969 }, 970 success: function (res) { 971 972 if (res.success) { 973 974 options.gdpr.all_disabled_by_api = res.data.all_disabled_by_api; 975 options.gdpr.facebook_disabled_by_api = res.data.facebook_disabled_by_api; 976 options.gdpr.analytics_disabled_by_api = res.data.analytics_disabled_by_api; 977 options.gdpr.google_ads_disabled_by_api = res.data.google_ads_disabled_by_api; 978 options.gdpr.pinterest_disabled_by_api = res.data.pinterest_disabled_by_api; 979 options.gdpr.bing_disabled_by_api = res.data.bing_disabled_by_api; 980 981 options.cookie.externalID_disabled_by_api = res.data.externalID_disabled_by_api; 982 options.cookie.disabled_all_cookie = res.data.disabled_all_cookie; 983 options.cookie.disabled_advanced_form_data_cookie = res.data.disabled_advanced_form_data_cookie; 984 options.cookie.disabled_landing_page_cookie = res.data.disabled_landing_page_cookie; 985 options.cookie.disabled_first_visit_cookie = res.data.disabled_first_visit_cookie; 986 options.cookie.disabled_trafficsource_cookie = res.data.disabled_trafficsource_cookie; 987 options.cookie.disabled_utmTerms_cookie = res.data.disabled_utmTerms_cookie; 988 options.cookie.disabled_utmId_cookie = res.data.disabled_utmId_cookie; 989 } 990 991 loadPixels(); 992 993 } 994 }); 995 996 } else { 997 loadPixels(); 998 } 999 1000 }, 1001 1002 consentGiven: function (pixel) { 1003 1004 /** 1005 * ConsentMagic 1006 */ 1007 if ( options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined" ) { 1008 1009 var test_prefix = CS_Data.test_prefix; 1010 if ( ( typeof CS_Data.cs_google_consent_mode_enabled !== "undefined" && CS_Data.cs_google_consent_mode_enabled == 1 ) && ( pixel == 'analytics' || pixel == 'google_ads' ) ) { 1011 if ( CS_Data.cs_cache_enabled == 0 || ( CS_Data.cs_cache_enabled == 1 && window.CS_Cache && window.CS_Cache.check_status ) ) { 1012 return true; 1013 } else { 1014 return false;
1015 } 1016 } 1017 1018 var substring = "cs_enabled_cookie_term"; 1019 var theCookies = document.cookie.split( ';' ); 1020 1021 for ( var i = 1; i <= theCookies.length; i++ ) { 1022 if ( theCookies[ i - 1 ].indexOf( substring ) !== -1 ) { 1023 var categoryCookie = theCookies[ i - 1 ].replace( 'cs_enabled_cookie_term' + test_prefix + '_', '' ); 1024 categoryCookie = Number( categoryCookie.replace( /\D+/g, "" ) ); 1025 var cs_cookie_val = Cookies.get( 'cs_enabled_cookie_term' + test_prefix + '_' + categoryCookie ); 1026 1027 if ( categoryCookie === CS_Data.cs_script_cat.facebook && pixel == 'facebook' ) { 1028 return cs_cookie_val == 'yes'; 1029 } else if ( categoryCookie === CS_Data.cs_script_cat.bing && pixel == 'bing' ) { 1030 return cs_cookie_val == 'yes'; 1031 } else if ( categoryCookie === CS_Data.cs_script_cat.analytics && pixel == 'analytics' ) { 1032 return cs_cookie_val == 'yes'; 1033 } else if ( categoryCookie === CS_Data.cs_script_cat.gads && pixel == 'google_ads' ) { 1034 return cs_cookie_val == 'yes'; 1035 } else if ( categoryCookie === CS_Data.cs_script_cat.pinterest && pixel == 'pinterest' ) { 1036 return cs_cookie_val == 'yes'; 1037 } else if ( categoryCookie === CS_Data.cs_script_cat.tiktok && pixel == 'tiktok' ) { 1038 return cs_cookie_val == 'yes'; 1039 } 1040 } 1041 } 1042 1043 return false; 1044 } 1045 1046 /** 1047 * Real Cookie Banner 1048 */ 1049 if(options.gdpr.real_cookie_banner_integration_enabled) { 1050 var consentApi = window.consentApi; 1051 if (consentApi) { 1052 switch (pixel) { 1053 case "analytics": 1054 return consentApi.consentSync("http", "_ga", "*").cookieOptIn; 1055 case "facebook": 1056 return consentApi.consentSync("http", "_fbp", "*").cookieOptIn; 1057 case "pinterest": 1058 return consentApi.consentSync("http", "_pinterest_sess", ".pinterest.com").cookieOptIn; 1059 default: 1060 return true; 1061 } 1062 } 1063 } 1064 1065 /** 1066 * Cookiebot 1067 */ 1068 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 1069 1070 var cookiebot_consent_category = options.gdpr['cookiebot_' + pixel + '_consent_category']; 1071 1072 if (options.gdpr[pixel + '_prior_consent_enabled']) { 1073 if (Cookiebot.consented === true || Cookiebot.consent[cookiebot_consent_category]) { 1074 return true; 1075 } 1076 } else { 1077 if (Cookiebot.consent[cookiebot_consent_category]) { 1078 return true; 1079 } 1080 } 1081 1082 return false; 1083 1084 } 1085 1086 /** 1087 * Cookie Notice 1088 */ 1089 if (options.gdpr.cookie_notice_integration_enabled && typeof cnArgs !== 'undefined') { 1090 1091 var cn_cookie = Cookies.get(cnArgs.cookieName); 1092 1093 if (options.gdpr[pixel + '_prior_consent_enabled']) { 1094 if (typeof cn_cookie === 'undefined' || cn_cookie === 'true') { 1095 return true; 1096 } 1097 } else { 1098 if (cn_cookie === 'true') { 1099 return true; 1100 } 1101 } 1102 1103 return false;
1104 1105 } 1106 1107 /** 1108 * Cookie Law Info 1109 */ 1110 if (options.gdpr.cookie_law_info_integration_enabled) { 1111 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 1112 if (options.gdpr[pixel + '_prior_consent_enabled']) { 1113 if (typeof cli_cookie === 'undefined') return true; 1114 if (cli_cookie && cli_cookie === Cookies.get('cookieyes-consent')) { 1115 if (getCookieYes('analytics') === 'yes') { 1116 return true; 1117 } 1118 } else if (cli_cookie && cli_cookie === Cookies.get('viewed_cookie_policy')) { 1119 if (Cookies.get('viewed_cookie_policy') === 'yes') { 1120 return true; 1121 } 1122 } 1123 } else { 1124 if (cli_cookie && cli_cookie === Cookies.get('cookieyes-consent')) { 1125 if (getCookieYes('analytics') === 'yes') { 1126 return true; 1127 } 1128 } else if (cli_cookie && cli_cookie === Cookies.get('viewed_cookie_policy')) { 1129 if (Cookies.get('viewed_cookie_policy') === 'yes') { 1130 return true; 1131 } 1132 } 1133 } 1134 return false; 1135 } 1136 1137 return true; 1138 1139 }, 1140 1141 setupGdprCallbacks: function () { 1142 /** 1143 * ConsentMagic 1144 */ 1145 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 1146 var test_prefix = CS_Data.test_prefix, 1147 cs_refresh_after_consent = false, 1148 substring = "cs_enabled_cookie_term"; 1149 1150 if (CS_Data.cs_refresh_after_consent == 1) { 1151 cs_refresh_after_consent = CS_Data.cs_refresh_after_consent; 1152 } 1153 1154 if (!cs_refresh_after_consent) { 1155 var theCookies = document.cookie.split(';'); 1156 for (var i = 1 ; i <= theCookies.length; i++) { 1157 if (theCookies[i-1].indexOf(substring) !== -1) { 1158 var categoryCookie = theCookies[i-1].replace('cs_enabled_cookie_term'+test_prefix+'_',''); 1159 categoryCookie = Number(categoryCookie.replace(/\D+/g,"")); 1160 var cs_cookie_val = Cookies.get('cs_enabled_cookie_term'+test_prefix+'_'+categoryCookie); 1161 if(cs_cookie_val == 'yes') { 1162 if (categoryCookie === CS_Data.cs_script_cat.facebook) { 1163 Facebook.loadPixel(); 1164 } 1165 1166 if (categoryCookie === CS_Data.cs_script_cat.bing) { 1167 Bing.loadPixel(); 1168 } 1169 1170 if (categoryCookie === CS_Data.cs_script_cat.analytics || (typeof CS_Data.cs_google_analytics_consent_mode !== "undefined" && CS_Data.cs_google_analytics_consent_mode == 1)) { 1171 1172 Analytics.loadPixel(); 1173 } 1174 1175 if (categoryCookie === CS_Data.cs_script_cat.pinterest) { 1176 Pinterest.loadPixel(); 1177 } 1178 } else { 1179 if (categoryCookie === CS_Data.cs_script_cat.facebook) { 1180 Facebook.disable(); 1181 } 1182 1183 if (categoryCookie === CS_Data.cs_script_cat.bing) { 1184 Bing.disable(); 1185 } 1186 if (categoryCookie === CS_Data.cs_script_cat.analytics && (typeof CS_Data.cs_google_analytics_consent_mode == "undefined" || CS_Data.cs_google_analytics_consent_mode == 0)) { 1187 Analytics.disable(); 1188 } 1189 1190 if (categoryCookie === CS_Data.cs_script_cat.pinterest) { 1191 Pinterest.disable(); 1192 } 1193 } 1194 if (Cookies.get('cs_enabled_advanced_matching') == 'yes') { 1195 Facebook.loadPixel(); 1196 } 1197 } 1198 } 1199 1200 $(document).on('click','.cs_action_btn',function(e) { 1201 e.preventDefault(); 1202 var elm = $(this), 1203 button_action = elm.attr('data-cs_action'); 1204 1205 if(button_action === 'allow_all') { 1206 Facebook.loadPixel(); 1207 Bing.loadPixel(); 1208 Analytics.loadPixel(); 1209 Pinterest.loadPixel(); 1210 } else if(button_action === 'disable_all') { 1211 Facebook.disable(); 1212 Bing.disable(); 1213 if(CS_Data.cs_google_analytics_consent_mode == 0 || typeof CS_Data.cs_google_analytics_consent_mode == "undefined") 1214 { 1215 Analytics.disable(); 1216 } 1217 Pinterest.disable(); 1218 } 1219 }); 1220 } 1221 } 1222 /** 1223 * Real Cookie Banner 1224 */ 1225 if(options.gdpr.real_cookie_banner_integration_enabled) { 1226 var consentApi = window.consentApi; 1227 if (consentApi) { 1228 consentApi.consent("http", "_ga", "*") 1229 .then(Analytics.loadPixel.bind(Analytics), Analytics.disable.bind(Analytics)); 1230 consentApi.consent("http", "_fbp", "*") 1231 .then(Facebook.loadPixel.bind(Facebook), Facebook.disable.bind(Facebook)); 1232 consentApi.consent("http", "_pinterest_sess", ".pinterest.com") 1233 .then(Pinterest.loadPixel.bind(Pinterest), Pinterest.disable.bind(Pinterest)); 1234 consentApi.consent("http", "_uetsid", "*") 1235 .then(Bing.loadPixel.bind(Bing), Bing.disable.bind(Bing)); 1236 } 1237 } 1238 /** 1239 * Cookiebot 1240 */ 1241 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 1242 1243 window.addEventListener("CookiebotOnConsentReady", function() { 1244 Utils.manageCookies(); 1245 if (Cookiebot.consent.marketing) { 1246 Facebook.loadPixel(); 1247 Bing.loadPixel(); 1248 Pinterest.loadPixel(); 1249 1250 } 1251 if (Cookiebot.consent.statistics) { 1252 Analytics.loadPixel(); 1253 } 1254 if (!Cookiebot.consent.marketing) { 1255 Facebook.disable(); 1256 Pinterest.disable(); 1257 Bing.disable() 1258 } 1259 if (!Cookiebot.consent.statistics) { 1260 Analytics.disable(); 1261 } 1262 }); 1263 1264 } 1265 1266 /** 1267 * Cookie Notice 1268 */ 1269 if (options.gdpr.cookie_notice_integration_enabled) { 1270 1271 $(document).onFirst('click', '.cn-set-cookie', function () { 1272 1273 if ($(this).data('cookie-set') === 'accept') { 1274 Facebook.loadPixel(); 1275 Analytics.loadPixel(); 1276 Pinterest.loadPixel(); 1277 Bing.loadPixel(); 1278 } else { 1279 Facebook.disable(); 1280 Analytics.disable(); 1281 Pinterest.disable(); 1282 Bing.disable(); 1283 } 1284 1285 }); 1286 1287 $(document).onFirst('click', '.cn-revoke-cookie', function () { 1288 Facebook.disable(); 1289 Analytics.disable(); 1290 Pinterest.disable(); 1291 Bing.disable(); 1292 }); 1293 1294 } 1295 1296 /** 1297 * Cookie Law Info 1298 */ 1299 if (options.gdpr.cookie_law_info_integration_enabled) { 1300 1301 $(document).onFirst('click', '#wt-cli-accept-all-btn,#cookie_action_close_header, .cky-btn-accept', function () { 1302 setTimeout(function (){ 1303 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 1304 if (typeof cli_cookie !== 'undefined') { 1305 if (cli_cookie === Cookies.get('cookieyes-consent') && getCookieYes('analytics') == 'yes') { 1306 Utils.manageCookies(); 1307 } else if (cli_cookie === Cookies.get('viewed_cookie_policy') && cli_cookie == 'yes') { 1308 Utils.manageCookies(); 1309 } 1310 } 1311 },1000) 1312 Facebook.loadPixel(); 1313 Analytics.loadPixel(); 1314 GAds.loadPixel(); 1315 Pinterest.loadPixel(); 1316 Bing.loadPixel(); 1317 TikTok.loadPixel(); 1318 }); 1319 1320 $(document).onFirst('click', '#cookie_action_close_header_reject, .cky-btn-reject', function () { 1321 Facebook.disable(); 1322 Analytics.disable(); 1323 GAds.disable(); 1324 Pinterest.disable(); 1325 Bing.disable(); 1326 TikTok.disable(); 1327 }); 1328 1329 } 1330 1331 }, 1332 1333 /** 1334 * DOWNLOAD DOCS 1335 */ 1336 1337 getLinkExtension: function (link) { 1338 1339 // Remove anchor, query string and everything before last slash 1340 link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); 1341 link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); 1342 link = link.substring(link.lastIndexOf("/") + 1, link.length); 1343 1344 // If there's a period left in the URL, then there's a extension 1345 if (link.length > 0 && link.indexOf('.') !== -1) { 1346 link = link.substring(link.indexOf(".") + 1); // Remove everything but what's after the first period 1347 return link; 1348 } else { 1349 return ""; 1350 } 1351 }, 1352 1353 getLinkFilename: function (link) { 1354 1355 // Remove anchor, query string and everything before last slash 1356 link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); 1357 link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); 1358 link = link.substring(link.lastIndexOf("/") + 1, link.length); 1359 1360 // If there's a period left in the URL, then there's a extension 1361 if (link.length > 0 && link.indexOf('.') !== -1) { 1362 return link; 1363 } else { 1364 return ""; 1365 } 1366 }, 1367 /** 1368 * Enrich 1369 */ 1370 isCheckoutPage: function () { 1371 return $('body').hasClass('woocommerce-checkout') || document.querySelector('.woocommerce-checkout') || 1372 $('body').hasClass('edd-checkout'); 1373 }, 1374 addCheckoutFields : function() { 1375 var utm = ""; 1376 var utms = getUTMs() 1377 1378 $.each(utmTerms, function (index, name) { 1379 if(index > 0) { 1380 utm+="|"; 1381 } 1382 utm+=name+":"+utms[name]; 1383 }); 1384 var utmIdList = ""; 1385 var utmsIds = getUTMId() 1386 $.each(utmId, function (index, name) { 1387 if(index > 0) { 1388 utmIdList+="|"; 1389 } 1390 utmIdList+=name+":"+utmsIds[name]; 1391 }); 1392 var utmIdListLast = ""; 1393 var utmsIdsLast = getUTMId(true) 1394 $.each(utmId, function (index, name) { 1395 if(index > 0) { 1396 utmIdListLast+="|"; 1397 } 1398 utmIdListLast+=name+":"+utmsIdsLast[name]; 1399 }); 1400 1401 1402 var utmLast = ""; 1403 var utmsLast = getUTMs(true) 1404 $.each(utmTerms, function (index, name) { 1405 if(index > 0) { 1406 utmLast+="|"; 1407 }
1408 utmLast+=name+":"+utmsLast[name]; 1409 }); 1410 1411 var dateTime = getDateTime(); 1412 var landing = getLandingPageValue(); 1413 var lastLanding = getLandingPageValue(); 1414 var trafic = getTrafficSourceValue(); 1415 var lastTrafic = getTrafficSourceValue(); 1416 1417 var $form = null; 1418 if($('body').hasClass('woocommerce-checkout')) { 1419 $form = $("form.woocommerce-checkout"); 1420 } else { 1421 $form = $("#edd_purchase_form"); 1422 } 1423 var inputs = {'pys_utm':utm, 1424 'pys_utm_id':utmIdList, 1425 'pys_browser_time':dateTime.join("|"), 1426 'pys_landing':landing, 1427 'pys_source':trafic, 1428 'pys_order_type': $(".wcf-optin-form").length > 0 ? "wcf-optin" : "normal", 1429 1430 'last_pys_landing':lastLanding, 1431 'last_pys_source':lastTrafic, 1432 'last_pys_utm':utmLast, 1433 'last_pys_utm_id':utmIdListLast, 1434 } 1435 1436 Object.keys(inputs).forEach(function(key,index) { 1437 $form.append("<input type='hidden' name='"+key+"' value='"+inputs[key]+"' /> "); 1438 }); 1439 1440 1441 }, 1442 getAdvancedFormData: function () { 1443 let dataStr = Cookies.get("pys_advanced_form_data"); 1444 if(dataStr === undefined) { 1445 return {'first_name':"",'last_name':"",'email':"",'phone':""}; 1446 } else { 1447 return JSON.parse(dataStr); 1448 } 1449 } 1450 }; 1451 1452 }(options); 1453 1454 var Facebook = function (options) { 1455 1456 1457 var defaultEventTypes = [ 1458 'PageView', 1459 'ViewContent', 1460 'Search', 1461 'AddToCart', 1462 'AddToWishlist', 1463 'InitiateCheckout', 1464 'AddPaymentInfo', 1465 'Purchase', 1466 'Lead', 1467 1468 'Subscribe', 1469 'CustomizeProduct', 1470 'FindLocation', 1471 'StartTrial', 1472 'SubmitApplication', 1473 'Schedule', 1474 'Contact', 1475 'Donate' 1476 ]; 1477 1478 var initialized = false; 1479 var genereateFbp = function (){ 1480 return !Cookies.get('_fbp') ? 'fb.1.'+Date.now()+'.'+Math.floor(1000000000 + Math.random() * 9000000000) : Cookies.get('_fbp'); 1481 }; 1482 var genereateFbc = function (){ 1483 return getUrlParameter('fbclid') ? 'fb.1.'+Date.now()+'.'+getUrlParameter('fbclid') : '' 1484 }; 1485 1486 // fire server side event gdpr plugin installed 1487 var isApiDisabled = options.gdpr.all_disabled_by_api || 1488 options.gdpr.facebook_disabled_by_api || 1489 options.gdpr.cookiebot_integration_enabled || 1490 options.gdpr.consent_magic_integration_enabled || 1491 options.gdpr.cookie_notice_integration_enabled || 1492 options.gdpr.cookie_law_info_integration_enabled; 1493 1494 /** 1495 * 1496 * @param allData 1497 * @param params 1498 * @returns {string | null} 1499 */ 1500 function sendFbServerEvent(allData,name,params) { 1501 let eventId = null; 1502 if(options.facebook.serverApiEnabled) { 1503 1504 if(allData.e_id === "woo_remove_from_cart") {// server event will sended from hook 1505 Facebook.updateEventId(allData.name); 1506 allData.eventID = Facebook.getEventId(allData.name); 1507 } else { 1508 if( options.ajaxForServerEvent 1509 || isApiDisabled 1510 || allData.delay > 0 1511 || allData.type !== "static") 1512 { // send event from server if they was bloc by gdpr or need send with delay 1513 allData.eventID = pys_generate_token(36); 1514 var json = { 1515 action: 'pys_api_event', 1516 pixel: 'facebook', 1517 event: name, 1518 data:params, 1519 ids:options.facebook.pixelIds, 1520 eventID:allData.eventID, 1521 url:window.location.href, 1522 ajax_event:options.ajax_event 1523 }; 1524 if(allData.hasOwnProperty('woo_order')) { 1525 json['woo_order'] = allData.woo_order; 1526 } 1527 if(allData.hasOwnProperty('edd_order')) { 1528 json['edd_order'] = allData.edd_order; 1529 } 1530 1531 if(name == 'PageView') { 1532 let expires = parseInt(options.cookie_duration); 1533 1534 timeoutDelay = 0; 1535 if(allData.delay > 0) 1536 { 1537 timeoutDelay = allData.delay; 1538 } 1539 if(!Cookies.get('_fbp')) 1540 { 1541 timeoutDelay = 100; 1542 } 1543 if(getUrlParameter('fbclid') && !Cookies.get('_fbc')) 1544 { 1545 timeoutDelay = 100; 1546 } 1547 setTimeout(function(){ 1548 if(!Cookies.get('_fbp')) 1549 { 1550 Cookies.set('_fbp',genereateFbp(), { expires: expires }); 1551 json['data']['_fbp'] = genereateFbp(); 1552 } 1553 if(getUrlParameter('fbclid') && !Cookies.get('_fbc')) 1554 { 1555 Cookies.set('_fbc', genereateFbc(), { expires: expires }); 1556 json['data']['_fbc'] = genereateFbc(); 1557 } 1558 jQuery.ajax( { 1559 type: 'POST', 1560 url: options.ajaxUrl, 1561 data: json, 1562 headers: { 1563 'Cache-Control': 'no-cache' 1564 }, 1565 success: function(){}, 1566 }); 1567 },timeoutDelay) 1568 } 1569 else 1570 { 1571 jQuery.ajax( { 1572 type: 'POST', 1573 url: options.ajaxUrl, 1574 data: json, 1575 headers: { 1576 'Cache-Control': 'no-cache' 1577 }, 1578 success: function(){}, 1579 }); 1580 } 1581 } 1582 } 1583 eventId = allData.eventID 1584 } 1585 1586 return eventId; 1587 } 1588 1589 function fireEvent(name, allData) { 1590 1591 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'facebook')) { 1592 return; 1593 } 1594 1595 var actionType = defaultEventTypes.includes(name) ? 'track' : 'trackCustom'; 1596 var data = allData.params; 1597 var params = {}; 1598 var arg = {}; 1599 Utils.copyProperties(data, params); 1600 1601 let eventId = sendFbServerEvent(allData,name,params) 1602 1603 1604 if("hCR" === name) { 1605 return; 1606 } 1607 1608 if (options.debug) { 1609 console.log('[Facebook] ' + name, params,"eventID",eventId); 1610 } 1611 1612 if(eventId != null) { 1613 arg.eventID = eventId; 1614 } 1615 if(name == 'PageView'){ 1616 fbq(actionType, name, data, arg); 1617 } 1618 else{ 1619 fbq(actionType, name, params, arg); 1620 } 1621 } 1622 1623 /** 1624 * Public API 1625 */ 1626 return { 1627 tag: function() { 1628 return "facebook"; 1629 }, 1630 isEnabled: function () { 1631 return options.hasOwnProperty('facebook'); 1632 }, 1633 1634 disable: function () { 1635 initialized = false;
1636 }, 1637 advancedMatching: function () { 1638 if(options.facebook.advancedMatchingEnabled) { 1639 let advancedMatchingForm = Utils.getAdvancedFormData(); 1640 let advancedMatching = {}; 1641 if(Object.keys(options.facebook.advancedMatching).length > 0) { 1642 advancedMatching = options.facebook.advancedMatching; 1643 } 1644 1645 if(!advancedMatching.hasOwnProperty("em") 1646 && advancedMatchingForm.hasOwnProperty("email") && advancedMatchingForm["email"].length > 0) { 1647 advancedMatching["em"] = advancedMatchingForm["email"]; 1648 } 1649 if(!advancedMatching.hasOwnProperty("ph") 1650 && advancedMatchingForm.hasOwnProperty("phone") && advancedMatchingForm["phone"].length > 0) { 1651 advancedMatching["ph"] = advancedMatchingForm["phone"]; 1652 } 1653 if(!advancedMatching.hasOwnProperty("fn") 1654 && advancedMatchingForm.hasOwnProperty("first_name") && advancedMatchingForm["first_name"].length > 0) { 1655 advancedMatching["fn"] = advancedMatchingForm["first_name"]; 1656 } 1657 if(!advancedMatching.hasOwnProperty("ln") 1658 && advancedMatchingForm.hasOwnProperty("last_name") && advancedMatchingForm["last_name"].length > 0) { 1659 advancedMatching["ln"] = advancedMatchingForm["last_name"]; 1660 } 1661 if(!advancedMatching.hasOwnProperty("external_id")){ 1662 if (Cookies.get('pbid') || (options.hasOwnProperty('pbid') && options.pbid)) { 1663 advancedMatching["external_id"] = Cookies.get('pbid') ? Cookies.get('pbid') : options.pbid; 1664 } 1665 } 1666 else if(advancedMatching.external_id != Cookies.get('pbid')) 1667 { 1668 advancedMatching["external_id"] = Cookies.get('pbid') ? Cookies.get('pbid') : advancedMatching.external_id; 1669 } 1670 if(Object.keys(advancedMatching).length > 0) { 1671 return advancedMatching; 1672 } 1673 } 1674 return false 1675 }, 1676 /** 1677 * Load pixel's JS 1678 */ 1679 loadPixel: function () { 1680 1681 if (initialized || !this.isEnabled() || !Utils.consentGiven('facebook')) { 1682 return; 1683 } 1684 1685 !function (f, b, e, v, n, t, s) { 1686 if (f.fbq) return; 1687 n = f.fbq = function () { 1688 n.callMethod ? 1689 n.callMethod.apply(n, arguments) : n.queue.push(arguments) 1690 }; 1691 if (!f._fbq) f._fbq = n; 1692 n.push = n; 1693 n.loaded = !0; 1694 n.version = '2.0'; 1695 n.agent = 'dvpixelyoursite'; 1696 n.queue = []; 1697 t = b.createElement(e); 1698 t.async = !0; 1699 t.src = v; 1700 s = b.getElementsByTagName(e)[0]; 1701 s.parentNode.insertBefore(t, s) 1702 }(window, 1703 document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); 1704 1705 // initialize pixel 1706 options.facebook.pixelIds.forEach(function (pixelId) { 1707 if (options.facebook.removeMetadata) { 1708 fbq('set', 'autoConfig', false, pixelId); 1709 } 1710 let advancedMatching = Facebook.advancedMatching(); 1711 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 1712 if(!advancedMatching) { 1713 fbq('init', pixelId); 1714 } else { 1715 var test_prefix = CS_Data.test_prefix; 1716 var cs_advanced_matching = Cookies.get('cs_enabled_advanced_matching'+test_prefix); 1717 if (jQuery('#cs_enabled_advanced_matching'+test_prefix).length > 0) { 1718 if (cs_advanced_matching == 'yes') { 1719 fbq('init', pixelId, advancedMatching); 1720 } else { 1721 fbq('init', pixelId); 1722 } 1723 } else { 1724 fbq('init', pixelId, advancedMatching); 1725 } 1726 } 1727 } else { 1728 if(!advancedMatching) { 1729 fbq('init', pixelId); 1730 } else { 1731 fbq('init', pixelId, advancedMatching); 1732 } 1733 } 1734 }); 1735 1736 initialized = true; 1737 1738 Utils.fireStaticEvents('facebook'); 1739 1740 }, 1741 1742 fireEvent: function (name, data) { 1743 1744 if (!initialized || !this.isEnabled()) { 1745 return false;
1746 } 1747 1748 data.delay = data.delay || 0; 1749 data.params = data.params || {}; 1750 1751 if (data.delay === 0) { 1752 1753 fireEvent(name, data); 1754 1755 } else { 1756 1757 setTimeout(function (name, params) { 1758 fireEvent(name, params); 1759 }, data.delay * 1000, name, data); 1760 1761 } 1762 1763 return true; 1764 1765 }, 1766 1767 onCommentEvent: function (event) { 1768 this.fireEvent(event.name, event); 1769 }, 1770 1771 onDownloadEvent: function (event) { 1772 this.fireEvent(event.name, event); 1773 }, 1774 1775 onFormEvent: function (event) { 1776 1777 this.fireEvent(event.name, event); 1778 1779 }, 1780 1781 onWooAddToCartOnButtonEvent: function (product_id) { 1782 1783 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 1784 return; 1785 var event = options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]; 1786 1787 if (window.pysWooProductData.hasOwnProperty(product_id)) { 1788 if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { 1789 event = Utils.copyProperties(event, {}) 1790 Utils.copyProperties(window.pysWooProductData[product_id]['facebook'].params, event.params) 1791 this.fireEvent(event.name, event); 1792 } 1793 } 1794 }, 1795 1796 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, $form) { 1797 1798 window.pysWooProductData = window.pysWooProductData || []; 1799 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 1800 return; 1801 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 1802 1803 if (product_type === Utils.PRODUCT_VARIABLE && !options.facebook.wooVariableAsSimple) { 1804 product_id = parseInt($form.find('input[name="variation_id"]').val()); 1805 } 1806 1807 if (window.pysWooProductData.hasOwnProperty(product_id)) { 1808 if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { 1809 1810 1811 Utils.copyProperties(window.pysWooProductData[product_id]['facebook'].params, event.params); 1812 1813 var groupValue = 0; 1814 if(product_type === Utils.PRODUCT_GROUPED ) { 1815 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 1816 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 1817 var quantity = parseInt($(this).val()); 1818 if(isNaN(quantity)) { 1819 quantity = 0; 1820 } 1821 var childItem = window.pysWooProductData[product_id]['facebook'].grouped[childId]; 1822 1823 if(quantity == 0) { 1824 event.params.content_ids.forEach(function(el,index,array) { 1825 if(el == childItem.content_id) { 1826 array.splice(index, 1); 1827 } 1828 }); 1829 } 1830 1831 if(event.params.hasOwnProperty('contents')) { 1832 event.params.contents.forEach(function(el,index,array) { 1833 if(el.id == childItem.content_id) { 1834 if(quantity > 0){ 1835 el.quantity = quantity; 1836 } else { 1837 array.splice(index, 1); 1838 } 1839 } 1840 }); 1841 } 1842 1843 1844 groupValue += childItem.price * quantity; 1845 }); 1846 if(groupValue == 0) return;
1846 // skip if no items selected 1847 } 1848 1849 // maybe customize value option 1850 if (options.woo.addToCartOnButtonValueEnabled && options.woo.addToCartOnButtonValueOption !== 'global') { 1851 1852 if(product_type === Utils.PRODUCT_GROUPED) { 1853 event.params.value = groupValue; 1854 } else if(product_type === Utils.PRODUCT_BUNDLE) { 1855 var data = $(".bundle_form .bundle_data").data("bundle_form_data"); 1856 var items_sum = getBundlePriceOnSingleProduct(data); 1857 event.params.value = (parseInt(data.base_price) + items_sum )* qty; 1858 } else { 1859 event.params.value = event.params.value * qty; 1860 } 1861 } 1862 1863 // only when non Facebook for WooCommerce logic used 1864 if (event.params.hasOwnProperty('contents') && product_type !== Utils.PRODUCT_GROUPED) { 1865 event.params.contents[0].quantity = qty; 1866 } 1867 1868 this.fireEvent(event.name, event); 1869 1870 } 1871 } 1872 }, 1873 1874 onWooRemoveFromCartEvent: function (event) { 1875 this.fireEvent(event.name, event); 1876 }, 1877 1878 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 1879 1880 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 1881 return; 1882 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 1883 1884 if (window.pysEddProductData.hasOwnProperty(download_id)) { 1885 1886 var index; 1887 1888 if (price_index) { 1889 index = download_id + '_' + price_index; 1890 } else { 1891 index = download_id; 1892 } 1893 1894 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 1895 if (window.pysEddProductData[download_id][index].hasOwnProperty('facebook')) { 1896 1897 1898 Utils.copyProperties(window.pysEddProductData[download_id][index]['facebook']["params"], event.params) 1899 1900 // maybe customize value option 1901 if (options.edd.addToCartOnButtonValueEnabled && options.edd.addToCartOnButtonValueOption !== 'global') { 1902 event.params.value = event.params.value * qty; 1903 } 1904 1905 // update contents qty param 1906 var contents = event.params.contents; 1907 contents[0].quantity = qty; 1908 event.params.contents = contents; 1909 1910 this.fireEvent(event.name,event); 1911 1912 } 1913 } 1914 1915 } 1916 1917 }, 1918 1919 onEddRemoveFromCartEvent: function (event) { 1920 this.fireEvent(event.name, event); 1921 }, 1922 onPageScroll: function (event) { 1923 this.fireEvent(event.name, event); 1924 }, 1925 onTime: function (event) { 1926 this.fireEvent(event.name, event); 1927 }, 1928 initEventIdCookies: function (key) { 1929 var ids = {}; 1930 ids[key] = pys_generate_token(36) 1931 Cookies.set('pys_fb_event_id', JSON.stringify(ids)); 1932 }, 1933 updateEventId:function(key) { 1934 var cooData = Cookies.get("pys_fb_event_id") 1935 if(cooData === undefined) { 1936 this.initEventIdCookies(key); 1937 } else { 1938 var data = JSON.parse(cooData); 1939 data[key] = pys_generate_token(36); 1940 Cookies.set('pys_fb_event_id', JSON.stringify(data) ); 1941 } 1942 }, 1943 1944 getEventId:function (key) { 1945 var data = Cookies.get("pys_fb_event_id"); 1946 if(data === undefined) {
1947 this.initEventIdCookies(key); 1948 data = Cookies.get("pys_fb_event_id"); 1949 } 1950 return JSON.parse(data)[key]; 1951 }, 1952 }; 1953 1954 }(options); 1955 1956 var Analytics = function (options) { 1957 1958 var initialized = false; 1959 1960 /** 1961 * Fires event 1962 * 1963 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data 1964 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/events 1965 * @link: https://developers.google.com/gtagjs/reference/event 1966 * @link: https://developers.google.com/gtagjs/reference/parameter 1967 * 1968 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets 1969 * 1970 * @param name 1971 * @param data 1972 */ 1973 function fireEvent(name, data) { 1974 1975 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'ga')) { 1976 return; 1977 } 1978 1979 var eventParams = Utils.copyProperties(data, {}); 1980 1981 var _fireEvent = function (tracking_id,name,params) { 1982 1983 params['send_to'] = tracking_id; 1984 1985 if (options.debug) { 1986 console.log('[Google Analytics #' + tracking_id + '] ' + name, params); 1987 } 1988 1989 gtag('event', name, params); 1990 1991 }; 1992 1993 options.ga.trackingIds.forEach(function (tracking_id) { 1994 var copyParams = Utils.copyProperties(eventParams, {}); // copy params because mapParamsTov4 can modify it 1995 var params = mapParamsTov4(tracking_id,name,copyParams) 1996 _fireEvent(tracking_id,name,params); 1997 }); 1998 1999 } 2000 function mapParamsTov4(tag,name,param) { 2001 //GA4 automatically collects a number of parameters for all events 2002 delete param.landing_page; 2003 // end 2004 if(isv4(tag)) { 2005 delete param.traffic_source; 2006 delete param.event_category; 2007 delete param.event_label; 2008 delete param.ecomm_prodid; 2009 delete param.ecomm_pagetype; 2010 delete param.ecomm_totalvalue; 2011 if(name === 'search') { 2012 param['search'] = param.search_term; 2013 delete param.search_term; 2014 delete param.dynx_itemid; 2015 delete param.dynx_pagetype; 2016 delete param.dynx_totalvalue; 2017 } 2018 } 2019 return param; 2020 } 2021 2022 function isv4(tag) { 2023 return tag.indexOf('G') === 0; 2024 } 2025 2026 /** 2027 * Public API 2028 */ 2029 return { 2030 tag: function() { 2031 return "ga"; 2032 }, 2033 isEnabled: function () { 2034 return options.hasOwnProperty('ga'); 2035 }, 2036 2037 disable: function () { 2038 initialized = false; 2039 }, 2040 2041 loadPixel: function () { 2042 2043 if (initialized || !this.isEnabled() || !Utils.consentGiven('analytics')) { 2044 return; 2045 } 2046 2047 Utils.loadGoogleTag(options.ga.trackingIds[0]); 2048 var config = {}; 2049 // Cross-Domain tracking 2050 if (options.ga.crossDomainEnabled) { 2051 config.linker = { 2052 accept_incoming: options.ga.crossDomainAcceptIncoming, 2053 domains: options.ga.crossDomainDomains 2054 }; 2055 } 2056 2057 2058 2059 // configure tracking ids 2060 options.ga.trackingIds.forEach(function (trackingId,index) { 2061 var obj = options.ga.isDebugEnabled; 2062 var searchValue = "index_"+index; 2063 config.debug_mode = false;
2064 2065 for (var key in obj) { 2066 if (obj.hasOwnProperty(key) && obj[key] === searchValue) { 2067 config.debug_mode = true; 2068 break; 2069 } 2070 } 2071 if(!config.debug_mode) 2072 { 2073 delete config.debug_mode; 2074 } 2075 if(isv4(trackingId)) { 2076 if(options.ga.disableAdvertisingFeatures) { 2077 config.allow_google_signals = false 2078 } 2079 if(options.ga.disableAdvertisingPersonalization) { 2080 config.allow_ad_personalization_signals = false 2081 } 2082 } 2083 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 2084 2085 var cookiebot_consent_category = options.gdpr['cookiebot_analytics_consent_category']; 2086 if (options.gdpr['analytics_prior_consent_enabled']) { 2087 if (Cookiebot.consented === true && Cookiebot.consent[cookiebot_consent_category]) { 2088 gtag('config', trackingId, config); 2089 } 2090 } else { 2091 if (Cookiebot.consent[cookiebot_consent_category]) { 2092 gtag('config', trackingId, config); 2093 } 2094 } 2095 2096 } 2097 else 2098 { 2099 gtag('config', trackingId, config); 2100 } 2101 }); 2102 2103 initialized = true; 2104 2105 Utils.fireStaticEvents('ga'); 2106 2107 }, 2108 2109 fireEvent: function (name, data) { 2110 2111 if (!initialized || !this.isEnabled()) { 2112 return false; 2113 } 2114 2115 data.delay = data.delay || 0; 2116 data.params = data.params || {}; 2117 2118 if (data.delay === 0) { 2119 2120 fireEvent(name, data.params); 2121 2122 } else { 2123 2124 setTimeout(function (name, params) { 2125 fireEvent(name, params); 2126 }, data.delay * 1000, name, data.params); 2127 2128 } 2129 2130 return true; 2131 2132 }, 2133 2134 onCommentEvent: function (event) { 2135 this.fireEvent(event.name, event); 2136 }, 2137 2138 onDownloadEvent: function (event) { 2139 this.fireEvent(event.name, event); 2140 }, 2141 2142 onFormEvent: function (event) { 2143 this.fireEvent(event.name, event); 2144 }, 2145 2146 onWooAddToCartOnButtonEvent: function (product_id) { 2147 2148 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 2149 return; 2150 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 2151 2152 if (window.pysWooProductData.hasOwnProperty(product_id)) { 2153 if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { 2154 Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params) 2155 this.fireEvent(event.name, event); 2156 } 2157 } 2158 2159 2160 }, 2161 2162 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, $form) { 2163 2164 window.pysWooProductData = window.pysWooProductData || []; 2165 2166 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 2167 return; 2168 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 2169 2170 if (product_type === Utils.PRODUCT_VARIABLE && !options.ga.wooVariableAsSimple) { 2171 product_id = parseInt($form.find('input[name="variation_id"]').val()); 2172 } 2173 2174 if (window.pysWooProductData.hasOwnProperty(product_id)) { 2175 if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { 2176 2177 Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params); 2178 if(product_type === Utils.PRODUCT_GROUPED ) { 2179 var groupValue = 0; 2180 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 2181 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 2182 var quantity = parseInt($(this).val()); 2183 if(isNaN(quantity)) { 2184 quantity = 0; 2185 } 2186 var childItem = window.pysWooProductData[product_id]['ga'].grouped[childId]; 2187 // update quantity
2188 event.params.items.forEach(function(el,index,array) { 2189 if(el.id == childItem.content_id) { 2190 if(quantity > 0){ 2191 el.quantity = quantity; 2192 } else { 2193 array.splice(index, 1); 2194 } 2195 } 2196 }); 2197 groupValue += childItem.price * quantity; 2198 }); 2199 if(options.woo.addToCartOnButtonValueEnabled && 2200 options.woo.addToCartOnButtonValueOption !== 'global' && 2201 event.params.hasOwnProperty('ecomm_totalvalue')) { 2202 event.params.ecomm_totalvalue = groupValue; 2203 } 2204 2205 if(groupValue == 0) return; // skip if no items selected 2206 } else { 2207 // update items qty param 2208 event.params.items[0].quantity = qty; 2209 } 2210 2211 // maybe customize value option 2212 if (options.woo.addToCartOnButtonValueEnabled && 2213 options.woo.addToCartOnButtonValueOption !== 'global' && 2214 product_type !== Utils.PRODUCT_GROUPED) 2215 { 2216 if(event.params.hasOwnProperty('ecomm_totalvalue')) { 2217 event.params.ecomm_totalvalue = event.params.items[0].price * qty; 2218 } 2219 2220 } 2221 2222 2223 this.fireEvent(event.name, event); 2224 } 2225 } 2226 2227 }, 2228 2229 onWooRemoveFromCartEvent: function (event) { 2230 2231 this.fireEvent(event.name, event); 2232 2233 }, 2234 2235 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 2236 2237 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 2238 return; 2239 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 2240 2241 2242 if (window.pysEddProductData.hasOwnProperty(download_id)) { 2243 2244 var index; 2245 2246 if (price_index) { 2247 index = download_id + '_' + price_index; 2248 } else { 2249 index = download_id; 2250 } 2251 2252 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 2253 if (window.pysEddProductData[download_id][index].hasOwnProperty('ga')) { 2254 2255 Utils.copyProperties(window.pysEddProductData[download_id][index]['ga'].params, event.params); 2256 2257 // update items qty param 2258 event.params.items[0].quantity = qty; 2259 2260 this.fireEvent(event.name,event); 2261 2262 } 2263 } 2264 2265 } 2266 2267 }, 2268 2269 onEddRemoveFromCartEvent: function (event) { 2270 this.fireEvent(event.name, event); 2271 }, 2272 onPageScroll: function (event) { 2273 this.fireEvent(event.name, event); 2274 }, 2275 onTime: function (event) { 2276 this.fireEvent(event.name, event); 2277 }, 2278 2279 }; 2280 2281 }(options); 2282 2283 window.pys = window.pys || {}; 2284 window.pys.Facebook = Facebook; 2285 window.pys.Analytics = Analytics; 2286 window.pys.Utils = Utils; 2287 2288 2289 2290 2291 $(document).ready(function () { 2292 2293 if($("#pys_late_event").length > 0) { 2294 var events = JSON.parse($("#pys_late_event").attr("dir")); 2295 for(var key in events) { 2296 var event = {}; 2297 event[events[key].e_id] = [events[key]]; 2298 if(options.staticEvents.hasOwnProperty(key)) { 2299 Object.assign(options.staticEvents[key], event); 2300 } else { 2301 options.staticEvents[key] = event; 2302 } 2303 2304 } 2305 } 2306 2307 var Pinterest = Utils.setupPinterestObject(); 2308 var Bing = Utils.setupBingObject(); 2309 2310 if(options.hasOwnProperty('cookie')) 2311 { 2312 if(options.cookie.externalID_disabled_by_api || options.cookie.disabled_all_cookie) 2313 { 2314 Cookies.remove('pbid') 2315 } 2316 if(options.cookie.disabled_advanced_form_data_cookie || options.cookie.disabled_all_cookie) 2317 { 2318 Cookies.remove('pys_advanced_form_data') 2319 } 2320 if(options.cookie.disabled_landing_page_cookie || options.cookie.disabled_all_cookie) 2321 { 2322 Cookies.remove('pys_landing_page') 2323 Cookies.remove('last_pys_landing_page') 2324 } 2325 if(options.cookie.disabled_trafficsource_cookie || options.cookie.disabled_all_cookie) 2326 { 2327 Cookies.remove('pysTrafficSource') 2328 Cookies.remove('last_pysTrafficSource') 2329 } 2330 if(options.cookie.disabled_first_visit_cookie || options.cookie.disabled_all_cookie) 2331 { 2332 Cookies.remove('pys_first_visit') 2333 2334 } 2335 if(options.cookie.disabled_utmTerms_cookie || options.cookie.disabled_all_cookie) 2336 { 2337 $.each(Utils.utmTerms, function (index, name) { 2338 Cookies.remove('pys_' + name) 2339 }); 2340 $.each(Utils.utmTerms, function (index, name) { 2341 Cookies.remove('last_pys_' + name) 2342 }); 2343 } 2344 if(options.cookie.disabled_utmId_cookie || options.cookie.disabled_all_cookie) 2345 { 2346 $.each(Utils.utmId,function(index,name) { 2347 Cookies.remove('pys_' + name) 2348 }) 2349 $.each(Utils.utmId,function(index,name) { 2350 Cookies.remove('last_pys_' + name) 2351 }); 2352 } 2353 } 2354 2355 2356 if (options.gdpr.cookie_law_info_integration_enabled) { 2357 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 2358 2359 if (typeof cli_cookie !== 'undefined') { 2360 if (cli_cookie === Cookies.get('cookieyes-consent') && getCookieYes('analytics') == 'yes') { 2361 Utils.manageCookies(); 2362 } else if (cli_cookie === Cookies.get('viewed_cookie_policy') && cli_cookie == 'yes') { 2363 Utils.manageCookies(); 2364 } 2365 } 2366 } 2367 else 2368 { 2369 Utils.manageCookies(); 2370 } 2371 Utils.setupGdprCallbacks(); 2372 // page scroll event 2373 if ( options.dynamicEvents.hasOwnProperty("automatic_event_scroll") 2374 ) { 2375 2376 var singlePageScroll = function () { 2377 2378 2379 var docHeight = $(document).height() - $(window).height(); 2380 var isFired = false;
2381 2382 if (options.dynamicEvents.hasOwnProperty("automatic_event_scroll")) { 2383 var pixels = Object.keys(options.dynamicEvents.automatic_event_scroll); 2384 for(var i = 0;i<pixels.length;i++) { 2385 var event = Utils.clone(options.dynamicEvents.automatic_event_scroll[pixels[i]]); 2386 var scroll = Math.round(docHeight * event.scroll_percent / 100)// convert % to absolute positions 2387 2388 if(scroll < $(window).scrollTop()) { 2389 Utils.copyProperties(Utils.getRequestParams(), event.params); 2390 getPixelBySlag(pixels[i]).onPageScroll(event); 2391 isFired = true 2392 } 2393 } 2394 } 2395 if(isFired) { 2396 $(document).off("scroll",singlePageScroll); 2397 } 2398 } 2399 $(document).on("scroll",singlePageScroll); 2400 } 2401 2402 2403 if (options.dynamicEvents.hasOwnProperty("automatic_event_time_on_page")) { 2404 var pixels = Object.keys(options.dynamicEvents.automatic_event_time_on_page); 2405 var time = options.dynamicEvents.automatic_event_time_on_page[pixels[0]].time_on_page; // the same for all pixel 2406 setTimeout(function(){ 2407 for(var i = 0;i<pixels.length;i++) { 2408 var event = Utils.clone(options.dynamicEvents.automatic_event_time_on_page[pixels[i]]);
2409 Utils.copyProperties(Utils.getRequestParams(), event.params); 2410 getPixelBySlag(pixels[i]).onTime(event); 2411 } 2412 },time*1000); 2413 } 2414 2415 // setup Click Event 2416 if (options.dynamicEvents.hasOwnProperty("automatic_event_download")) { 2417 2418 $(document).onFirst('click', 'a, button, input[type="button"], input[type="submit"]', function (e) { 2419 2420 var $elem = $(this); 2421 2422 // Download 2423 if(options.dynamicEvents.hasOwnProperty("automatic_event_download") 2424 ) { 2425 var isFired = false; 2426 if ($elem.is('a')) { 2427 var href = $elem.attr('href'); 2428 if (typeof href !== "string") { 2429 return; 2430 } 2431 href = href.trim(); 2432 var extension = Utils.getLinkExtension(href); 2433 var track_download = false; 2434 2435 if (extension.length > 0) { 2436 2437 if(options.dynamicEvents.hasOwnProperty("automatic_event_download") ) { 2438 var pixels = Object.keys(options.dynamicEvents.automatic_event_download); 2439 for (var i = 0; i < pixels.length; i++) { 2440 var event = Utils.clone(options.dynamicEvents.automatic_event_download[pixels[i]]); 2441 var extensions = event.extensions; 2442 if (extensions.includes(extension)) { 2443 2444 if(pixels[i] == "tiktok") { 2445 getPixelBySlag(pixels[i]).fireEvent(tikEvent.name, event); 2446 } else { 2447 if (options.enable_remove_download_url_param) { 2448 href = href.split('?')[0]; 2449 } 2450 event.params.download_url = href; 2451 event.params.download_type = extension; 2452 event.params.download_name = Utils.getLinkFilename(href); 2453 getPixelBySlag(pixels[i]).onDownloadEvent(event); 2454 } 2455 2456 isFired = true; 2457 } 2458 } 2459 } 2460 } 2461 } 2462 if(isFired) { // prevent duplicate events on the same element 2463 return; 2464 } 2465 } 2466 }); 2467 } 2468 2469 2470 // setup Dynamic events 2471 $.each(options.triggerEventTypes, function (triggerType, events) { 2472 2473 $.each(events, function (eventId, triggers) { 2474 2475 switch (triggerType) { 2476 case 'url_click': 2477 //@see: Utils.setupURLClickEvents() 2478 break; 2479 2480 case 'css_click': 2481 Utils.setupCSSClickEvents(eventId, triggers); 2482 break; 2483 2484 case 'css_mouseover': 2485 Utils.setupMouseOverClickEvents(eventId, triggers); 2486 break; 2487 2488 case 'scroll_pos': 2489 Utils.setupScrollPosEvents(eventId, triggers); 2490 break; 2491 case 'comment': 2492 Utils.setupCommentEvents(eventId, triggers); 2493 break; 2494 } 2495 2496 }); 2497 2498 }); 2499 // setup WooCommerce events 2500 if (options.woo.enabled) { 2501 2502 // WooCommerce AddToCart 2503 if (options.dynamicEvents.hasOwnProperty("woo_add_to_cart_on_button_click") 2504 && options.woo.hasOwnProperty("addToCartCatchMethod") 2505 && options.woo.addToCartCatchMethod === "add_cart_js" 2506 ) { 2507 2508 // Loop, any kind of "simple" product, except external 2509 $('.add_to_cart_button:not(.product_type_variable,.product_type_bundle,.single_add_to_cart_button)').on("click",function (e) { 2510 2511 var product_id = $(this).data('product_id'); 2512 2513 if (typeof product_id !== 'undefined') { 2514 Facebook.onWooAddToCartOnButtonEvent(product_id); 2515 Analytics.onWooAddToCartOnButtonEvent(product_id); 2516 Pinterest.onWooAddToCartOnButtonEvent(product_id); 2517 Bing.onWooAddToCartOnButtonEvent(product_id); 2518 } 2519 2520 }); 2521 2522 // Single Product 2523 // tap try to https://stackoverflow.com/questions/30990967/on-tap-click-event-firing-twice-how-to-avoid-it 2524 // $(document) not work 2525 $('body').onFirst('click','button.single_add_to_cart_button,.single_add_to_cart_button',function (e) { 2526 2527 var $button = $(this); 2528 2529 if ($button.hasClass('disabled')) { 2530 return; 2531 } 2532 2533 var $form = $button.closest('form'); 2534 2535 var product_type = Utils.PRODUCT_SIMPLE; 2536 2537 if ($form.length === 0) { 2538 return ; 2539 } else if ($form.hasClass('variations_form')) { 2540 product_type = Utils.PRODUCT_VARIABLE; 2541 } else if($form.hasClass('bundle_form')) { 2542 product_type = Utils.PRODUCT_BUNDLE; 2543 } else if($form.hasClass('grouped_form')) { 2544 product_type = Utils.PRODUCT_GROUPED; 2545 } 2546 2547 2548 2549 2550 var product_id; 2551 var qty; 2552 2553 if (product_type === Utils.PRODUCT_GROUPED) { 2554 qty = 1; 2555 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 2556 } else if (product_type === Utils.PRODUCT_VARIABLE) { 2557 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 2558 var qtyTag = $form.find('input[name="quantity"]'); 2559 if(qtyTag.length <= 0) { 2560 qtyTag = $form.find('select[name="quantity"]'); 2561 } 2562 qty = parseInt(qtyTag.val()); 2563 } else { 2564 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 2565 var qtyTag = $form.find('input[name="quantity"]'); 2566 if(qtyTag.length <= 0) { 2567 qtyTag = $form.find('select[name="quantity"]'); 2568 } 2569 qty = parseInt(qtyTag.val()); 2570 } 2571 2572 Facebook.onWooAddToCartOnSingleEvent(product_id, qty, product_type, $form); 2573 Analytics.onWooAddToCartOnSingleEvent(product_id, qty, product_type, $form); 2574 2575 Pinterest.onWooAddToCartOnSingleEvent(product_id, qty, product_type, false, $form); 2576 Bing.onWooAddToCartOnSingleEvent(product_id, qty, product_type, false, $form); 2577 2578 }); 2579 2580 } 2581 2582 // WooCommerce RemoveFromCart 2583 if (options.dynamicEvents.hasOwnProperty("woo_remove_from_cart")) { 2584 2585 $('body').on('click', options.woo.removeFromCartSelector, function (e) { 2586 2587 var $a = $(e.currentTarget), 2588 href = $a.attr('href'); 2589 2590 // extract cart item hash from remove button URL 2591 var regex = new RegExp("[\\?&]remove_item=([^&#]*)"), 2592 results = regex.exec(href); 2593 2594 if (results !== null) { 2595 2596 var item_hash = results[1]; 2597 2598 if (options.dynamicEvents["woo_remove_from_cart"].hasOwnProperty(item_hash)) { 2599 var events = options.dynamicEvents["woo_remove_from_cart"][item_hash]; 2600 Utils.fireEventForAllPixel("onWooRemoveFromCartEvent",events) 2601 } 2602 2603 } 2604 2605 }); 2606 } 2607 } 2608 2609 // setup EDD events 2610 if (options.edd.enabled) { 2611 2612 // EDD AddToCart 2613 if (options.dynamicEvents.hasOwnProperty("edd_add_to_cart_on_button_click")) { 2614 2615 $('form.edd_download_purchase_form .edd-add-to-cart').on("click",function (e) { 2616 2617 var $button = $(this); 2618 var $form = $button.closest('form'); 2619 var variable_price = $button.data('variablePrice'); // yes/no 2620 var price_mode = $button.data('priceMode'); // single/multi 2621 var ids = []; 2622 var quantities = []; 2623 var qty; 2624 var id; 2625 2626 if (variable_price === 'yes' && price_mode === 'multi') { 2627 2628 id = $form.find('input[name="download_id"]').val(); 2629 2630 // get selected variants 2631 $.each($form.find('input[name="edd_options[price_id][]"]:checked'), function (i, el) { 2632 ids.push(id + '_' + $(el).val()); 2633 }); 2634 2635 // get qty for selected variants 2636 $.each(ids, function (i, variant_id) { 2637 2638 var variant_index = variant_id.split('_', 2); 2639 qty = $form.find('input[name="edd_download_quantity_' + variant_index[1] + '"]').val(); 2640 2641 if (typeof qty !== 'undefined') { 2642 quantities.push(qty); 2643 } else { 2644 quantities.push(1); 2645 } 2646 2647 }); 2648 2649 } else if (variable_price === 'yes' && price_mode === 'single') { 2650 2651 id = $form.find('input[name="download_id"]').val(); 2652 ids.push(id + '_' + $form.find('input[name="edd_options[price_id][]"]:checked').val()); 2653 2654 qty = $form.find('input[name="edd_download_quantity"]').val(); 2655 2656 if (typeof qty !== 'undefined') { 2657 quantities.push(qty); 2658 } else { 2659 quantities.push(1); 2660 } 2661 2662 } else { 2663 2664 ids.push($button.data('downloadId')); 2665 2666 qty = $form.find('input[name="edd_download_quantity"]').val(); 2667 2668 if (typeof qty !== 'undefined') { 2669 quantities.push(qty); 2670 } else { 2671 quantities.push(1); 2672 } 2673 } 2674 2675 // fire event for each download/variant 2676 $.each(ids, function (i, download_id) { 2677 2678 var q = parseInt(quantities[i]); 2679 var variant_index = download_id.toString().split('_', 2); 2680 var price_index; 2681 2682 if (variant_index.length === 2) { 2683 download_id = variant_index[0]; 2684 price_index = variant_index[1]; 2685 } 2686 2687 Facebook.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2688 Analytics.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2689 Pinterest.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2690 Bing.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2691 2692 }); 2693 2694 }); 2695 2696 } 2697 2698 2699 // EDD RemoveFromCart 2700 if (options.dynamicEvents.hasOwnProperty("edd_remove_from_cart") ) { 2701 2702 $('form#edd_checkout_cart_form .edd_cart_remove_item_btn').on("click",function (e) { 2703 2704 var href = $(this).attr('href'); 2705 if(href) { 2706 var key = href.substring(href.indexOf('=') + 1).charAt(0); 2707 if (options.dynamicEvents.edd_remove_from_cart.hasOwnProperty(key)) { 2708 var events = options.dynamicEvents.edd_remove_from_cart[key]; 2709 Utils.fireEventForAllPixel("onEddRemoveFromCartEvent",events) 2710 } 2711 } 2712 }); 2713 2714 } 2715 2716 } 2717 2718 // setup Comment Event 2719 if (options.dynamicEvents.hasOwnProperty("automatic_event_c
2719omment") 2720 ) { 2721 2722 $('form.comment-form').on("submit",function () { 2723 if (options.dynamicEvents.hasOwnProperty("automatic_event_comment")) { 2724 var pixels = Object.keys(options.dynamicEvents.automatic_event_comment); 2725 for (var i = 0; i < pixels.length; i++) { 2726 var event = Utils.clone(options.dynamicEvents.automatic_event_comment[pixels[i]]); 2727 Utils.copyProperties(Utils.getRequestParams(), event.params); 2728 getPixelBySlag(pixels[i]).onCommentEvent(event); 2729 } 2730 } 2731 }); 2732 2733 } 2734 2735 2736 // setup Form Event 2737 if ( options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 2738 2739 $(document).onFirst('submit', 'form', function (e) { 2740 2741 var $form = $(this); 2742 2743 // exclude WP forms 2744 if ($form.hasClass('comment-form') || $form.hasClass('search-form') || $form.attr('id') === 'adminbarsearch') { 2745 return; 2746 } 2747 2748 // exclude Woo forms 2749 if ($form.hasClass('woocommerce-product-search') || $form.hasClass('cart') || $form.hasClass('woocommerce-cart-form') || 2750 $form.hasClass('woocommerce-shipping-calculator') || $form.hasClass('checkout') || $form.hasClass('checkout_coupon')) { 2751 return; 2752 } 2753 2754 // exclude EDD forms 2755 if ($form.hasClass('edd_form') || $form.hasClass('edd_download_purchase_form')) { 2756 return; 2757 } 2758// exclude CF7 forms 2759 if ($form.hasClass('wpcf7-form')) { 2760 return; 2761 } 2762 // exclude Forminator forms 2763 if ($form.hasClass('forminator-custom-form') || $form.hasClass('forminator_ajax')) { 2764 return; 2765 } 2766 // exclude WPforms forms 2767 if ($form.hasClass('wpforms-form') || $form.hasClass('wpforms-ajax-form')) { 2768 return; 2769 } 2770 // exclude Formidable forms 2771 /*if ($form.hasClass('frm-show-form')) { 2772 return; 2773 }*/ 2774 // exclude Ninja Forms forms 2775 if ($form.parent().hasClass('nf-form-layout')) { 2776 return; 2777 } 2778 // exclude Fluent forms 2779 if ($form.hasClass('frm-fluent-form')) { 2780 return; 2781 } 2782 if(!options.enable_success_send_form) { 2783 var params = { 2784 form_id: $form.attr('id'), 2785 form_class: $form.attr('class'), 2786 text: $form.find('[type="submit"]').is('input') ? 2787 $form.find('[type="submit"]').val() : $form.find('[type="submit"]').text() 2788 }; 2789 2790 if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 2791 var pixels = Object.keys(options.dynamicEvents.automatic_event_form); 2792 for (var i = 0; i < pixels.length; i++) { 2793 var event = Utils.clone(options.dynamicEvents.automatic_event_form[pixels[i]]); 2794 2795 if (pixels[i] === "tiktok") { 2796 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 2797 } else { 2798 Utils.copyProperties(params, event.params,) 2799 Utils.copyProperties(Utils.getRequestParam
2799s(), event.params); 2800 getPixelBySlag(pixels[i]).onFormEvent(event); 2801 } 2802 } 2803 } 2804 } 2805 }); 2806 2807 document.addEventListener( 'wpcf7mailsent', function( event ) { 2808 var form_id = event.detail.contactFormId; 2809 sendFormAction($(event.target), form_id); 2810 }, false ); 2811 //Forminator 2812 $(document).on( 'forminator:form:submit:success', function( event ){ 2813 var form_id = $(event.target).find('input[name="form_id"]').val(); 2814 sendFormAction($(event.target), form_id); 2815 }); 2816 2817 //WPForm 2818 $('form.wpforms-form').on('wpformsAjaxSubmitSuccess', (event) => { 2819 var form_id = $(event.target).attr('data-formid'); 2820 sendFormAction($(event.target), form_id); 2821 }) 2822 $(document).on( 'frmFormComplete', function( event, form, response ) { 2823 const form_id = $(form).find('input[name="form_id"]').val(); 2824 sendFormAction($(event.target), form_id); 2825 }); 2826 // Ninja Forms 2827 $(document).onFirst('nfFormSubmitResponse', function (event, data) { 2828 const form_id = data.response.data.form_id; 2829 sendFormAction($(event.target), form_id); 2830 }); 2831 2832 var fluentForms = $('form.frm-fluent-form'); 2833 fluentForms.each(function() { 2834 var $form = $(this); 2835 $form.on('fluentform_submission_success', function(event) { 2836 var $formItem = $(this); 2837 var form_id = $formItem.attr('data-form_id'); 2838 sendFormAction($(event.target), form_id); 2839 }); 2840 }); 2841 2842 } 2843 2844 2845 // load pixel APIs 2846 Utils.loadPixels(); 2847 // setup Enrich content 2848 if(Utils.isCheckoutPage()) { 2849 Utils.addCheckoutFields(); 2850 } 2851 }); 2852 2853 var sendFormAction = function (form_target, formId){ 2854 var params = { 2855 form_id: formId, 2856 text: form_target.find('[type="submit"]').is('input') ? form_target.find('[type="submit"]').val() : 2857 form_target.find('.forminator-button-submit').text() != '' ? form_target.find('.forminator-button-submit').text() : 2858 form_target.find('[type="submit"]').text() 2859 }; 2860 2861 if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 2862 var pixels = Object.keys(options.dynamicEvents.automatic_event_form); 2863 for (var i = 0; i < pixels.length; i++) { 2864 var event = options.dynamicEvents.automatic_event_form[pixels[i]]; 2865 if (pixels[i] === "tiktok") { 2866 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 2867 } else { 2868 Utils.copyProperties(params, event.params)
2869 Utils.copyProperties(Utils.getRequestParams(), event.params); 2870 getPixelBySlag(pixels[i]).onFormEvent(event); 2871 } 2872 } 2873 } 2874 } 2875 2876}(jQuery, pysOptions); 2877 2878var disabled_GDRP_plugin = false; 2879if (pysOptions.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 2880 if (Cookiebot.consented === false && !Cookiebot.consent['marketing'] && !Cookiebot.consent['statistics']) { 2881 disabled_GDRP_plugin = true; 2882 } 2883} 2884if (pysOptions.gdpr.cookie_law_info_integration_enabled) { 2885 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 2886 2887 if (typeof cli_cookie !== 'undefined') { 2888 if (cli_cookie === Cookies.get('cookieyes-consent')) { 2889 if (getCookieYes('analytics') !== 'yes') { 2890 disabled_GDRP_plugin = true; 2891 } 2892 } else if (cli_cookie === Cookies.get('viewed_cookie_policy')) { 2893 if (Cookies.get('viewed_cookie_policy') !== 'yes') { 2894 disabled_GDRP_plugin = true; 2895 } 2896 } 2897 } 2898 else if(typeof Cli_Data !== "undefined" && typeof cli_cookie == 'undefined'){ 2899 disabled_GDRP_plugin = true; 2900 } 2901} 2902 2903if (pysOptions.ajaxForServerEvent && !Cookies.get('pbid')) { 2904 jQuery.ajax({ 2905 url: pysOptions.ajaxUrl, 2906 dataType: 'json', 2907 data: { 2908 action: 'pys_get_pbid' 2909 }, 2910 success: function (res) { 2911 if (res.data && res.data.pbid != false && pysOptions.send_external_id) { 2912 if(!(pysOptions.cookie.disabled_all_cookie || pysOptions.cookie.externalID_disabled_by_api || disabled_GDRP_plugin)){ 2913 var expires = parseInt(pysOptions.external_id_expire || 180); 2914 Cookies.set('pbid', res.data.pbid, { expires: expires, path: '/' }); 2915 } 2916 2917 if(pysOptions.hasOwnProperty('facebook')) { 2918 pysOptions.facebook.advancedMatching = { 2919 ...pysOptions.facebook.advancedMatching, 2920 external_id: res.data.pbid 2921 }; 2922 } 2923 } 2924 } 2925 }); 2926} 2927function pys_generate_token(length){ 2928 //edit the token allowed characters 2929 var a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".split(""); 2930 var b = []; 2931 for (var i=0; i<length; i++) { 2932 var j = (Math.random() * (a.length-1)).toFixed(0); 2933 b[i] = a[j]; 2934 } 2935 return b.join(""); 2936} 2937 2938function getBundlePriceOnSingleProduct(data) { 2939 var items_sum = 0; 2940 jQuery(".bundle_form .bundled_product").each(function(index){ 2941 var id = jQuery(this).find(".cart").data("bundled_item_id"); 2942 var item_price = data.prices[id]; 2943 var item_quantity = jQuery(this).find(".bundled_qty").val(); 2944 if(!jQuery(this).hasClass("bundled_item_optional") || 2945 jQuery(this).find(".bundled_product_optional_checkbox input").prop('checked')) { 2946 items_sum += item_price*item_quantity; 2947 } 2948 }); 2949 return items_sum; 2950} 2951 2952function getPixelBySlag(slug) { 2953 switch (slug) { 2954 case "facebook": return window.pys.Facebook; 2955 case "ga": return window.pys.Analytics; 2956 case "bing": return window.pys.Bing; 2957 case "pinterest": return window.pys.Pinterest; 2958 } 2959} 2960var getUrlParameter = function getUrlParameter(sParam) { 2961 var sPageURL = window.location.search.substring(1), 2962 sURLVariables = sPageURL.split('&'), 2963 sParameterName, 2964 i; 2965 2966 for (i = 0; i < sURLVariables.length; i++) { 2967 sParameterName = sURLVariables[i].split('='); 2968 2969 if (sParameterName[0] === sParam) { 2970 return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); 2971 } 2972 } 2973 return false; 2974}; 2975function getCookieYes(key) { 2976 const cookies = document.cookie 2977 .split(";") 2978 .reduce( 2979 (ac, cv, i) => 2980 Object.assign(ac, { [cv.split("=")[0].trim()]: cv.split("=")[1] }), 2981 {} 2982 )["cookieyes-consent"]; 2983 const { [key]: value } = cookies 2984 .split(",") 2985 .reduce( 2986 (obj, pair) => ( 2987 (pair = pair.split(":")), (obj[pair[0]] = pair[1]), obj 2988 ), 2989 {} 2990 ); 2991 return value; 2992}
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.