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') && Facebook.isEnabled()) { 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 sendServerAjaxRequest : function(url, data) { 689 jQuery.ajax({ 690 type: 'POST', 691 url: url, 692 data: data, 693 headers: { 694 'Cache-Control': 'no-cache' 695 }, 696 success: function () {}, 697 }); 698 }, 699 // clone object 700 clone: function(obj) { 701 var copy; 702 703 // Handle the 3 simple types, and null or undefined 704 if (null == obj || "object" != typeof obj) return obj; 705 706 // Handle Date 707 if (obj instanceof Date) { 708 copy = new Date(); 709 copy.setTime(obj.getTime()); 710 return copy; 711 } 712 713 // Handle Array 714 if (obj instanceof Array) { 715 copy = []; 716 for (var i = 0, len = obj.length; i < len; i++) { 717 if("function" == typeof obj[i]) { 718 continue; 719 } 720 copy[i] = Utils.clone(obj[i]); 721 } 722 return copy; 723 } 724 725 // Handle Object 726 if (obj instanceof Object) { 727 copy = {}; 728 for (var attr in obj) { 729 if (obj.hasOwnProperty(attr)) { 730 if("function" == typeof obj[attr]) { 731 continue; 732 } 733 copy[attr] = Utils.clone(obj[attr]); 734 } 735 } 736 return copy; 737 } 738 739 return obj; 740 }, 741 742 // Returns array of elements with given tag name 743 getTagsAsArray: function (tag) { 744 return [].slice.call(document.getElementsByTagName(tag)); 745 }, 746
747 getRequestParams: function () { 748 return []; 749 }, 750 751 /** 752 * CUSTOM EVENTS 753 */ 754 755 setupMouseOverClickEvents: function (eventId, triggers) { 756 757 // Non-default binding used to avoid situations when some code in external js 758 // stopping events propagation, eg. returns false, and our handler will never called 759 document.addEventListener('mouseover', function(event) { 760 var matchedElements = Array.from(document.querySelectorAll(triggers)); 761 if (matchedElements.includes(event.target)) { 762 if (event.target.classList.contains('pys-mouse-over-' + eventId)) { 763 return true; 764 } else { 765 event.target.classList.add('pys-mouse-over-' + eventId); 766 } 767 768 Utils.fireTriggerEvent(eventId); 769 } 770 }); 771 772 }, 773 774 setupCSSClickEvents: function (eventId, triggers) { 775 // Non-default binding used to avoid situations when some code in external js 776 // stopping events propagation, eg. returns false, and our handler will never called 777 document.addEventListener('click', function(event) { 778 var matchedElements = Array.from(document.querySelectorAll(triggers)); 779 if (matchedElements.includes(event.target)) { 780 console.log(event.target) 781 Utils.fireTriggerEvent(eventId); 782 } 783 }, true); 784 }, 785 786 setupURLClickEvents: function () { 787 788 // Non-default binding used to avoid situations when some code in external js 789 // stopping events propagation, eg. returns false, and our handler will never called 790 $('a[data-pys-event-id]').onFirst('click', function (evt) { 791 792 $(this).attr('data-pys-event-id').split(',').forEach(function (eventId) { 793 794 eventId = parseInt(eventId); 795 796 if (isNaN(eventId) === false) { 797 Utils.fireTriggerEvent(eventId); 798 } 799 800 }); 801 802 }); 803 804 805 }, 806 807 setupScrollPosEvents: function (eventId, triggers) { 808 809 var scrollPosThresholds = {}, 810 docHeight = $(document).height() - $(window).height(); 811 812 // convert % to absolute positions 813 $.each(triggers, function (index, scrollPos) { 814 815 // convert % to pixels 816 scrollPos = docHeight * scrollPos / 100; 817 scrollPos = Math.round(scrollPos); 818 819 scrollPosThresholds[scrollPos] = eventId; 820 821 }); 822 823 $(document).on("scroll",function () { 824 825 var scrollPos = $(window).scrollTop(); 826 827 $.each(scrollPosThresholds, function (threshold, eventId) { 828 829 // position has not reached yes 830 if (scrollPos <= threshold) { 831 return true; 832 } 833 834 // fire event only once 835 if (eventId === null) { 836 return true; 837 } else { 838 scrollPosThresholds[threshold] = null; 839 } 840 841 Utils.fireTriggerEvent(eventId); 842 843 }); 844 845 }); 846 847 848 }, 849 setupCommentEvents : function (eventId,triggers) { 850 $('form.comment-form').on("submit",function () { 851 Utils.fireTriggerEvent(eventId); 852 }); 853 }, 854 855 /** 856 * Events 857 */ 858 859 fireTriggerEvent: function (eventId) { 860 861 if (!options.triggerEvents.hasOwnProperty(eventId)) { 862 return; 863 } 864 865 var event = {}; 866 var events = options.triggerEvents[eventId]; 867 868 if (events.hasOwnProperty('facebook')) { 869 event = events.facebook; 870 Facebook.fireEvent(event.name, event); 871 } 872 873 if (events.hasOwnProperty('ga')) { 874 event = events.ga; 875 Analytics.fireEvent(event.name, event); 876 } 877 878 if (events.hasOwnProperty('pinterest')) { 879 event = events.pinterest; 880 Pinterest.fireEvent(event.name, event); 881 } 882 883 if (events.hasOwnProperty('bing')) { 884 event = events.bing; 885 Bing.fireEvent(event.name, event); 886 } 887 }, 888 889 fireStaticEvents: function (pixel) { 890 891 if (options.staticEvents.hasOwnProperty(pixel)) { 892 893 $.each(options.staticEvents[pixel], function (eventName, events) { 894 $.each(events, function (index, eventData) { 895 896 eventData.fired = eventData.fired || false; 897 898 if (!eventData.fired) { 899 900 var fired = false;
901 902 // fire event 903 if ('facebook' === pixel) { 904 fired = Facebook.fireEvent(eventData.name, eventData); 905 } else if ('ga' === pixel) { 906 fired = Analytics.fireEvent(eventData.name, eventData); 907 } else if ('pinterest' === pixel) { 908 fired = Pinterest.fireEvent(eventData.name, eventData); 909 } else if ('bing' === pixel) { 910 fired = Bing.fireEvent(eventData.name, eventData); 911 } 912 913 // prevent event double event firing 914 eventData.fired = fired; 915 916 } 917 918 }); 919 }); 920 921 } 922 923 }, 924 925 /** 926 * Load tag's JS 927 * 928 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/ 929 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets 930 */ 931 loadGoogleTag: function (id) { 932 933 if (!gtag_loaded) { 934 935 (function (window, document, src) { 936 var a = document.createElement('script'), 937 m = document.getElementsByTagName('script')[0]; 938 a.async = 1; 939 a.src = src; 940 m.parentNode.insertBefore(a, m); 941 })(window, document, '//www.googletagmanager.com/gtag/js?id=' + id); 942 943 window.dataLayer = window.dataLayer || []; 944 window.gtag = window.gtag || function gtag() { 945 dataLayer.push(arguments); 946 }; 947 948 if ( options.google_consent_mode ) { 949 let data = {}; 950 data[ 'analytics_storage' ] = options.gdpr.analytics_storage.enabled ? options.gdpr.analytics_storage.value : 'granted'; 951 data[ 'ad_storage' ] = options.gdpr.ad_storage.enabled ? options.gdpr.ad_storage.value : 'granted'; 952 data[ 'ad_user_data' ] = options.gdpr.ad_user_data.enabled ? options.gdpr.ad_user_data.value : 'granted'; 953 data[ 'ad_personalization' ] = options.gdpr.ad_personalization.enabled ? options.gdpr.ad_personalization.value : 'granted'; 954 955 gtag( 'consent', 'default', data ); 956 } 957 958 gtag('js', new Date()); 959 gtag_loaded = true; 960 961 } 962 963 }, 964 965 /** 966 * GDPR 967 */ 968 969 loadPixels: function () { 970 971 if (options.gdpr.ajax_enabled && !options.gdpr.consent_magic_integration_enabled) { 972 973 // retrieves actual PYS GDPR filters values which allow to avoid cache issues 974 $.get({ 975 url: options.ajaxUrl, 976 dataType: 'json', 977 data: { 978 action: 'pys_get_gdpr_filters_values' 979 }, 980 success: function (res) { 981 982 if (res.success) { 983 984 options.gdpr.all_disabled_by_api = res.data.all_disabled_by_api; 985 options.gdpr.facebook_disabled_by_api = res.data.facebook_disabled_by_api; 986 options.gdpr.analytics_disabled_by_api = res.data.analytics_disabled_by_api; 987 options.gdpr.google_ads_disabled_by_api = res.data.google_ads_disabled_by_api; 988 options.gdpr.pinterest_disabled_by_api = res.data.pinterest_disabled_by_api; 989 options.gdpr.bing_disabled_by_api = res.data.bing_disabled_by_api; 990 991 options.cookie.externalID_disabled_by_api = res.data.externalID_disabled_by_api; 992 options.cookie.disabled_all_cookie = res.data.disabled_all_cookie; 993 options.cookie.disabled_advanced_form_data_cookie = res.data.disabled_advanced_form_data_cookie; 994 options.cookie.disabled_landing_page_cookie = res.data.disabled_landing_page_cookie; 995 options.cookie.disabled_first_visit_cookie = res.data.disabled_first_visit_cookie; 996 options.cookie.disabled_trafficsource_cookie = res.data.disabled_trafficsource_cookie; 997 options.cookie.disabled_utmTerms_cookie = res.data.disabled_utmTerms_cookie; 998 options.cookie.disabled_utmId_cookie = res.data.disabled_utmId_cookie; 999 } 1000 1001 loadPixels(); 1002 1003 } 1004 }); 1005 1006 } else { 1007 loadPixels(); 1008 } 1009 1010 }, 1011 1012 consentGiven: function (pixel) { 1013 1014 /** 1015 * ConsentMagic 1016 */ 1017 if ( options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined" ) { 1018 1019 var test_prefix = CS_Data.test_prefix; 1020 if ( ( typeof CS_Data.cs_google_consent_mode_enabled !== "undefined" && CS_Data.cs_google_consent_mode_enabled == 1 ) && ( pixel == 'analytics' || pixel == 'google_ads' ) ) { 1021 if ( CS_Data.cs_cache_enabled == 0 || ( CS_Data.cs_cache_enabled == 1 && window.CS_Cache && window.CS_Cache.check_status ) ) { 1022 return true; 1023 } else { 1024 return false;
1025 } 1026 } 1027 1028 if ( CS_Data.cs_script_cat.pys == CS_Data.cs_necessary_cat_id ) { 1029 return true; 1030 } else { 1031 if( pixel == 'facebook' && ( CS_Data.cs_script_cat.facebook == 0 || CS_Data.cs_script_cat.facebook == CS_Data.cs_necessary_cat_id ) ) { 1032 return true; 1033 } else if( pixel == 'bing' && ( CS_Data.cs_script_cat.bing == 0 || CS_Data.cs_script_cat.bing == CS_Data.cs_necessary_cat_id ) ) { 1034 return true; 1035 } else if( pixel == 'analytics' && ( CS_Data.cs_script_cat.analytics == 0 || CS_Data.cs_script_cat.analytics == CS_Data.cs_necessary_cat_id ) ) { 1036 return true; 1037 } else if( pixel == 'google_ads' && ( CS_Data.cs_script_cat.gads == 0 || CS_Data.cs_script_cat.gads == CS_Data.cs_necessary_cat_id ) ) { 1038 return true; 1039 } else if( pixel == 'pinterest' && ( CS_Data.cs_script_cat.pinterest == 0 || CS_Data.cs_script_cat.pinterest == CS_Data.cs_necessary_cat_id ) ) { 1040 return true; 1041 } else if( pixel == 'tiktok' && ( CS_Data.cs_script_cat.tiktok == 0 || CS_Data.cs_script_cat.tiktok == CS_Data.cs_necessary_cat_id ) ) { 1042 return true; 1043 } 1044 } 1045 1046 var substring = "cs_enabled_cookie_term"; 1047 var theCookies = document.cookie.split( ';' ); 1048 1049 for ( var i = 1; i <= theCookies.length; i++ ) { 1050 if ( theCookies[ i - 1 ].indexOf( substring ) !== -1 ) { 1051 var categoryCookie = theCookies[ i - 1 ].replace( 'cs_enabled_cookie_term' + test_prefix + '_', '' ); 1052 categoryCookie = Number( categoryCookie.replace( /\D+/g, "" ) ); 1053 var cs_cookie_val = Cookies.get( 'cs_enabled_cookie_term' + test_prefix + '_' + categoryCookie ); 1054 1055 if ( categoryCookie === CS_Data.cs_script_cat.facebook && pixel == 'facebook' ) { 1056 return cs_cookie_val == 'yes'; 1057 } else if ( categoryCookie === CS_Data.cs_script_cat.bing && pixel == 'bing' ) { 1058 return cs_cookie_val == 'yes'; 1059 } else if ( categoryCookie === CS_Data.cs_script_cat.analytics && pixel == 'analytics' ) { 1060 return cs_cookie_val == 'yes'; 1061 } else if ( categoryCookie === CS_Data.cs_script_cat.gads && pixel == 'google_ads' ) { 1062 return cs_cookie_val == 'yes'; 1063 } else if ( categoryCookie === CS_Data.cs_script_cat.pinterest && pixel == 'pinterest' ) { 1064 return cs_cookie_val == 'yes'; 1065 } else if ( categoryCookie === CS_Data.cs_script_cat.tiktok && pixel == 'tiktok' ) { 1066 return cs_cookie_val == 'yes'; 1067 } 1068 } 1069 } 1070 1071 return false; 1072 } 1073 1074 /** 1075 * Real Cookie Banner 1076 */ 1077 if(options.gdpr.real_cookie_banner_integration_enabled) { 1078 var consentApi = window.consentApi; 1079 if (consentApi) { 1080 switch (pixel) { 1081 case "analytics": 1082 return consentApi.consentSync("http", "_ga", "*").cookieOptIn; 1083 case "facebook": 1084 return consentApi.consentSync("http", "_fbp", "*").cookieOptIn; 1085 case "pinterest": 1086 return consentApi.consentSync("http", "_pinterest_sess", ".pinterest.com").cookieOptIn; 1087 default: 1088 return true; 1089 } 1090 } 1091 } 1092 1093 /** 1094 * Cookiebot 1095 */ 1096 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 1097 1098 var cookiebot_consent_category = options.gdpr['cookiebot_' + pixel + '_consent_category']; 1099 1100 if (options.gdpr[pixel + '_prior_consent_enabled']) { 1101 if (Cookiebot.consented === true || Cookiebot.consent[cookiebot_consent_category]) { 1102 return true; 1103 } 1104 } else { 1105 if (Cookiebot.consent[cookiebot_consent_category]) { 1106 return true; 1107 } 1108 } 1109 1110 return false;
1111 1112 } 1113 1114 /** 1115 * Cookie Notice 1116 */ 1117 if (options.gdpr.cookie_notice_integration_enabled && typeof cnArgs !== 'undefined') { 1118 1119 var cn_cookie = Cookies.get(cnArgs.cookieName); 1120 1121 if (options.gdpr[pixel + '_prior_consent_enabled']) { 1122 if (typeof cn_cookie === 'undefined' || cn_cookie === 'true') { 1123 return true; 1124 } 1125 } else { 1126 if (cn_cookie === 'true') { 1127 return true; 1128 } 1129 } 1130 1131 return false; 1132 1133 } 1134 1135 /** 1136 * Cookie Law Info 1137 */ 1138 if (options.gdpr.cookie_law_info_integration_enabled) { 1139 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 1140 if (options.gdpr[pixel + '_prior_consent_enabled']) { 1141 if (typeof cli_cookie === 'undefined') return true; 1142 if (cli_cookie && cli_cookie === Cookies.get('cookieyes-consent')) { 1143 if (getCookieYes('analytics') === 'yes') { 1144 return true; 1145 } 1146 } else if (cli_cookie && cli_cookie === Cookies.get('viewed_cookie_policy')) { 1147 if (Cookies.get('viewed_cookie_policy') === 'yes') { 1148 return true; 1149 } 1150 } 1151 } else { 1152 if (cli_cookie && cli_cookie === Cookies.get('cookieyes-consent')) { 1153 if (getCookieYes('analytics') === 'yes') { 1154 return true; 1155 } 1156 } else if (cli_cookie && cli_cookie === Cookies.get('viewed_cookie_policy')) { 1157 if (Cookies.get('viewed_cookie_policy') === 'yes') { 1158 return true; 1159 } 1160 } 1161 } 1162 return false; 1163 } 1164 1165 return true; 1166 1167 }, 1168 1169 setupGdprCallbacks: function () { 1170 /** 1171 * ConsentMagic 1172 */ 1173 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 1174 var test_prefix = CS_Data.test_prefix, 1175 cs_refresh_after_consent = false, 1176 substring = "cs_enabled_cookie_term"; 1177 1178 if (CS_Data.cs_refresh_after_consent == 1) { 1179 cs_refresh_after_consent = CS_Data.cs_refresh_after_consent; 1180 } 1181 1182 if (!cs_refresh_after_consent) { 1183 var theCookies = document.cookie.split(';'); 1184 for (var i = 1 ; i <= theCookies.length; i++) { 1185 if (theCookies[i-1].indexOf(substring) !== -1) { 1186 var categoryCookie = theCookies[i-1].replace('cs_enabled_cookie_term'+test_prefix+'_',''); 1187 categoryCookie = Number(categoryCookie.replace(/\D+/g,"")); 1188 var cs_cookie_val = Cookies.get('cs_enabled_cookie_term'+test_prefix+'_'+categoryCookie); 1189 if(cs_cookie_val == 'yes') { 1190 if (categoryCookie === CS_Data.cs_script_cat.facebook) { 1191 Facebook.loadPixel(); 1192 } 1193 1194 if (categoryCookie === CS_Data.cs_script_cat.bing) { 1195 Bing.loadPixel(); 1196 } 1197 1198 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)
1198) { 1199 1200 Analytics.loadPixel(); 1201 } 1202 1203 if (categoryCookie === CS_Data.cs_script_cat.pinterest) { 1204 Pinterest.loadPixel(); 1205 } 1206 } else { 1207 if (categoryCookie === CS_Data.cs_script_cat.facebook) { 1208 Facebook.disable(); 1209 } 1210 1211 if (categoryCookie === CS_Data.cs_script_cat.bing) { 1212 Bing.disable(); 1213 } 1214 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)) { 1215 Analytics.disable(); 1216 } 1217 1218 if (categoryCookie === CS_Data.cs_script_cat.pinterest) { 1219 Pinterest.disable(); 1220 } 1221 } 1222 if (Cookies.get('cs_enabled_advanced_matching') == 'yes') { 1223 Facebook.loadPixel(); 1224 } 1225 } 1226 } 1227 1228 $(document).on('click','.cs_action_btn',function(e) { 1229 e.preventDefault(); 1230 var elm = $(this), 1231 button_action = elm.attr('data-cs_action'); 1232 1233 if(button_action === 'allow_all') { 1234 Facebook.loadPixel(); 1235 Bing.loadPixel(); 1236 Analytics.loadPixel(); 1237 Pinterest.loadPixel(); 1238 } else if(button_action === 'disable_all') { 1239 Facebook.disable(); 1240 Bing.disable(); 1241 if(CS_Data.cs_google_analytics_consent_mode == 0 || typeof CS_Data.cs_google_analytics_consent_mode == "undefined") 1242 { 1243 Analytics.disable(); 1244 } 1245 Pinterest.disable(); 1246 } 1247 }); 1248 } 1249 } 1250 /** 1251 * Real Cookie Banner 1252 */ 1253 if(options.gdpr.real_cookie_banner_integration_enabled) { 1254 var consentApi = window.consentApi; 1255 if (consentApi) { 1256 consentApi.consent("http", "_ga", "*") 1257 .then(Analytics.loadPixel.bind(Analytics), Analytics.disable.bind(Analytics)); 1258 consentApi.consent("http", "_fbp", "*") 1259 .then(Facebook.loadPixel.bind(Facebook), Facebook.disable.bind(Facebook)); 1260 consentApi.consent("http", "_pinterest_sess", ".pinterest.com") 1261 .then(Pinterest.loadPixel.bind(Pinterest), Pinterest.disable.bind(Pinterest)); 1262 consentApi.consent("http", "_uetsid", "*") 1263 .then(Bing.loadPixel.bind(Bing), Bing.disable.bind(Bing)); 1264 } 1265 } 1266 /** 1267 * Cookiebot 1268 */ 1269 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 1270 1271 window.addEventListener("CookiebotOnConsentReady", function() { 1272 Utils.manageCookies(); 1273 if (Cookiebot.consent.marketing) { 1274 Facebook.loadPixel(); 1275 Bing.loadPixel(); 1276 Pinterest.loadPixel(); 1277 1278 } 1279 if (Cookiebot.consent.statistics) { 1280 Analytics.loadPixel(); 1281 } 1282 if (!Cookiebot.consent.marketing) { 1283 Facebook.disable(); 1284 Pinterest.disable(); 1285 Bing.disable() 1286 } 1287 if (!Cookiebot.consent.statistics) { 1288 Analytics.disable(); 1289 } 1290 }); 1291 1292 } 1293 1294 /** 1295 * Cookie Notice 1296 */ 1297 if (options.gdpr.cookie_notice_integration_enabled) { 1298 1299 $(document).onFirst('click', '.cn-set-cookie', function () { 1300 1301 if ($(this).data('cookie-set') === 'accept') { 1302 Facebook.loadPixel(); 1303 Analytics.loadPixel(); 1304 Pinterest.loadPixel(); 1305 Bing.loadPixel(); 1306 } else { 1307 Facebook.disable(); 1308 Analytics.disable(); 1309 Pinterest.disable(); 1310 Bing.disable(); 1311 } 1312 1313 }); 1314 1315 $(document).onFirst('click', '.cn-revoke-cookie', function () { 1316 Facebook.disable(); 1317 Analytics.disable(); 1318 Pinterest.disable(); 1319 Bing.disable(); 1320 }); 1321 1322 } 1323 1324 /** 1325 * Cookie Law Info 1326 */ 1327 if (options.gdpr.cookie_law_info_integration_enabled) { 1328 1329 $(document).onFirst('click', '#wt-cli-accept-all-btn,#cookie_action_close_header, .cky-btn-accept', function () { 1330 setTimeout(function (){ 1331 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 1332 if (typeof cli_cookie !== 'undefined') { 1333 if (cli_cookie === Cookies.get('cookieyes-consent') && getCookieYes('analytics') == 'yes') { 1334 Utils.manageCookies(); 1335 } else if (cli_cookie === Cookies.get('viewed_cookie_policy') && cli_cookie == 'yes') { 1336 Utils.manageCookies(); 1337 } 1338 } 1339 },1000) 1340 Facebook.loadPixel(); 1341 Analytics.loadPixel(); 1342 Pinterest.loadPixel(); 1343 Bing.loadPixel(); 1344 }); 1345 1346 $(document).onFirst('click', '#cookie_action_close_header_reject, .cky-btn-reject', function () { 1347 Facebook.disable(); 1348 Analytics.disable(); 1349 Pinterest.disable(); 1350 Bing.disable(); 1351 }); 1352 1353 } 1354 1355 }, 1356 1357 /** 1358 * DOWNLOAD DOCS 1359 */ 1360 1361 getLinkExtension: function (link) { 1362 1363 // Remove anchor, query string and everything before last slash 1364 link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); 1365 link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); 1366 link = link.substring(link.lastIndexOf("/") + 1, link.length); 1367 1368 // If there's a period left in the URL, then there's a extension 1369 if (link.length > 0 && link.indexOf('.') !== -1) { 1370 link = link.substring(link.indexOf(".") + 1); // Remove everything but what's after the first period 1371 return link; 1372 } else { 1373 return ""; 1374 } 1375 }, 1376 1377 getLinkFilename: function (link) { 1378 1379 // Remove anchor, query string and everything before last slash 1380 link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); 1381 link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); 1382 link = link.substring(link.lastIndexOf("/") + 1, link.length); 1383 1384 // If there's a period left in the URL, then there's a extension 1385 if (link.length > 0 && link.indexOf('.') !== -1) { 1386 return link; 1387 } else { 1388 return ""; 1389 } 1390 }, 1391 /** 1392 * Enrich 1393 */ 1394 isCheckoutPage: function () { 1395 return $('body').hasClass('woocommerce-checkout') || document.querySelector('.woocommerce-checkout') || 1396 $('body').hasClass('edd-checkout'); 1397 }, 1398 addCheckoutFields : function() { 1399 var utm = ""; 1400 var utms = getUTMs() 1401 1402 $.each(utmTerms, function (index, name) { 1403 if(index > 0) { 1404 utm+="|"; 1405 } 1406 utm+=name+":"+utms[name]; 1407 }); 1408 var utmIdList = ""; 1409 var utmsIds = getUTMId() 1410 $.each(utmId, function (index, name) { 1411 if(index > 0) { 1412 utmIdList+="|"; 1413 } 1414 utmIdList+=name+":"+utmsIds[name]; 1415 }); 1416 var utmIdListLast = ""; 1417 var utmsIdsLast = getUTMId(true) 1418 $.each(utmId, function (index, name) { 1419 if(index > 0) { 1420 utmIdListLast+="|"; 1421 } 1422 utmIdListLast+=name+":"+utmsIdsLast[name]; 1423 }); 1424 1425 1426 var utmLast = ""; 1427 var utmsLast = getUTMs(true) 1428 $.each(utmTerms, function (index, name) { 1429 if(index > 0) { 1430 utmLast+="|"; 1431 }
1432 utmLast+=name+":"+utmsLast[name]; 1433 }); 1434 1435 var dateTime = getDateTime(); 1436 var landing = getLandingPageValue(); 1437 var lastLanding = getLandingPageValue(); 1438 var trafic = getTrafficSourceValue(); 1439 var lastTrafic = getTrafficSourceValue(); 1440 1441 var $form = null; 1442 if($('body').hasClass('woocommerce-checkout')) { 1443 $form = $("form.woocommerce-checkout"); 1444 } else { 1445 $form = $("#edd_purchase_form"); 1446 } 1447 var inputs = {'pys_utm':utm, 1448 'pys_utm_id':utmIdList, 1449 'pys_browser_time':dateTime.join("|"), 1450 'pys_landing':landing, 1451 'pys_source':trafic, 1452 'pys_order_type': $(".wcf-optin-form").length > 0 ? "wcf-optin" : "normal", 1453 1454 'last_pys_landing':lastLanding, 1455 'last_pys_source':lastTrafic, 1456 'last_pys_utm':utmLast, 1457 'last_pys_utm_id':utmIdListLast, 1458 } 1459 1460 Object.keys(inputs).forEach(function(key,index) { 1461 $form.append("<input type='hidden' name='"+key+"' value='"+inputs[key]+"' /> "); 1462 }); 1463 1464 1465 }, 1466 getAdvancedFormData: function () { 1467 let dataStr = Cookies.get("pys_advanced_form_data"); 1468 if(dataStr === undefined) { 1469 return {'first_name':"",'last_name':"",'email':"",'phone':""}; 1470 } else { 1471 return JSON.parse(dataStr); 1472 } 1473 } 1474 }; 1475 1476 }(options); 1477 1478 var Facebook = function (options) { 1479 1480 1481 var defaultEventTypes = [ 1482 'PageView', 1483 'ViewContent', 1484 'Search', 1485 'AddToCart', 1486 'AddToWishlist', 1487 'InitiateCheckout', 1488 'AddPaymentInfo', 1489 'Purchase', 1490 'Lead', 1491 1492 'Subscribe', 1493 'CustomizeProduct', 1494 'FindLocation', 1495 'StartTrial', 1496 'SubmitApplication', 1497 'Schedule', 1498 'Contact', 1499 'Donate' 1500 ]; 1501 1502 var initialized = false; 1503 1504 // fire server side event gdpr plugin installed 1505 var isApiDisabled = options.gdpr.all_disabled_by_api || 1506 options.gdpr.facebook_disabled_by_api || 1507 options.gdpr.cookiebot_integration_enabled || 1508 options.gdpr.consent_magic_integration_enabled || 1509 options.gdpr.cookie_notice_integration_enabled || 1510 options.gdpr.cookie_law_info_integration_enabled; 1511 1512 /** 1513 * 1514 * @param allData 1515 * @param params 1516 * @returns {string | null} 1517 */ 1518 function sendFbServerEvent(allData,name,params) { 1519 let eventId = null; 1520 if(options.facebook.serverApiEnabled) { 1521 1522 if(allData.e_id === "woo_remove_from_cart") {// server event will sended from hook 1523 Facebook.updateEventId(allData.name); 1524 allData.eventID = Facebook.getEventId(allData.name); 1525 } else { 1526 // send event from server if they was bloc by gdpr or need send with delay 1527 if( !allData.eventID && (options.ajaxForServerEvent || event.type !== "static")) { 1528 allData.eventID = pys_generate_token(36); 1529 } 1530 if( options.ajaxForServerEvent || isApiDisabled ){ 1531 var json = { 1532 action: 'pys_api_event', 1533 pixel: 'facebook', 1534 event: name, 1535 data:params, 1536 ids:options.facebook.pixelIds, 1537 eventID:allData.eventID, 1538 url:window.location.href, 1539 ajax_event:options.ajax_event 1540 }; 1541 if(allData.hasOwnProperty('woo_order')) { 1542 json['woo_order'] = allData.woo_order; 1543 } 1544 if(allData.hasOwnProperty('edd_order')) { 1545 json['edd_order'] = allData.edd_order; 1546 } 1547 1548 if (allData.e_id === "automatic_event_internal_link" || allData.e_id === "automatic_event_outbound_link") { 1549 setTimeout(() => Utils.sendServerAjaxRequest(options.ajaxUrl, json), 500); 1550 } else if (allData.type != 'static') { 1551 Utils.sendServerAjaxRequest(options.ajaxUrl, json); 1552 } 1553 } 1554 } 1555 eventId = allData.eventID 1556 } 1557 1558 return eventId; 1559 } 1560 1561 function fireEvent(name, allData) { 1562 1563 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'facebook')) { 1564 return; 1565 } 1566 1567 var actionType = defaultEventTypes.includes(name) ? 'track' : 'trackCustom'; 1568 var data = allData.params; 1569 var params = {}; 1570 var arg = {}; 1571 Utils.copyProperties(data, params); 1572 1573 let eventId = sendFbServerEvent(allData,name,params) 1574 1575 1576 if("hCR" === name) { 1577 return; 1578 } 1579 1580 if (options.debug) { 1581 console.log('[Facebook] ' + name, params,"eventID",eventId); 1582 } 1583 1584 if(eventId != null) { 1585 arg.eventID = eventId; 1586 } 1587 1588 fbq(actionType, name, params, arg); 1589 1590 } 1591 1592 /** 1593 * Public API 1594 */ 1595 return { 1596 tag: function() { 1597 return "facebook"; 1598 }, 1599 isEnabled: function () { 1600 return options.hasOwnProperty('facebook'); 1601 }, 1602 1603 disable: function () { 1604 initialized = false;
1605 }, 1606 advancedMatching: function () { 1607 if(options.facebook.advancedMatchingEnabled) { 1608 let advancedMatchingForm = Utils.getAdvancedFormData(); 1609 let advancedMatching = {}; 1610 if(Object.keys(options.facebook.advancedMatching).length > 0) { 1611 advancedMatching = options.facebook.advancedMatching; 1612 } 1613 1614 if(!advancedMatching.hasOwnProperty("em") 1615 && advancedMatchingForm.hasOwnProperty("email") && advancedMatchingForm["email"].length > 0) { 1616 advancedMatching["em"] = advancedMatchingForm["email"]; 1617 } 1618 if(!advancedMatching.hasOwnProperty("ph") 1619 && advancedMatchingForm.hasOwnProperty("phone") && advancedMatchingForm["phone"].length > 0) { 1620 advancedMatching["ph"] = advancedMatchingForm["phone"]; 1621 } 1622 if(!advancedMatching.hasOwnProperty("fn") 1623 && advancedMatchingForm.hasOwnProperty("first_name") && advancedMatchingForm["first_name"].length > 0) { 1624 advancedMatching["fn"] = advancedMatchingForm["first_name"]; 1625 } 1626 if(!advancedMatching.hasOwnProperty("ln") 1627 && advancedMatchingForm.hasOwnProperty("last_name") && advancedMatchingForm["last_name"].length > 0) { 1628 advancedMatching["ln"] = advancedMatchingForm["last_name"]; 1629 } 1630 if(!advancedMatching.hasOwnProperty("external_id")){ 1631 if (Cookies.get('pbid') || (options.hasOwnProperty('pbid') && options.pbid)) { 1632 advancedMatching["external_id"] = Cookies.get('pbid') ? Cookies.get('pbid') : options.pbid; 1633 } 1634 } 1635 else if(advancedMatching.external_id != Cookies.get('pbid')) 1636 { 1637 advancedMatching["external_id"] = Cookies.get('pbid') ? Cookies.get('pbid') : advancedMatching.external_id; 1638 } 1639 if(Object.keys(advancedMatching).length > 0) { 1640 return advancedMatching; 1641 } 1642 } 1643 return false 1644 }, 1645 /** 1646 * Load pixel's JS 1647 */ 1648 loadPixel: function () { 1649 1650 if (initialized || !this.isEnabled() || !Utils.consentGiven('facebook')) { 1651 return; 1652 } 1653 1654 !function (f, b, e, v, n, t, s) { 1655 if (f.fbq) return; 1656 n = f.fbq = function () { 1657 n.callMethod ? 1658 n.callMethod.apply(n, arguments) : n.queue.push(arguments) 1659 }; 1660 if (!f._fbq) f._fbq = n; 1661 n.push = n; 1662 n.loaded = !0; 1663 n.version = '2.0'; 1664 n.agent = 'dvpixelyoursite'; 1665 n.queue = []; 1666 t = b.createElement(e); 1667 t.async = !0; 1668 t.src = v; 1669 s = b.getElementsByTagName(e)[0]; 1670 s.parentNode.insertBefore(t, s) 1671 }(window, 1672 document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); 1673 1674 let expires = parseInt(options.cookie_duration); 1675 if(!Cookies.get('_fbp') && options.facebook.hasOwnProperty('fbp')) { 1676 Cookies.set('_fbp', options.facebook.fbp, { expires: expires }); 1677 } 1678 1679 if(!Cookies.get('_fbc') && options.facebook.hasOwnProperty('fbc') && options.facebook.fbc.length > 0) { 1680 Cookies.set('_fbc', options.facebook.fbc, { expires: expires }); 1681 } 1682 // initialize pixel 1683 options.facebook.pixelIds.forEach(function (pixelId) { 1684 if (options.facebook.removeMetadata) { 1685 fbq('set', 'autoConfig', false, pixelId); 1686 } 1687 let advancedMatching = Facebook.advancedMatching(); 1688 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 1689 if(!advancedMatching) { 1690 fbq('init', pixelId); 1691 } else { 1692 var test_prefix = CS_Data.test_prefix; 1693 var cs_advanced_matching = Cookies.get('cs_enabled_advanced_matching'+test_prefix); 1694 if (jQuery('#cs_enabled_advanced_matching'+test_prefix).length > 0) { 1695 if (cs_advanced_matching == 'yes') { 1696 fbq('init', pixelId, advancedMatching); 1697 } else { 1698 fbq('init', pixelId); 1699 } 1700 } else { 1701 fbq('init', pixelId, advancedMatching); 1702 } 1703 } 1704 } else { 1705 if(!advancedMatching) { 1706 fbq('init', pixelId); 1707 } else { 1708 fbq('init', pixelId, advancedMatching); 1709 } 1710 } 1711 }); 1712 1713 initialized = true; 1714 1715 Utils.fireStaticEvents('facebook'); 1716 1717 }, 1718 1719 fireEvent: function (name, data) { 1720 1721 if (!initialized || !this.isEnabled()) { 1722 return false;
1723 } 1724 1725 data.delay = data.delay || 0; 1726 data.params = data.params || {}; 1727 1728 if (data.delay === 0) { 1729 1730 fireEvent(name, data); 1731 1732 } else { 1733 1734 setTimeout(function (name, params) { 1735 fireEvent(name, params); 1736 }, data.delay * 1000, name, data); 1737 1738 } 1739 1740 return true; 1741 1742 }, 1743 1744 onCommentEvent: function (event) { 1745 this.fireEvent(event.name, event); 1746 }, 1747 1748 onDownloadEvent: function (event) { 1749 this.fireEvent(event.name, event); 1750 }, 1751 1752 onFormEvent: function (event) { 1753 1754 this.fireEvent(event.name, event); 1755 1756 }, 1757 1758 onWooAddToCartOnButtonEvent: function (product_id) { 1759 1760 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 1761 return; 1762 var event = options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]; 1763 1764 if (window.pysWooProductData.hasOwnProperty(product_id)) { 1765 if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { 1766 event = Utils.copyProperties(event, {}) 1767 Utils.copyProperties(window.pysWooProductData[product_id]['facebook'].params, event.params) 1768 this.fireEvent(event.name, event); 1769 } 1770 } 1771 }, 1772 1773 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, $form) { 1774 1775 window.pysWooProductData = window.pysWooProductData || []; 1776 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 1777 return; 1778 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 1779 1780 if (product_type === Utils.PRODUCT_VARIABLE && !options.facebook.wooVariableAsSimple) { 1781 product_id = parseInt($form.find('input[name="variation_id"]').val()); 1782 } 1783 1784 if (window.pysWooProductData.hasOwnProperty(product_id)) { 1785 if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { 1786 1787 1788 Utils.copyProperties(window.pysWooProductData[product_id]['facebook'].params, event.params); 1789 1790 var groupValue = 0; 1791 if(product_type === Utils.PRODUCT_GROUPED ) { 1792 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 1793 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 1794 var quantity = parseInt($(this).val()); 1795 if(isNaN(quantity)) { 1796 quantity = 0; 1797 } 1798 var childItem = window.pysWooProductData[product_id]['facebook'].grouped[childId]; 1799 1800 if(quantity == 0) { 1801 event.params.content_ids.forEach(function(el,index,array) { 1802 if(el == childItem.content_id) { 1803 array.splice(index, 1); 1804 } 1805 }); 1806 } 1807 1808 if(event.params.hasOwnProperty('contents')) { 1809 event.params.contents.forEach(function(el,index,array) { 1810 if(el.id == childItem.content_id) { 1811 if(quantity > 0){ 1812 el.quantity = quantity; 1813 } else { 1814 array.splice(index, 1); 1815 } 1816 } 1817 }); 1818 } 1819 1820 1821 groupValue += childItem.price * quantity; 1822 }); 1823 if(groupValue == 0) return;
1823 // skip if no items selected 1824 } 1825 1826 // maybe customize value option 1827 if (options.woo.addToCartOnButtonValueEnabled && options.woo.addToCartOnButtonValueOption !== 'global') { 1828 1829 if(product_type === Utils.PRODUCT_GROUPED) { 1830 event.params.value = groupValue; 1831 } else if(product_type === Utils.PRODUCT_BUNDLE) { 1832 var data = $(".bundle_form .bundle_data").data("bundle_form_data"); 1833 var items_sum = getBundlePriceOnSingleProduct(data); 1834 event.params.value = (parseInt(data.base_price) + items_sum )* qty; 1835 } else { 1836 event.params.value = event.params.value * qty; 1837 } 1838 } 1839 1840 // only when non Facebook for WooCommerce logic used 1841 if (event.params.hasOwnProperty('contents') && product_type !== Utils.PRODUCT_GROUPED) { 1842 event.params.contents[0].quantity = qty; 1843 } 1844 1845 this.fireEvent(event.name, event); 1846 1847 } 1848 } 1849 }, 1850 1851 onWooRemoveFromCartEvent: function (event) { 1852 this.fireEvent(event.name, event); 1853 }, 1854 1855 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 1856 1857 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 1858 return; 1859 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 1860 1861 if (window.pysEddProductData.hasOwnProperty(download_id)) { 1862 1863 var index; 1864 1865 if (price_index) { 1866 index = download_id + '_' + price_index; 1867 } else { 1868 index = download_id; 1869 } 1870 1871 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 1872 if (window.pysEddProductData[download_id][index].hasOwnProperty('facebook')) { 1873 1874 1875 Utils.copyProperties(window.pysEddProductData[download_id][index]['facebook']["params"], event.params) 1876 1877 // maybe customize value option 1878 if (options.edd.addToCartOnButtonValueEnabled && options.edd.addToCartOnButtonValueOption !== 'global') { 1879 event.params.value = event.params.value * qty; 1880 } 1881 1882 // update contents qty param 1883 var contents = event.params.contents; 1884 contents[0].quantity = qty; 1885 event.params.contents = contents; 1886 1887 this.fireEvent(event.name,event); 1888 1889 } 1890 } 1891 1892 } 1893 1894 }, 1895 1896 onEddRemoveFromCartEvent: function (event) { 1897 this.fireEvent(event.name, event); 1898 }, 1899 onPageScroll: function (event) { 1900 this.fireEvent(event.name, event); 1901 }, 1902 onTime: function (event) { 1903 this.fireEvent(event.name, event); 1904 }, 1905 initEventIdCookies: function (key) { 1906 var ids = {}; 1907 ids[key] = pys_generate_token(36) 1908 Cookies.set('pys_fb_event_id', JSON.stringify(ids)); 1909 }, 1910 updateEventId:function(key) { 1911 var cooData = Cookies.get("pys_fb_event_id") 1912 if(cooData === undefined) { 1913 this.initEventIdCookies(key); 1914 } else { 1915 var data = JSON.parse(cooData); 1916 data[key] = pys_generate_token(36); 1917 Cookies.set('pys_fb_event_id', JSON.stringify(data) ); 1918 } 1919 }, 1920 1921 getEventId:function (key) { 1922 var data = Cookies.get("pys_fb_event_id"); 1923 if(data === undefined) {
1924 this.initEventIdCookies(key); 1925 data = Cookies.get("pys_fb_event_id"); 1926 } 1927 return JSON.parse(data)[key]; 1928 }, 1929 }; 1930 1931 }(options); 1932 1933 var Analytics = function (options) { 1934 1935 var initialized = false; 1936 1937 /** 1938 * Fires event 1939 * 1940 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data 1941 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/events 1942 * @link: https://developers.google.com/gtagjs/reference/event 1943 * @link: https://developers.google.com/gtagjs/reference/parameter 1944 * 1945 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets 1946 * 1947 * @param name 1948 * @param data 1949 */ 1950 function fireEvent(name, data) { 1951 1952 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'ga')) { 1953 return; 1954 } 1955 1956 var eventParams = Utils.copyProperties(data, {}); 1957 1958 var _fireEvent = function (tracking_id,name,params) { 1959 1960 params['send_to'] = tracking_id; 1961 1962 if (options.debug) { 1963 console.log('[Google Analytics #' + tracking_id + '] ' + name, params); 1964 } 1965 1966 gtag('event', name, params); 1967 1968 }; 1969 1970 options.ga.trackingIds.forEach(function (tracking_id) { 1971 var copyParams = Utils.copyProperties(eventParams, {}); // copy params because mapParamsTov4 can modify it 1972 var params = mapParamsTov4(tracking_id,name,copyParams) 1973 _fireEvent(tracking_id,name,params); 1974 }); 1975 1976 } 1977 function mapParamsTov4(tag,name,param) { 1978 //GA4 automatically collects a number of parameters for all events 1979 delete param.landing_page; 1980 // end 1981 if(isv4(tag)) { 1982 delete param.traffic_source; 1983 delete param.event_category; 1984 delete param.event_label; 1985 delete param.ecomm_prodid; 1986 delete param.ecomm_pagetype; 1987 delete param.ecomm_totalvalue; 1988 if(name === 'search') { 1989 param['search'] = param.search_term; 1990 delete param.search_term; 1991 delete param.dynx_itemid; 1992 delete param.dynx_pagetype; 1993 delete param.dynx_totalvalue; 1994 } 1995 } 1996 return param; 1997 } 1998 1999 function isv4(tag) { 2000 return tag.indexOf('G') === 0; 2001 } 2002 2003 /** 2004 * Public API 2005 */ 2006 return { 2007 tag: function() { 2008 return "ga"; 2009 }, 2010 isEnabled: function () { 2011 return options.hasOwnProperty('ga'); 2012 }, 2013 2014 disable: function () { 2015 initialized = false; 2016 }, 2017 2018 loadPixel: function () { 2019 2020 if (initialized || !this.isEnabled() || !Utils.consentGiven('analytics')) { 2021 return; 2022 } 2023 2024 Utils.loadGoogleTag(options.ga.trackingIds[0]); 2025 var config = {}; 2026 // Cross-Domain tracking 2027 if (options.ga.crossDomainEnabled) { 2028 config.linker = { 2029 accept_incoming: options.ga.crossDomainAcceptIncoming, 2030 domains: options.ga.crossDomainDomains 2031 }; 2032 } 2033 2034 2035 2036 // configure tracking ids 2037 options.ga.trackingIds.forEach(function (trackingId,index) { 2038 var obj = options.ga.isDebugEnabled; 2039 var searchValue = "index_"+index; 2040 var config = Object.assign({}, options.config); 2041 config.debug_mode = false;
2042 2043 for (var key in obj) { 2044 if (obj.hasOwnProperty(key) && obj[key] === searchValue) { 2045 config.debug_mode = true; 2046 break; 2047 } 2048 } 2049 if(!config.debug_mode) 2050 { 2051 delete config.debug_mode; 2052 } 2053 if(isv4(trackingId)) { 2054 if(options.ga.disableAdvertisingFeatures) { 2055 config.allow_google_signals = false 2056 } 2057 if(options.ga.disableAdvertisingPersonalization) { 2058 config.allow_ad_personalization_signals = false 2059 } 2060 } 2061 if(options.ga.hasOwnProperty('serverContainerUrls')){ 2062 if(options.ga.serverContainerUrls.hasOwnProperty(trackingId)){ 2063 config.server_container_url = options.ga.serverContainerUrls[trackingId]; 2064 } 2065 } 2066 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 2067 2068 var cookiebot_consent_category = options.gdpr['cookiebot_analytics_consent_category']; 2069 if (options.gdpr['analytics_prior_consent_enabled']) { 2070 if (Cookiebot.consented === true && Cookiebot.consent[cookiebot_consent_category]) { 2071 gtag('config', trackingId, config); 2072 } 2073 } else { 2074 if (Cookiebot.consent[cookiebot_consent_category]) { 2075 gtag('config', trackingId, config); 2076 } 2077 } 2078 } 2079 else 2080 { 2081 gtag('config', trackingId, config); 2082 } 2083 }); 2084 2085 initialized = true; 2086 2087 Utils.fireStaticEvents('ga'); 2088 2089 }, 2090 2091 fireEvent: function (name, data) { 2092 2093 if (!initialized || !this.isEnabled()) { 2094 return false; 2095 } 2096 2097 data.delay = data.delay || 0; 2098 data.params = data.params || {}; 2099 2100 if (data.delay === 0) { 2101 2102 fireEvent(name, data.params); 2103 2104 } else { 2105 2106 setTimeout(function (name, params) { 2107 fireEvent(name, params); 2108 }, data.delay * 1000, name, data.params); 2109 2110 } 2111 2112 return true; 2113 2114 }, 2115 2116 onCommentEvent: function (event) { 2117 this.fireEvent(event.name, event); 2118 }, 2119 2120 onDownloadEvent: function (event) { 2121 this.fireEvent(event.name, event); 2122 }, 2123 2124 onFormEvent: function (event) { 2125 this.fireEvent(event.name, event); 2126 }, 2127 2128 onWooAddToCartOnButtonEvent: function (product_id) { 2129 2130 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 2131 return; 2132 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 2133 2134 if (window.pysWooProductData.hasOwnProperty(product_id)) { 2135 if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { 2136 Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params) 2137 this.fireEvent(event.name, event); 2138 } 2139 } 2140 2141 2142 }, 2143 2144 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, $form) { 2145 2146 window.pysWooProductData = window.pysWooProductData || []; 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 (product_type === Utils.PRODUCT_VARIABLE && !options.ga.wooVariableAsSimple) { 2153 product_id = parseInt($form.find('input[name="variation_id"]').val()); 2154 } 2155 2156 if (window.pysWooProductData.hasOwnProperty(product_id)) { 2157 if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { 2158 2159 Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params); 2160 if(product_type === Utils.PRODUCT_GROUPED ) { 2161 var groupValue = 0; 2162 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 2163 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 2164 var quantity = parseInt($(this).val()); 2165 if(isNaN(quantity)) { 2166 quantity = 0; 2167 } 2168 var childItem = window.pysWooProductData[product_id]['ga'].grouped[childId]; 2169 // update quantity
2170 event.params.items.forEach(function(el,index,array) { 2171 if(el.id == childItem.content_id) { 2172 if(quantity > 0){ 2173 el.quantity = quantity; 2174 } else { 2175 array.splice(index, 1); 2176 } 2177 } 2178 }); 2179 groupValue += childItem.price * quantity; 2180 }); 2181 if(options.woo.addToCartOnButtonValueEnabled && 2182 options.woo.addToCartOnButtonValueOption !== 'global' && 2183 event.params.hasOwnProperty('ecomm_totalvalue')) { 2184 event.params.ecomm_totalvalue = groupValue; 2185 } 2186 2187 if(groupValue == 0) return; // skip if no items selected 2188 } else { 2189 // update items qty param 2190 event.params.items[0].quantity = qty; 2191 } 2192 2193 // maybe customize value option 2194 if (options.woo.addToCartOnButtonValueEnabled && 2195 options.woo.addToCartOnButtonValueOption !== 'global' && 2196 product_type !== Utils.PRODUCT_GROUPED) 2197 { 2198 if(event.params.hasOwnProperty('ecomm_totalvalue')) { 2199 event.params.ecomm_totalvalue = event.params.items[0].price * qty; 2200 } 2201 2202 } 2203 2204 2205 this.fireEvent(event.name, event); 2206 } 2207 } 2208 2209 }, 2210 2211 onWooRemoveFromCartEvent: function (event) { 2212 2213 this.fireEvent(event.name, event); 2214 2215 }, 2216 2217 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 2218 2219 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 2220 return; 2221 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 2222 2223 2224 if (window.pysEddProductData.hasOwnProperty(download_id)) { 2225 2226 var index; 2227 2228 if (price_index) { 2229 index = download_id + '_' + price_index; 2230 } else { 2231 index = download_id; 2232 } 2233 2234 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 2235 if (window.pysEddProductData[download_id][index].hasOwnProperty('ga')) { 2236 2237 Utils.copyProperties(window.pysEddProductData[download_id][index]['ga'].params, event.params); 2238 2239 // update items qty param 2240 event.params.items[0].quantity = qty; 2241 2242 this.fireEvent(event.name,event); 2243 2244 } 2245 } 2246 2247 } 2248 2249 }, 2250 2251 onEddRemoveFromCartEvent: function (event) { 2252 this.fireEvent(event.name, event); 2253 }, 2254 onPageScroll: function (event) { 2255 this.fireEvent(event.name, event); 2256 }, 2257 onTime: function (event) { 2258 this.fireEvent(event.name, event); 2259 }, 2260 2261 }; 2262 2263 }(options); 2264 2265 window.pys = window.pys || {}; 2266 window.pys.Facebook = Facebook; 2267 window.pys.Analytics = Analytics; 2268 window.pys.Utils = Utils; 2269 2270 2271 2272 2273 $(document).ready(function () { 2274 2275 if($("#pys_late_event").length > 0) { 2276 var events = JSON.parse($("#pys_late_event").attr("dir")); 2277 for(var key in events) { 2278 var event = {}; 2279 event[events[key].e_id] = [events[key]]; 2280 if(options.staticEvents.hasOwnProperty(key)) { 2281 Object.assign(options.staticEvents[key], event); 2282 } else { 2283 options.staticEvents[key] = event; 2284 } 2285 2286 } 2287 } 2288 2289 var Pinterest = Utils.setupPinterestObject(); 2290 var Bing = Utils.setupBingObject(); 2291 2292 if(options.hasOwnProperty('cookie')) 2293 { 2294 if(options.cookie.externalID_disabled_by_api || options.cookie.disabled_all_cookie) 2295 { 2296 Cookies.remove('pbid') 2297 } 2298 if(options.cookie.disabled_advanced_form_data_cookie || options.cookie.disabled_all_cookie) 2299 { 2300 Cookies.remove('pys_advanced_form_data') 2301 } 2302 if(options.cookie.disabled_landing_page_cookie || options.cookie.disabled_all_cookie) 2303 { 2304 Cookies.remove('pys_landing_page') 2305 Cookies.remove('last_pys_landing_page') 2306 } 2307 if(options.cookie.disabled_trafficsource_cookie || options.cookie.disabled_all_cookie) 2308 { 2309 Cookies.remove('pysTrafficSource') 2310 Cookies.remove('last_pysTrafficSource') 2311 } 2312 if(options.cookie.disabled_first_visit_cookie || options.cookie.disabled_all_cookie) 2313 { 2314 Cookies.remove('pys_first_visit') 2315 2316 } 2317 if(options.cookie.disabled_utmTerms_cookie || options.cookie.disabled_all_cookie) 2318 { 2319 $.each(Utils.utmTerms, function (index, name) { 2320 Cookies.remove('pys_' + name) 2321 }); 2322 $.each(Utils.utmTerms, function (index, name) { 2323 Cookies.remove('last_pys_' + name) 2324 }); 2325 } 2326 if(options.cookie.disabled_utmId_cookie || options.cookie.disabled_all_cookie) 2327 { 2328 $.each(Utils.utmId,function(index,name) { 2329 Cookies.remove('pys_' + name) 2330 }) 2331 $.each(Utils.utmId,function(index,name) { 2332 Cookies.remove('last_pys_' + name) 2333 }); 2334 } 2335 } 2336 2337 2338 if (options.gdpr.cookie_law_info_integration_enabled) { 2339 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 2340 2341 if (typeof cli_cookie !== 'undefined') { 2342 if (cli_cookie === Cookies.get('cookieyes-consent') && getCookieYes('analytics') == 'yes') { 2343 Utils.manageCookies(); 2344 } else if (cli_cookie === Cookies.get('viewed_cookie_policy') && cli_cookie == 'yes') { 2345 Utils.manageCookies(); 2346 } 2347 } 2348 } 2349 2350 if ( options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined" ) { 2351 if ( CS_Data.cs_script_cat.pys == CS_Data.cs_necessary_cat_id || CS_Data.cs_script_cat.pys == 0 ) { 2352 Utils.manageCookies(); 2353 } else if ( Cookies.get( 'cs_enabled_cookie_term' + CS_Data.test_prefix + '_' + CS_Data.cs_script_cat.pys ) == 'yes' ) { 2354 Utils.manageCookies(); 2355 } 2356 } else { 2357 Utils.manageCookies(); 2358 } 2359 2360 Utils.setupGdprCallbacks(); 2361 // page scroll event 2362 if ( options.dynamicEvents.hasOwnProperty("automatic_event_scroll") 2363 ) { 2364 2365 var singlePageScroll = function () { 2366 2367 2368 var docHeight = $(document).height() - $(window).height(); 2369 var isFired = false;
2370 2371 if (options.dynamicEvents.hasOwnProperty("automatic_event_scroll")) { 2372 var pixels = Object.keys(options.dynamicEvents.automatic_event_scroll); 2373 for(var i = 0;i<pixels.length;i++) { 2374 var event = Utils.clone(options.dynamicEvents.automatic_event_scroll[pixels[i]]); 2375 var scroll = Math.round(docHeight * event.scroll_percent / 100)// convert % to absolute positions 2376 2377 if(scroll < $(window).scrollTop()) { 2378 Utils.copyProperties(Utils.getRequestParams(), event.params); 2379 getPixelBySlag(pixels[i]).onPageScroll(event); 2380 isFired = true 2381 } 2382 } 2383 } 2384 if(isFired) { 2385 $(document).off("scroll",singlePageScroll); 2386 } 2387 } 2388 $(document).on("scroll",singlePageScroll); 2389 } 2390 2391 2392 if (options.dynamicEvents.hasOwnProperty("automatic_event_time_on_page")) { 2393 var pixels = Object.keys(options.dynamicEvents.automatic_event_time_on_page); 2394 var time = options.dynamicEvents.automatic_event_time_on_page[pixels[0]].time_on_page; // the same for all pixel 2395 setTimeout(function(){ 2396 for(var i = 0;i<pixels.length;i++) { 2397 var event = Utils.clone(options.dynamicEvents.automatic_event_time_on_page[pixels[i]]);
2398 Utils.copyProperties(Utils.getRequestParams(), event.params); 2399 getPixelBySlag(pixels[i]).onTime(event); 2400 } 2401 },time*1000); 2402 } 2403 2404 // setup Click Event 2405 if (options.dynamicEvents.hasOwnProperty("automatic_event_download")) { 2406 2407 $(document).onFirst('click', 'a, button, input[type="button"], input[type="submit"]', function (e) { 2408 2409 var $elem = $(this); 2410 2411 // Download 2412 if(options.dynamicEvents.hasOwnProperty("automatic_event_download") 2413 ) { 2414 var isFired = false; 2415 if ($elem.is('a')) { 2416 var href = $elem.attr('href'); 2417 if (typeof href !== "string") { 2418 return; 2419 } 2420 href = href.trim(); 2421 var extension = Utils.getLinkExtension(href); 2422 var track_download = false; 2423 2424 if (extension.length > 0) { 2425 2426 if(options.dynamicEvents.hasOwnProperty("automatic_event_download") ) { 2427 var pixels = Object.keys(options.dynamicEvents.automatic_event_download); 2428 for (var i = 0; i < pixels.length; i++) { 2429 var event = Utils.clone(options.dynamicEvents.automatic_event_download[pixels[i]]); 2430 var extensions = event.extensions; 2431 if (extensions.includes(extension)) { 2432 2433 if(pixels[i] == "tiktok") { 2434 getPixelBySlag(pixels[i]).fireEvent(tikEvent.name, event); 2435 } else { 2436 if (options.enable_remove_download_url_param) { 2437 href = href.split('?')[0]; 2438 } 2439 event.params.download_url = href; 2440 event.params.download_type = extension; 2441 event.params.download_name = Utils.getLinkFilename(href); 2442 getPixelBySlag(pixels[i]).onDownloadEvent(event); 2443 } 2444 2445 isFired = true; 2446 } 2447 } 2448 } 2449 } 2450 } 2451 if(isFired) { // prevent duplicate events on the same element 2452 return; 2453 } 2454 } 2455 }); 2456 } 2457 2458 2459 // setup Dynamic events 2460 $.each(options.triggerEventTypes, function (triggerType, events) { 2461 2462 $.each(events, function (eventId, triggers) { 2463 2464 switch (triggerType) { 2465 case 'url_click': 2466 //@see: Utils.setupURLClickEvents() 2467 break; 2468 2469 case 'css_click': 2470 Utils.setupCSSClickEvents(eventId, triggers); 2471 break; 2472 2473 case 'css_mouseover': 2474 Utils.setupMouseOverClickEvents(eventId, triggers); 2475 break; 2476 2477 case 'scroll_pos': 2478 Utils.setupScrollPosEvents(eventId, triggers); 2479 break; 2480 case 'comment': 2481 Utils.setupCommentEvents(eventId, triggers); 2482 break; 2483 } 2484 2485 }); 2486 2487 }); 2488 // setup WooCommerce events 2489 if (options.woo.enabled) { 2490 2491 // WooCommerce AddToCart 2492 if (options.dynamicEvents.hasOwnProperty("woo_add_to_cart_on_button_click") 2493 && options.woo.hasOwnProperty("addToCartCatchMethod") 2494 && options.woo.addToCartCatchMethod === "add_cart_js" 2495 ) { 2496 2497 // Loop, any kind of "simple" product, except external 2498 $('.add_to_cart_button:not(.product_type_variable,.product_type_bundle,.single_add_to_cart_button)').on("click",function (e) { 2499 2500 var product_id = $(this).data('product_id'); 2501 2502 if (typeof product_id !== 'undefined') { 2503 Facebook.onWooAddToCartOnButtonEvent(product_id); 2504 Analytics.onWooAddToCartOnButtonEvent(product_id); 2505 Pinterest.onWooAddToCartOnButtonEvent(product_id); 2506 Bing.onWooAddToCartOnButtonEvent(product_id); 2507 } 2508 2509 }); 2510 2511 // Single Product 2512 // tap try to https://stackoverflow.com/questions/30990967/on-tap-click-event-firing-twice-how-to-avoid-it 2513 // $(document) not work 2514 $('body').onFirst('click','button.single_add_to_cart_button,.single_add_to_cart_button',function (e) { 2515 2516 var $button = $(this); 2517 2518 if ($button.hasClass('disabled')) { 2519 return; 2520 } 2521 2522 var $form = $button.closest('form'); 2523 2524 var product_type = Utils.PRODUCT_SIMPLE; 2525 2526 if ($form.length === 0) { 2527 return ; 2528 } else if ($form.hasClass('variations_form')) { 2529 product_type = Utils.PRODUCT_VARIABLE; 2530 } else if($form.hasClass('bundle_form')) { 2531 product_type = Utils.PRODUCT_BUNDLE; 2532 } else if($form.hasClass('grouped_form')) { 2533 product_type = Utils.PRODUCT_GROUPED; 2534 } 2535 2536 2537 2538 2539 var product_id; 2540 var qty; 2541 2542 if (product_type === Utils.PRODUCT_GROUPED) { 2543 qty = 1; 2544 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 2545 } else if (product_type === Utils.PRODUCT_VARIABLE) { 2546 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 2547 var qtyTag = $form.find('input[name="quantity"]'); 2548 if(qtyTag.length <= 0) { 2549 qtyTag = $form.find('select[name="quantity"]'); 2550 } 2551 qty = parseInt(qtyTag.val()); 2552 } else { 2553 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 2554 var qtyTag = $form.find('input[name="quantity"]'); 2555 if(qtyTag.length <= 0) { 2556 qtyTag = $form.find('select[name="quantity"]'); 2557 } 2558 qty = parseInt(qtyTag.val()); 2559 } 2560 2561 Facebook.onWooAddToCartOnSingleEvent(product_id, qty, product_type, $form); 2562 Analytics.onWooAddToCartOnSingleEvent(product_id, qty, product_type, $form); 2563 2564 Pinterest.onWooAddToCartOnSingleEvent(product_id, qty, product_type, false, $form); 2565 Bing.onWooAddToCartOnSingleEvent(product_id, qty, product_type, false, $form); 2566 2567 }); 2568 2569 } 2570 2571 // WooCommerce RemoveFromCart 2572 if (options.dynamicEvents.hasOwnProperty("woo_remove_from_cart")) { 2573 2574 $('body').on('click', options.woo.removeFromCartSelector, function (e) { 2575 2576 var $a = $(e.currentTarget), 2577 href = $a.attr('href'); 2578 2579 // extract cart item hash from remove button URL 2580 var regex = new RegExp("[\\?&]remove_item=([^&#]*)"), 2581 results = regex.exec(href); 2582 2583 if (results !== null) { 2584 2585 var item_hash = results[1]; 2586 2587 if (options.dynamicEvents["woo_remove_from_cart"].hasOwnProperty(item_hash)) { 2588 var events = options.dynamicEvents["woo_remove_from_cart"][item_hash]; 2589 Utils.fireEventForAllPixel("onWooRemoveFromCartEvent",events) 2590 } 2591 2592 } 2593 2594 }); 2595 } 2596 } 2597 2598 // setup EDD events 2599 if (options.edd.enabled) { 2600 2601 // EDD AddToCart 2602 if (options.dynamicEvents.hasOwnProperty("edd_add_to_cart_on_button_click")) { 2603 2604 $('form.edd_download_purchase_form .edd-add-to-cart').on("click",function (e) { 2605 2606 var $button = $(this); 2607 var $form = $button.closest('form'); 2608 var variable_price = $button.data('variablePrice'); // yes/no 2609 var price_mode = $button.data('priceMode'); // single/multi 2610 var ids = []; 2611 var quantities = []; 2612 var qty; 2613 var id; 2614 2615 if (variable_price === 'yes' && price_mode === 'multi') { 2616 2617 id = $form.find('input[name="download_id"]').val(); 2618 2619 // get selected variants 2620 $.each($form.find('input[name="edd_options[price_id][]"]:checked'), function (i, el) { 2621 ids.push(id + '_' + $(el).val()); 2622 }); 2623 2624 // get qty for selected variants 2625 $.each(ids, function (i, variant_id) { 2626 2627 var variant_index = variant_id.split('_', 2); 2628 qty = $form.find('input[name="edd_download_quantity_' + variant_index[1] + '"]').val(); 2629 2630 if (typeof qty !== 'undefined') { 2631 quantities.push(qty); 2632 } else { 2633 quantities.push(1); 2634 } 2635 2636 }); 2637 2638 } else if (variable_price === 'yes' && price_mode === 'single') { 2639 2640 id = $form.find('input[name="download_id"]').val(); 2641 ids.push(id + '_' + $form.find('input[name="edd_options[price_id][]"]:checked').val()); 2642 2643 qty = $form.find('input[name="edd_download_quantity"]').val(); 2644 2645 if (typeof qty !== 'undefined') { 2646 quantities.push(qty); 2647 } else { 2648 quantities.push(1); 2649 } 2650 2651 } else { 2652 2653 ids.push($button.data('downloadId')); 2654 2655 qty = $form.find('input[name="edd_download_quantity"]').val(); 2656 2657 if (typeof qty !== 'undefined') { 2658 quantities.push(qty); 2659 } else { 2660 quantities.push(1); 2661 } 2662 } 2663 2664 // fire event for each download/variant 2665 $.each(ids, function (i, download_id) { 2666 2667 var q = parseInt(quantities[i]); 2668 var variant_index = download_id.toString().split('_', 2); 2669 var price_index; 2670 2671 if (variant_index.length === 2) { 2672 download_id = variant_index[0]; 2673 price_index = variant_index[1]; 2674 } 2675 2676 Facebook.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2677 Analytics.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2678 Pinterest.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2679 Bing.onEddAddToCartOnButtonEvent(download_id, price_index, q); 2680 2681 }); 2682 2683 }); 2684 2685 } 2686 2687 2688 // EDD RemoveFromCart 2689 if (options.dynamicEvents.hasOwnProperty("edd_remove_from_cart") ) { 2690 2691 $('form#edd_checkout_cart_form .edd_cart_remove_item_btn').on("click",function (e) { 2692 2693 var href = $(this).attr('href'); 2694 if(href) { 2695 var key = href.substring(href.indexOf('=') + 1).charAt(0); 2696 if (options.dynamicEvents.edd_remove_from_cart.hasOwnProperty(key)) { 2697 var events = options.dynamicEvents.edd_remove_from_cart[key]; 2698 Utils.fireEventForAllPixel("onEddRemoveFromCartEvent",events) 2699 } 2700 } 2701 }); 2702 2703 } 2704 2705 } 2706 2707 // setup Comment Event 2708 if (options.dynamicEvents.hasOwnProperty("automatic_event_c
2708omment") 2709 ) { 2710 2711 $('form.comment-form').on("submit",function () { 2712 if (options.dynamicEvents.hasOwnProperty("automatic_event_comment")) { 2713 var pixels = Object.keys(options.dynamicEvents.automatic_event_comment); 2714 for (var i = 0; i < pixels.length; i++) { 2715 var event = Utils.clone(options.dynamicEvents.automatic_event_comment[pixels[i]]); 2716 Utils.copyProperties(Utils.getRequestParams(), event.params); 2717 getPixelBySlag(pixels[i]).onCommentEvent(event); 2718 } 2719 } 2720 }); 2721 2722 } 2723 2724 2725 // setup Form Event 2726 if ( options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 2727 2728 $(document).onFirst('submit', 'form', function (e) { 2729 2730 var $form = $(this); 2731 2732 // exclude WP forms 2733 if ($form.hasClass('comment-form') || $form.hasClass('search-form') || $form.attr('id') === 'adminbarsearch') { 2734 return; 2735 } 2736 2737 // exclude Woo forms 2738 if ($form.hasClass('woocommerce-product-search') || $form.hasClass('cart') || $form.hasClass('woocommerce-cart-form') || 2739 $form.hasClass('woocommerce-shipping-calculator') || $form.hasClass('checkout') || $form.hasClass('checkout_coupon')) { 2740 return; 2741 } 2742 2743 // exclude EDD forms 2744 if ($form.hasClass('edd_form') || $form.hasClass('edd_download_purchase_form')) { 2745 return; 2746 } 2747// exclude CF7 forms 2748 if ($form.hasClass('wpcf7-form')) { 2749 return; 2750 } 2751 // exclude Forminator forms 2752 if ($form.hasClass('forminator-custom-form') || $form.hasClass('forminator_ajax')) { 2753 return; 2754 } 2755 // exclude WPforms forms 2756 if ($form.hasClass('wpforms-form') || $form.hasClass('wpforms-ajax-form')) { 2757 return; 2758 } 2759 // exclude Formidable forms 2760 /*if ($form.hasClass('frm-show-form')) { 2761 return; 2762 }*/ 2763 // exclude Ninja Forms forms 2764 if ($form.parent().hasClass('nf-form-layout')) { 2765 return; 2766 } 2767 // exclude Fluent forms 2768 if ($form.hasClass('frm-fluent-form')) { 2769 return; 2770 } 2771 if(!options.enable_success_send_form) { 2772 var params = { 2773 form_id: $form.attr('id'), 2774 form_class: $form.attr('class'), 2775 text: $form.find('[type="submit"]').is('input') ? 2776 $form.find('[type="submit"]').val() : $form.find('[type="submit"]').text() 2777 }; 2778 2779 if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 2780 var pixels = Object.keys(options.dynamicEvents.automatic_event_form); 2781 for (var i = 0; i < pixels.length; i++) { 2782 var event = Utils.clone(options.dynamicEvents.automatic_event_form[pixels[i]]); 2783 2784 if (pixels[i] === "tiktok") { 2785 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 2786 } else { 2787 Utils.copyProperties(params, event.params,) 2788 Utils.copyProperties(Utils.getRequestParam
2788s(), event.params); 2789 getPixelBySlag(pixels[i]).onFormEvent(event); 2790 } 2791 } 2792 } 2793 } 2794 }); 2795 2796 document.addEventListener( 'wpcf7mailsent', function( event ) { 2797 var form_id = event.detail.contactFormId; 2798 sendFormAction($(event.target), form_id); 2799 }, false ); 2800 //Forminator 2801 $(document).on( 'forminator:form:submit:success', function( event ){ 2802 var form_id = $(event.target).find('input[name="form_id"]').val(); 2803 sendFormAction($(event.target), form_id); 2804 }); 2805 2806 //WPForm 2807 $('form.wpforms-form').on('wpformsAjaxSubmitSuccess', (event) => { 2808 var form_id = $(event.target).attr('data-formid'); 2809 sendFormAction($(event.target), form_id); 2810 }) 2811 $(document).on( 'frmFormComplete', function( event, form, response ) { 2812 const form_id = $(form).find('input[name="form_id"]').val(); 2813 sendFormAction($(event.target), form_id); 2814 }); 2815 // Ninja Forms 2816 $(document).onFirst('nfFormSubmitResponse', function (event, data) { 2817 const form_id = data.response.data.form_id; 2818 sendFormAction($(event.target), form_id); 2819 }); 2820 2821 var fluentForms = $('form.frm-fluent-form'); 2822 fluentForms.each(function() { 2823 var $form = $(this); 2824 $form.on('fluentform_submission_success', function(event) { 2825 var $formItem = $(this); 2826 var form_id = $formItem.attr('data-form_id'); 2827 sendFormAction($(event.target), form_id); 2828 }); 2829 }); 2830 2831 } 2832 2833 2834 // load pixel APIs 2835 Utils.loadPixels(); 2836 // setup Enrich content 2837 if(Utils.isCheckoutPage()) { 2838 Utils.addCheckoutFields(); 2839 } 2840 }); 2841 2842 var sendFormAction = function (form_target, formId){ 2843 var params = { 2844 form_id: formId, 2845 text: form_target.find('[type="submit"]').is('input') ? form_target.find('[type="submit"]').val() : 2846 form_target.find('.forminator-button-submit').text() != '' ? form_target.find('.forminator-button-submit').text() : 2847 form_target.find('[type="submit"]').text() 2848 }; 2849 2850 if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 2851 var pixels = Object.keys(options.dynamicEvents.automatic_event_form); 2852 for (var i = 0; i < pixels.length; i++) { 2853 var event = options.dynamicEvents.automatic_event_form[pixels[i]]; 2854 if (pixels[i] === "tiktok") { 2855 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 2856 } else { 2857 Utils.copyProperties(params, event.params)
2858 Utils.copyProperties(Utils.getRequestParams(), event.params); 2859 getPixelBySlag(pixels[i]).onFormEvent(event); 2860 } 2861 } 2862 } 2863 } 2864 2865}(jQuery, pysOptions); 2866 2867function pys_generate_token(length){ 2868 //edit the token allowed characters 2869 var a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".split(""); 2870 var b = []; 2871 for (var i=0; i<length; i++) { 2872 var j = (Math.random() * (a.length-1)).toFixed(0); 2873 b[i] = a[j]; 2874 } 2875 return b.join(""); 2876} 2877 2878function getBundlePriceOnSingleProduct(data) { 2879 var items_sum = 0; 2880 jQuery(".bundle_form .bundled_product").each(function(index){ 2881 var id = jQuery(this).find(".cart").data("bundled_item_id"); 2882 var item_price = data.prices[id]; 2883 var item_quantity = jQuery(this).find(".bundled_qty").val(); 2884 if(!jQuery(this).hasClass("bundled_item_optional") || 2885 jQuery(this).find(".bundled_product_optional_checkbox input").prop('checked')) { 2886 items_sum += item_price*item_quantity; 2887 } 2888 }); 2889 return items_sum; 2890} 2891 2892function getPixelBySlag(slug) { 2893 switch (slug) { 2894 case "facebook": return window.pys.Facebook; 2895 case "ga": return window.pys.Analytics; 2896 case "bing": return window.pys.Bing; 2897 case "pinterest": return window.pys.Pinterest; 2898 } 2899} 2900var getUrlParameter = function getUrlParameter(sParam) { 2901 var sPageURL = window.location.search.substring(1), 2902 sURLVariables = sPageURL.split('&'), 2903 sParameterName, 2904 i; 2905 2906 for (i = 0; i < sURLVariables.length; i++) { 2907 sParameterName = sURLVariables[i].split('='); 2908 2909 if (sParameterName[0] === sParam) { 2910 return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); 2911 } 2912 } 2913 return false; 2914}; 2915function getCookieYes(key) { 2916 const cookies = document.cookie 2917 .split(";") 2918 .reduce( 2919 (ac, cv, i) => 2920 Object.assign(ac, { [cv.split("=")[0].trim()]: cv.split("=")[1] }), 2921 {} 2922 )["cookieyes-consent"]; 2923 const { [key]: value } = cookies 2924 .split(",") 2925 .reduce( 2926 (obj, pair) => ( 2927 (pair = pair.split(":")), (obj[pair[0]] = pair[1]), obj 2928 ), 2929 {} 2930 ); 2931 return value; 2932}
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.