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