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 56if (!String.prototype.startsWith) { 57 Object.defineProperty(String.prototype, 'startsWith', { 58 enumerable: false, 59 configurable: false, 60 writable: false, 61 value: function (searchString, position) { 62 position = position || 0; 63 return this.indexOf(searchString, position) === position; 64 } 65 }); 66} 67 68if (!String.prototype.trim) { 69 (function () { 70 String.prototype.trim = function () { 71 return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); 72 }; 73 })(); 74} 75 76! function ($, options) { 77 if (options.debug) { 78 console.log('PYS:', options); 79 } 80 81 var uniqueId = {}; 82 83 var firstVisit = false; 84 85 var isTrackEventForGA = []; 86 87 var isAdsLoad = false; 88 89 let gtm_variables = {}; 90 let gtm_datalayername = "dynamicVariable"; 91 var domain = ''; 92 if(options.hasOwnProperty("track_cookie_for_subdomains") && options.track_cookie_for_subdomains) { 93 domain = getRootDomain(true); 94 } 95 96 97 98 var loadTags = []; 99 100 var dummyPinterest = function () { 101 102 /** 103 * Public API 104 */ 105 return { 106 tag: function() { 107 return "pinterest"; 108 }, 109 isEnabled: function () {}, 110 111 disable: function () {}, 112 113 loadPixel: function () {}, 114 115 fireEvent: function (name, data) { 116 return false; 117 }, 118 119 onAdSenseEvent: function (event) {}, 120 121 onClickEvent: function (params) {}, 122 123 onWatchVideo: function (params) {}, 124 125 onCommentEvent: function (event) {}, 126 127 onFormEvent: function (params) {}, 128 129 onDownloadEvent: function (params) {}, 130 131 132 133 onWooAddToCartOnButtonEvent: function (product_id) {}, 134 135 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, is_external, $form) {}, 136 137 onWooRemoveFromCartEvent: function (cart_item_hash) {}, 138 139 onWooAffiliateEvent: function (product_id) {}, 140 141 onWooPayPalEvent: function (event) {}, 142 143 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) {}, 144 145 onEddRemoveFromCartEvent: function (item) {}, 146 147 onPageScroll: function (event) {}, 148 onTime: function (event) { 149 150 }, 151 152 } 153 154 }(); 155 156 var dummyBing = function () { 157 158 /** 159 * Public API 160 */ 161 return { 162 tag: function() { 163 return "bing"; 164 }, 165 isEnabled: function () {}, 166 167 disable: function () {}, 168 169 loadPixel: function () {}, 170 171 fireEvent: function (name, data) { 172 return false; 173 }, 174 175 onAdSenseEvent: function (event) {}, 176 177 onClickEvent: function (params) {}, 178 179 onWatchVideo: function (params) {}, 180 181 onCommentEvent: function (event) {}, 182 183 onFormEvent: function (params) {}, 184 185 onDownloadEvent: function (params) {}, 186 187 188 onWooAddToCartOnButtonEvent: function (product_id) {}, 189 190 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, is_external, $form) {}, 191 192 onWooRemoveFromCartEvent: function (cart_item_hash) {}, 193 194 onWooAffiliateEvent: function (product_id) {}, 195 196 onWooPayPalEvent: function (event) {}, 197 198 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) {}, 199 200 onEddRemoveFromCartEvent: function (item) {}, 201 onPageScroll: function (event) {}, 202 onTime: function (event) { 203 204 }, 205 } 206 207 }(); 208 209 var Utils = function (options) { 210 211 212 var Pinterest = dummyPinterest; 213 214 var Bing = dummyBing; 215 216 var gtag_loaded = false; 217 218 var gtm_loaded = false; 219 220 let isNewSession = checkSession(); 221 222 let dataLayerName = 'dataLayerPYS'; 223 224 let GTMdataLayerName = 'dataLayer'; 225 226 227 function loadPixels() { 228 229 if (!options.gdpr.all_disabled_by_api) { 230 if (!options.gdpr.tiktok_disabled_by_api) { 231 TikTok.loadPixel(); 232 } 233 234 if (!options.gdpr.facebook_disabled_by_api) { 235 Facebook.loadPixel(); 236 } 237 238 if (!options.gdpr.analytics_disabled_by_api) { 239 Analytics.loadPixel(); 240 } 241 242 if (!options.gdpr.google_ads_disabled_by_api) { 243 GAds.loadPixel(); 244 } 245 246 if (!options.gdpr.analytics_disabled_by_api) { 247 GTM.loadPixel(); 248 } 249 250 if (!options.gdpr.pinterest_disabled_by_api) { 251 Pinterest.loadPixel(); 252 } 253 254 if (!options.gdpr.bing_disabled_by_api) { 255 Bing.loadPixel(); 256 } 257 258 } 259 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 260 if (typeof CS_Data.cs_google_analytics_consent_mode !== "undefined" && CS_Data.cs_google_analytics_consent_mode == 1) { 261 Analytics.loadPixel(); 262 } 263 if (typeof CS_Data.cs_google_ads_consent_mode !== "undefined" && CS_Data.cs_google_ads_consent_mode == 1 ) { 264 GAds.loadPixel(); 265 } 266 } 267 } 268 269 /** 270 * WATCHVIDEO UTILS 271 */ 272 273 function isJSApiAttrEnabled(url) { 274 return url.indexOf('enablejsapi') > -1; 275 } 276 277 function isOriginAttrEnabled(url) { 278 return url.indexOf('origin') > -1; 279 } 280 281 // Returns key/value pairs of percentages: number of seconds to achieve 282 function getVideoCompletionMarks(duration) { 283 284 var marks = {}; 285 var points = [0, 10, 50, 90, 100]; 286 287 for (var i = 0; i < points.length; i++) { 288 289 var _point = points[i]; 290 var _mark = _point + '%'; 291 var _time = duration * _point / 100; 292 293 if (_point === 100) { 294 _time = _time - 1; 295 } 296 297 // 10% => 123 298 marks[_mark] = Math.floor(_time); 299 300 } 301 302 return marks; 303 304 } 305 306 // Determine if the element is a YouTube video or not 307 function tagIsYouTubeVideo(tag) { 308 var src = tag.src || ''; 309 return src.indexOf('youtube.com/embed/') > -1 || src.indexOf('youtube.com/v/') > -1; 310 } 311 312 function tagIsYouTubeAsyncVideo(tag) { 313 if(tag.src && tag.src.indexOf("data:image") !== -1) return false; // video is loaded 314 var keys = Object.keys(tag.dataset); 315 for(var i = 0;i<keys.length;i++) { 316 if(keys[i].toLowerCase().indexOf("src") > -1) { 317 var src = tag.dataset[keys[i]]; 318 return src.indexOf('youtube.com/embed/') > -1 || src.indexOf('youtube.com/v/') > -1; 319 } 320 } 321 return false; //not find src 322 } 323 324 // Turn embed objects into iframe objects and ensure they have the right parameters 325 function normalizeYouTubeIframe(tag) { 326 327 var loc = window.location; 328 var a = document.createElement('a'); 329 a.href = tag.src; 330 a.hostname = 'www.youtube.com'; 331 a.protocol = loc.protocol; 332 var tmpPathname = a.pathname.charAt(0) === '/' ? a.pathname : '/' + a.pathname; // IE10 shim 333 334 if (!isJSApiAttrEnabled(a.search)) { 335 a.search = (a.search.length > 0 ? a.search + '&' : '') + 'enablejsapi=1'; 336 } 337 338 // for security reasons, YouTube wants an origin parameter set that matches our hostname
339 if (!isOriginAttrEnabled(a.search) && loc.hostname.indexOf('localhost') === -1) { 340 341 var port = loc.port ? ':' + loc.port : ''; 342 var origin = loc.protocol + '%2F%2F' + loc.hostname + port; 343 344 a.search = a.search + '&origin=' + origin; 345 346 } 347 348 if (tag.type === 'application/x-shockwave-flash') { 349 350 var newIframe = document.createElement('iframe'); 351 newIframe.height = tag.height; 352 newIframe.width = tag.width; 353 tmpPathname = tmpPathname.replace('/v/', '/embed/'); 354 355 tag.parentNode.parentNode.replaceChild(newIframe, tag.parentNode); 356 357 tag = newIframe; 358 359 } 360 361 a.pathname = tmpPathname; 362 363 if (tag.src !== a.href + a.hash) { 364 tag.src = a.href + a.hash; 365 } 366 367 return tag; 368 369 } 370 371 // Add event handlers for events emitted by the YouTube API 372 function addYouTubeEvents(iframe) { 373 374 var player = YT.get(iframe.id); 375 if (!player) { 376 player = new YT.Player(iframe, {}); 377 } 378 379 if (typeof iframe.pauseFlag === 'undefined') { 380 381 iframe.pauseFlag = false; 382 player.addEventListener('onStateChange', function (evt) { 383 onYouTubePlayerStateChange(evt, iframe); 384 }); 385 386 } 387 388 } 389 390 function addDynYouTubeVideos(el) { 391 // We only bind to iFrames with a YouTube URL with the enablejsapi=1 and 392 // origin=<<hostname>> parameters 393 if (el.tagName === 'IFRAME' 394 && tagIsYouTubeVideo(el) 395 && isJSApiAttrEnabled(el.src) 396 && isOriginAttrEnabled(el.src)) 397 { 398 addYouTubeEvents(el); 399 } 400 } 401 402 // Event handler for events emitted from the YouTube API 403 function onYouTubePlayerStateChange(evt, iframe) { 404 405 var stateIndex = evt.data; 406 var player = evt.target; 407 var targetVideoUrl = player.getVideoUrl(); 408 var targetVideoId = targetVideoUrl.match(/[?&]v=([^&#]*)/)[1]; // Extract the ID 409 var playerState = player.getPlayerState(); 410 var marks = getVideoCompletionMarks(player.getDuration()); 411 412 iframe.playTracker = iframe.playTracker || {}; 413 414 if (playerState === YT.PlayerState.PLAYING && !iframe.timer) { 415 416 clearInterval(iframe.timer); 417 418 // check every second to see if we've hit any of our percentage viewed marks 419 iframe.timer = setInterval(function () { 420 checkYouTubeCompletion(player, marks, iframe.videoId); 421 }, 1000); 422 423 } else { 424 425 clearInterval(iframe.timer); 426 iframe.timer = false; 427 428 } 429 430 // playlist edge-case handler 431 if (stateIndex === YT.PlayerState.PLAYING) { 432 iframe.playTracker[targetVideoId] = true; 433 iframe.videoId = targetVideoId; 434 iframe.pauseFlag = false; 435 } 436 437 if (!iframe.playTracker[iframe.videoId]) { 438 return false; // this video hasn't started yet, so this is spam 439 } 440 441 if (stateIndex === YT.PlayerState.PAUSED) { 442 443 if (!iframe.pauseFlag) { 444 iframe.pauseFlag = true; 445 } else { 446 return false; // we don't want to fire consecutive pause events 447 } 448 449 } 450 451 } 452 453 // Trigger event if YouTube video mark was reached 454 function checkYouTubeCompletion(player, marks, videoId) { 455 456 var currentTime = player.getCurrentTime(); 457 458 player[videoId] = player[videoId] || {}; 459 460 for (var key in marks) { 461 462 if (marks[key] <= currentTime && !player[videoId][key]) { 463 player[videoId][key] = true; 464 465 var data = player.getVideoData(); 466 467 if (key === '0%') { 468 key = 'play'; 469 } 470 471 var params = { 472 video_type: 'youtube', 473 video_id: videoId, 474 video_title: data.title, 475 }; 476 477 let disable_watch_video = []; 478 479 //Custom 480 if ( options.triggerEventTypes.hasOwnProperty( "video_view" ) ) { 481 Object.entries( options.triggerEventTypes.video_view ).forEach( function ( [ trigger_id, triggers ] ) {
482 triggers.forEach( function ( trigger ) { 483 if ( trigger.type === 'youtube' && trigger.rule === videoId ) { 484 485 let pixels = Object.keys( options.triggerEvents[ trigger_id ] ); 486 for ( let i = 0; i < pixels.length; i++ ) { 487 let event = Utils.clone( options.triggerEvents[ trigger_id ][ pixels[ i ] ] ); 488 489 if ( trigger.disable_watch_video ) { 490 disable_watch_video.push( pixels[ i ] ); 491 } 492 493 if ( currentTime >= marks[ trigger.value ] ) { 494 event.params[ "progress" ] = key; 495 Utils.copyProperties( params, event.params ); 496 497 if ( event.fired !== true ) { 498 if ( Utils.isEventInTimeWindow( event.name, event, 'dyn_' + pixels[ i ] + '_' + trigger_id ) ) { 499 event = Utils.getFormFilledData( event ); 500 getPixelBySlag( pixels[ i ] ).fireEvent( event.name, event ); 501 options.triggerEvents[ trigger_id ][ pixels[ i ] ].fired = true; 502 } 503 } 504 } 505 } 506 } 507 } ) 508 } ) 509 } 510 511 // Auto 512 if( options.automatic.enable_video 513 && options.automatic.enable_youtube 514 && options.dynamicEvents.hasOwnProperty("automatic_event_video") 515 ) { 516 var pixels = Object.keys(options.dynamicEvents.automatic_event_video); 517 518 for (var i = 0; i < pixels.length; i++) { 519 if ( disable_watch_video.includes( pixels[ i ] ) ) { 520 continue; 521 } 522 var event = Utils.clone(options.dynamicEvents.automatic_event_video[pixels[i]]); 523 event.params["progress"] = key 524 Utils.copyProperties(params, event.params) 525 if ( pixels[i] === 'tiktok' ) { 526 var time_trigger = event.automatic_event_video_trigger; 527 if ( currentTime >= marks[time_trigger] && event.fired !== true ) { 528 getPixelBySlag(pixels[i]).onWatchVideo(event); 529 530 //tiktok watch video fire once 531 options.dynamicEvents.automatic_event_video[pixels[i]].fired = true; 532 } 533 } else { 534 Utils.copyProperties(Utils.getRequestParam
534s(), event.params); 535 getPixelBySlag(pixels[i]).onWatchVideo(event); 536 } 537 } 538 } 539 540 if(key == "play") { 541 542 $.each(options.triggerEventTypes, function (triggerType, events) { 543 $.each(events, function (eventId, triggers) { 544 switch (triggerType) { 545 case 'video_play': 546 Utils.fireTriggerEvent(eventId); 547 break; 548 } 549 550 }); 551 }); 552 } 553 554 } 555 556 } 557 558 } 559 560 // Determine if the element is a Vimeo video or not 561 function tagIsVimeoVideo(tag) { 562 var src = tag.src || ''; 563 return src.indexOf('player.vimeo.com/video/') > -1; 564 } 565 566 function tagIsAsincVimeoVideo(tag) { 567 if(tag.src) return false; // video is loaded 568 var keys = Object.keys(tag.dataset); 569 for(var i = 0;i<keys.length;i++) { 570 if(keys[i].toLowerCase().indexOf("src") > -1) { 571 var src = tag.dataset[keys[i]]; 572 return src.indexOf('player.vimeo.com/video/') > -1; 573 } 574 } 575 return false; //not find src 576 } 577 578 function attachVimeoPlayerToTag(tag) { 579 var player = new Vimeo.Player(tag); 580 581 player.getDuration().then(function (pl,seconds) { 582 pl.pysMarks = getVideoCompletionMarks(seconds); 583 }.bind(null,player)); 584 585 player.getVideoTitle().then(function (pl,title) { 586 pl.pysVideoTitle = title; 587 }.bind(null,player)); 588 589 player.getVideoId().then(function (pl,id) { 590 pl.pysVideoId = id; 591 }.bind(null,player)); 592 593 player.pysCompletedMarks = {}; 594 595 player.on('play', function () { 596 597 if (this.pysTimer) { 598 return; 599 } 600 601 clearInterval(this.pysTimer); 602 603 var player = this; 604 605 this.pysTimer = setInterval(function () { 606 checkVimeoCompletion(player); 607 }, 1000); 608 609 }); 610 611 player.on('pause', function () { 612 clearInterval(this.pysTimer); 613 this.pysTimer = false; 614 }); 615 616 player.on('ended', function () { 617 clearInterval(this.pysTimer); 618 this.pysTimer = false; 619 }); 620 } 621 622 // Trigger event if Vimeo video mark was reached 623 function checkVimeoCompletion(player) { 624 625 player.getCurrentTime().then(function (seconds) { 626 627 for (var key in player.pysMarks) { 628 629 if (player.pysMarks[key] <= seconds && !player.pysCompletedMarks[key]) { 630 631 player.pysCompletedMarks[key] = true; 632 633 if (key === '0%') { 634 key = 'play'; 635 } 636 637 var params = { 638 video_type: 'vimeo', 639 video_id: player.pysVideoId, 640 video_title: player.pysVideoTitle, 641 }; 642 643 let disable_watch_video = []; 644 645 //Custom 646 if ( options.triggerEventTypes.hasOwnProperty( "video_view" ) ) { 647 Object.entries( options.triggerEventTypes.video_view ).forEach( function ( [ trigger_id, triggers ] ) { 648 triggers.forEach( function ( trigger ) { 649 if ( trigger.type === 'vimeo' && trigger.rule == player.pysVideoId ) { 650 let pixels = Object.keys( options.triggerEvents[ trigger_id ] ); 651 for ( let i = 0; i < pixels.length; i++ ) { 652 let event = Utils.clone( options.triggerEvents[ trigger_id ][ pixels[ i ] ] ); 653 654 if ( trigger.disable_watch_video ) { 655 disable_watch_video.push( pixels[ i ] ); 656 } 657 658 if ( seconds >= player.pysMarks[ trigger.value ] ) { 659 event.params[ "progress" ]
659= key; 660 Utils.copyProperties( params, event.params ); 661 662 if ( event.fired !== true ) { 663 if ( Utils.isEventInTimeWindow( event.name, event, 'dyn_' + pixels[ i ] + '_' + trigger_id ) ) { 664 event = Utils.getFormFilledData( event ); 665 getPixelBySlag( pixels[ i ] ).fireEvent( event.name, event ); 666 options.triggerEvents[ trigger_id ][ pixels[ i ] ].fired = true; 667 } 668 } 669 } 670 } 671 } 672 } ) 673 } ) 674 } 675 676 // Auto 677 if(options.automatic.enable_video 678 && options.automatic.enable_vimeo 679 && options.dynamicEvents.hasOwnProperty("automatic_event_video") 680 ) { 681 var pixels = Object.keys(options.dynamicEvents.automatic_event_video); 682 683 for (var i = 0; i < pixels.length; i++) { 684 if ( disable_watch_video.includes( pixels[ i ] ) ) { 685 continue; 686 } 687 688 var event = Utils.clone(options.dynamicEvents.automatic_event_video[pixels[i]]); 689 event.params["progress"] = key 690 Utils.copyProperties(params, event.params); 691 692 if ( pixels[i] === 'tiktok' ) { 693 var time_trigger = event.automatic_event_video_trigger; 694 if ( seconds >= player.pysMarks[time_trigger] && event.fired !== true ) { 695 getPixelBySlag(pixels[i]).onWatchVideo(event); 696 697 //tiktok watch video fire once 698 options.dynamicEvents.automatic_event_video[pixels[i]].fired = true; 699 } 700 } else { 701 Utils.copyProperties(Utils.getRequestParam
701s(), event.params); 702 getPixelBySlag(pixels[i]).onWatchVideo(event); 703 } 704 } 705 } 706 707 if(key == "play") { 708 $.each(options.triggerEventTypes, function (triggerType, events) { 709 $.each(events, function (eventId, triggers) { 710 switch (triggerType) { 711 case 'video_play': 712 Utils.fireTriggerEvent(eventId); 713 break; 714 } 715 716 }); 717 }); 718 } 719 } 720 721 } 722 723 }); 724 725 } 726 727 /** 728 * COOKIES UTILS 729 */ 730 731 var utmTerms = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content' ,'utm_term']; 732 var utmId = ['fbadid', 'gadid', 'padid', 'bingid']; 733 var requestParams = []; 734 735 736 function getDomain(url) { 737 738 url = url.replace(/(https?:\/\/)?(www.)?/i, ''); 739 740 if (url.indexOf('/') !== -1) { 741 return url.split('/')[0]; 742 } 743 744 return url; 745 } 746 747 function checkSession() { 748 749 if( Cookies.get('pys_start_session') === undefined || 750 Cookies.get('pys_session_limit') === undefined) { 751 firstVisit = true; 752 return true 753 } 754 return false 755 756 } 757 758 function getTrafficSource() { 759 760 try { 761 762 let referrer = document.referrer.toString(), 763 source; 764 765 let direct = referrer.length === 0; 766 let internal = direct ? false : referrer.indexOf(options.siteUrl) === 0; 767 let external = !direct && !internal; 768 769 if (external === false) { 770 source = 'direct'; 771 } else { 772 source = referrer; 773 } 774 775 if (source !== 'direct') { 776 // leave only domain (Issue #70) 777 return getDomain(source); 778 } else { 779 return source; 780 } 781 782 } catch (e) { 783 console.error(e); 784 return 'direct'; 785 } 786 787 } 788 789 /** 790 * Return query variables object with where property name is query variable 791 * and property value is query variable value. 792 */ 793 function getQueryVars() { 794 795 try { 796 797 var result = {}, 798 tmp = []; 799 800 window.location.search 801 .substr(1) 802 .split("&") 803 .forEach(function (item) { 804 805 tmp = item.split('='); 806 807 if (tmp.length > 1) { 808 result[tmp[0]] = tmp[1]; 809 } 810 811 }); 812 813 return result; 814 815 } catch (e) { 816 console.error(e); 817 return {}; 818 } 819 820 } 821 822 function getLandingPageValue() { 823 let name = "pys_landing_page" 824 if(options.visit_data_model === "last_visit") { 825 name = "last_pys_landing_page" 826 } 827 if(Cookies.get(name) && Cookies.get(name) !== "undefined") { 828 return Cookies.get(name); 829 } 830 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficLanding){ 831 return options.tracking_analytics.TrafficLanding; 832 } else{ 833 return ""; 834 } 835 } 836 function getTrafficSourceValue() { 837 let name = "pysTrafficSource" 838 if(options.visit_data_model === "last_visit") { 839 name = "last_pysTrafficSource" 840 } 841 if(Cookies.get(name) && Cookies.get(name) !== "undefined") { 842 return Cookies.get(name); 843 } 844 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficSource){ 845 return options.tracking_analytics.TrafficSource; 846 } else{ 847 return ""; 848 } 849 } 850 851 function getUTMId(useLast = false) { 852 try { 853 let cookiePrefix = 'pys_' 854 let terms = []; 855 if (useLast) { 856 cookiePrefix = 'last_pys_' 857 } 858 $.each(utmId, function (index, name) { 859 if (Cookies.get(cookiePrefix + name)) { 860 terms[name] = Cookies.get(cookiePrefix + name) 861 } 862 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficUtmsId[name]) { 863 terms[name] = filterEmails(options.tracking_analytics.TrafficUtmsId[name]) 864 } 865 }); 866 return terms; 867 } catch (e) { 868 console.error(e); 869 return []; 870 } 871 } 872 /** 873 * Return UTM terms from request query variables or from cookies. 874 */ 875 function getUTMs(useLast = false) { 876 877 try { 878 let cookiePrefix = 'pys_' 879 if(useLast) { 880 cookiePrefix = 'last_pys_' 881 } 882 let terms = []; 883 $.each(utmTerms, function (index, name) { 884 if (Cookies.get(cookiePrefix + name)) { 885 let value = Cookies.get(cookiePrefix + name); 886 terms[name] = filterEmails(value); // do not allow email in request params (Issue #70) 887 } 888 else if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.TrafficUtms[name]) { 889 terms[name] = filterEmails(options.tracking_analytics.TrafficUtms[name]) 890 } 891 }); 892 893 return terms; 894 895 } catch (e) { 896 console.error(e); 897 return []; 898 } 899 900 } 901 902 function getDateTime() { 903 var dateTime = new Array(); 904 var date = new Date(), 905 days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], 906 months = ['January', 'February', 'March', 'April', 'May', 'June', 907 'July', 'August', 'September', 'October', 'November', 'December' 908 ], 909 hours = ['00-01', '01-02', '02-03', '03-04', '04-05', '05-06', '06-07', '07-08', 910 '08-09', '09-10', '10-11', '11-12', '12-13', '13-14', '14-15', '15-16', '16-17', 911 '17-18', '18-19', '19-20', '20-21', '21-22', '22-23', '23-24' 912 ]; 913 dateTime.push(hours[date.getHours()]); 914 dateTime.push(days[date.getDay()]); 915 dateTime.push(months[date.getMonth()]); 916 return dateTime; 917 } 918 919 function filterEmails(value) { 920 return Utils.validateEmail(value) ? undefined : value; 921 } 922 923 /** 924 * PUBLIC API 925 */ 926 return { 927 928 PRODUCT_SIMPLE : 0, 929 PRODUCT_VARIABLE : 1, 930 PRODUCT_BUNDLE : 2, 931 PRODUCT_GROUPED : 3, 932 utmTerms : utmTerms, 933 utmId : utmId, 934 isNewSession: checkSession(), 935 setHidePixelCookie: function(){ 936 let refresh_after_consent = false; 937 if ( !firstVisit && options.gdpr.consent_magic_integration_enabled && window.CS_Data !== undefined && window.CS_Data.cs_refresh_after_consent) { 938 refresh_after_consent = true; 939 } 940 if( !refresh_after_consent && !firstVisit) return false; 941 942 const url_parts = window.location.href; 943 const url_params = new URLSearchParams(window.location.search); 944 const matchingPixels = ["facebook", "ga", "gtm", "google_ads", "bing", "pinterest", "tiktok"]; 945 $.each(matchingPixels, function (slug){ 946 var module = getPixelBySlag(slug); 947 if(module && module.isEnabled()){ 948 $.each(module.getHidePixel(), function (index, hide_info) { 949 for (const item of hide_info.hide_tag_contain) { 950 if (item) { 951 let hideTagTimeInHours = hide_info.hide_tag_time; 952 let hideTagTimeInMilliseconds = hideTagTimeInHours * 60 * 60 * 1000; 953 let currentTimeInMilliseconds = new Date().getTime(); 954 let expiresTimeInMilliseconds = currentTimeInMilliseconds + hideTagTimeInMilliseconds; 955 const itemValue = item.split('=');
956 const key = itemValue[0]; 957 const value = itemValue[1]; 958 959 if (value !== undefined) { 960 if (url_params.get(key) === value) { 961 Cookies.set('hide_tag_'+hide_info.pixel, true, { expires: new Date(expiresTimeInMilliseconds), path: '/' }); 962 break; 963 } 964 } else if (url_params.get(key) !== null) { 965 Cookies.set('hide_tag_'+hide_info.pixel, true, { expires: new Date(expiresTimeInMilliseconds), path: '/' }); 966 break; 967 } 968 } 969 } 970 }); 971 } 972 973 }); 974 }, 975 hideMatchingPixel: function(pixelValue, slug) { 976 if(Cookies.get('hide_tag_'+pixelValue)) 977 { 978 return true; 979 } 980 return false; 981 }, 982 validateEmail: function (email) { 983 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,}))$/; 984 return re.test(email); 985 }, 986 fireEventForAllPixel:function(functionName,events){ 987 if (events.hasOwnProperty(Facebook.tag())) 988 Facebook[functionName](events[Facebook.tag()]); 989 if (events.hasOwnProperty(Analytics.tag())) 990 Analytics[functionName](events[Analytics.tag()]); 991 if (events.hasOwnProperty(GAds.tag())) 992 GAds[functionName](events[GAds.tag()]); 993 if (events.hasOwnProperty(Pinterest.tag())) 994 Pinterest[functionName](events[Pinterest.tag()]); 995 if (events.hasOwnProperty(Bing.tag())) 996 Bing[functionName](events[Bing.tag()]); 997 if (events.hasOwnProperty(TikTok.tag())) 998 TikTok[functionName](events[TikTok.tag()]); 999 1000 if (events.hasOwnProperty(GTM.tag())) 1001 GTM[functionName](events[GTM.tag()]); 1002 }, 1003 1004 getQueryValue:function (name){ 1005 return getQueryVars()[name]; 1006 }, 1007 1008 filterEmails: function (value) { 1009 return filterEmails(value); 1010 }, 1011 1012 setupPinterestObject: function () { 1013 Pinterest = window.pys.Pinterest || Pinterest; 1014 return Pinterest; 1015 }, 1016 1017 setupBingObject: function () { 1018 Bing = window.pys.Bing || Bing; 1019 return Bing; 1020 }, 1021 1022 // Clone all object members to another and return it 1023 copyProperties: function (from, to) { 1024 for (var key in from) { 1025 if("function" == typeof from[key]) { 1026 continue; 1027 } 1028 to[key] = from[key]; 1029 } 1030 return to; 1031 }, 1032 1033 /** 1034 * Generate unique ID 1035 */ 1036 generateUniqueId : function (event) { 1037 if(event.eventID.length == 0 || (event.type == "static" && options.ajaxForServerStaticEvent) || (event.type !== "static" && options.ajaxForServerEvent)) { 1038 let idKey = event.hasOwnProperty('custom_event_post_id') ? event.custom_event_post_id : event.e_id; 1039 if (!uniqueId.hasOwnProperty(idKey)) { 1040 uniqueId[idKey] = pys_generate_token(); 1041 } 1042 return uniqueId[idKey]; 1043 } 1044 else if(event.eventID.length !== 0) 1045 { 1046 return event.eventID; 1047 } 1048 }, 1049 1050 sendServerAjaxRequest: function ( url, data ) { 1051 jQuery.ajax( { 1052 type: 'POST', 1053 url: url, 1054 data: data, 1055 headers: { 1056 'Cache-Control': 'no-cache' 1057 }, 1058 success: function () { 1059 }, 1060 } ); 1061 }, 1062 1063 clone: function(obj) { 1064 var copy; 1065 1066 // Handle the 3 simple types, and null or undefined 1067 if (null == obj || "object" != typeof obj) return obj;
1068 1069 // Handle Date 1070 if (obj instanceof Date) { 1071 copy = new Date(); 1072 copy.setTime(obj.getTime()); 1073 return copy; 1074 } 1075 1076 // Handle Array 1077 if (obj instanceof Array) { 1078 copy = []; 1079 for (var i = 0, len = obj.length; i < len; i++) { 1080 if("function" == typeof obj[i]) { 1081 continue; 1082 } 1083 copy[i] = Utils.clone(obj[i]); 1084 } 1085 return copy; 1086 } 1087 1088 // Handle Object 1089 if (obj instanceof Object) { 1090 copy = {}; 1091 for (var attr in obj) { 1092 if (obj.hasOwnProperty(attr)) { 1093 if("function" == typeof obj[attr]) { 1094 continue; 1095 } 1096 copy[attr] = Utils.clone(obj[attr]); 1097 } 1098 } 1099 return copy; 1100 } 1101 1102 return obj; 1103 }, 1104 1105 // Returns array of elements with given tag name 1106 getTagsAsArray: function (tag) { 1107 return [].slice.call(document.getElementsByTagName(tag)); 1108 }, 1109 1110 1111 initializeVideoAPIs: function (options) { 1112 let trigger_has_video_YT, trigger_has_video_Vimeo = false; 1113 if (options.hasOwnProperty('automatic') && options.automatic.enable_video) { 1114 if ( options.triggerEventTypes.hasOwnProperty( "video_view" ) ) { 1115 Object.entries( options.triggerEventTypes.video_view ).forEach( function ( [ trigger_id, triggers ] ) { 1116 triggers.forEach( function ( trigger ) { 1117 if (trigger.type === 'youtube') { 1118 trigger_has_video_YT = true; 1119 } 1120 if(trigger.type === 'vimeo'){ 1121 trigger_has_video_Vimeo = true; 1122 } 1123 }); 1124 }); 1125 } 1126 if(options.automatic.enable_youtube || trigger_has_video_YT){ 1127 Utils.initYouTubeAPI(); 1128 } 1129 if(options.automatic.enable_vimeo || trigger_has_video_Vimeo){ 1130 Utils.initVimeoAPI(); 1131 } 1132 } 1133 }, 1134 /** 1135 * Load and initialize YouTube API 1136 * 1137 * @link: https://developers.google.com/youtube/iframe_api_reference 1138 */ 1139 initYouTubeAPI: function () { 1140 1141 // maybe load YouTube JS API 1142 if (typeof window.YT === 'undefined') { 1143 var tag = document.createElement('script'); 1144 tag.src = '//www.youtube.com/iframe_api'; 1145 var firstScriptTag = document.getElementsByTagName('script')[0]; 1146 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 1147 } 1148 1149 // initialize when API is ready 1150 if ( typeof window.onYouTubeIframeAPIReady !== 'function' ) { 1151 1152 window.onYouTubeIframeAPIReady = function () { 1153 1154 // collect all possible YouTube tags 1155 var potentialVideos = Utils.getTagsAsArray( 'iframe' ).concat(
1155Utils.getTagsAsArray( 'embed' ) ); 1156 1157 // turn videos into trackable videos with events 1158 for ( var i = 0; i < potentialVideos.length; i++ ) { 1159 var video = potentialVideos[ i ]; 1160 if ( tagIsYouTubeVideo( video ) ) { 1161 var iframe = normalizeYouTubeIframe( video ); 1162 addYouTubeEvents( iframe ); 1163 } else if ( tagIsYouTubeAsyncVideo( video ) ){ 1164 video.addEventListener( "load", function ( evt ) { 1165 var iframe = normalizeYouTubeIframe( evt.currentTarget ); 1166 addYouTubeEvents( iframe ); 1167 } ); 1168 } 1169 } 1170 1171 var targets = document.querySelectorAll( '.elementor-widget-video .elementor-wrapper' ); 1172 1173 const config = { 1174 attributes: false, 1175 childList: true, 1176 subtree: true 1177 }; 1178 1179 const callback = function ( mutationsList, observer ) { 1180 for ( let mutation of mutationsList ) { 1181 if ( mutation.type === 'childList' ) { 1182 for ( var m = 0; m < mutation.addedNodes.length; m++ ) { 1183 addDynYouTubeVideos( mutation.addedNodes[ m ] ); 1184 } 1185 } 1186 } 1187 }; 1188 // observe elementator widget-video and add event when it add iframe 1189 for ( var i = 0; i < targets.length; i++ ) { 1190 const observer = new MutationObserver( callback ); 1191 observer.observe( targets[ i ], config );//maybe remove before add 1192 } 1193 } 1194 } 1195 }, 1196 1197 /** 1198 * Load and initialize Vimeo API 1199 * 1200 * @link: https://github.com/vimeo/player.js 1201 */ 1202 initVimeoAPI: function () { 1203 1204 1205 $(document).ready(function () { 1206 1207 var potentialVideos = Utils.getTagsAsArray('iframe').concat(Utils.getTagsAsArray('embed')); 1208 1209 for (var i = 0; i < potentialVideos.length; i++) { 1210 var tag = potentialVideos[i]; 1211 if (tagIsVimeoVideo(tag)) { 1212 var nextElementHasClass = $(tag).closest('.elementor-widget-video').find('.elementor-custom-embed-image-overlay'); 1213 if(nextElementHasClass.length > 0) { 1214 tag.addEventListener("load", function() { 1215 attachVimeoPlayerToTag(this); 1216 }); 1217 } 1218 else { 1219 attachVimeoPlayerToTag(tag); 1220 } 1221 1222 1223 } else { 1224 if (tagIsAsincVimeoVideo(tag)) { 1225 tag.addEventListener("load", function(evt) { 1226 attachVimeoPlayerToTag(evt.currentTarget); 1227 }); 1228 } 1229 } 1230 } 1231 1232 }); 1233 1234 }, 1235 1236 manageCookies: function () { 1237 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 1238 if (Cookiebot.consented === false && !Cookiebot.consent['marketing'] && !Cookiebot.consent['statistics']) { 1239 return; 1240 } 1241 } 1242 1243 let cm_consent_not_expressed = false; 1244 if ( options.gdpr.consent_magic_integration_enabled && window.CS_Data !== undefined && window.CS_Data.cs_refresh_after_consent == 1 ) { 1245 if ( Cookies.get( 'cs_viewed_cookie_policy' ) === undefined ) { 1246 cm_consent_not_expressed = true; 1247 } 1248 } 1249 1250 if( !cm_consent_not_expressed && isNewSession && !options.cookie.disabled_all_cookie && !options.cookie.disabled_start_session_cookie) { 1251 let duration = options.last_visit_duration * 60000 1252 var now = new Date(); 1253 now.setTime(now.getTime() + duration); 1254 Cookies.set('pys_session_limit', true,{ expires: now, path: '/',domain: domain }) 1255 Cookies.set('pys_start_session', true,{ path: '/',domain: domain }); 1256 Utils.setHidePixelCookie(); 1257 } 1258 if (options.gdpr.ajax_enabled && !options.gdpr.consent_magic_integration_enabled) { 1259 1260 // retrieves actual PYS GDPR filters values which allow to avoid cache issues 1261 $.get({ 1262 url: options.ajaxUrl, 1263 dataType: 'json', 1264 data: { 1265 action: 'pys_get_gdpr_filters_values' 1266 }, 1267 success: function (res) { 1268 1269 if (res.success) { 1270 1271 options.gdpr.all_disabled_by_api = res.data.all_disabled_by_api; 1272 options.gdpr.facebook_disabled_by_api = res.data.facebook_disabled_by_api; 1273 options.gdpr.tiktok_disabled_by_api = res.data.tiktok_disabled_by_api; 1274 options.gdpr.analytics_disabled_by_api = res.data.analytics_disabled_by_api; 1275 options.gdpr.google_ads_disabled_by_api = res.data.google_ads_disabled_by_api; 1276 options.gdpr.pinterest_disabled_by_api = res.data.pinterest_disabled_by_api; 1277 options.gdpr.bing_disabled_by_api = res.data.bing_disabled_by_api; 1278 1279 options.cookie.externalID_disabled_by_api = res.data.externalID_disabled_by_api; 1280 options.cookie.disabled_all_cookie = res.data.disabled_all_cookie; 1281 options.cookie.disabled_advanced_form_data_cookie = res.data.disabled_advanced_form_data_cookie; 1282 options.cookie.disabled_landing_page_cookie = res.data.disabled_landing_page_cookie; 1283 options.cookie.disabled_first_visit_cookie = res.data.disabled_first_visit_cookie; 1284 options.cookie.disabled_trafficsource_cookie = res.data.disabled_trafficsource_cookie; 1285 options.cookie.disabled_utmTerms_cookie = res.data.disabled_utmTerms_cookie; 1286 options.cookie.disabled_utmId_cookie = res.data.disabled_utmId_cookie; 1287 1288 } 1289 } 1290 }); 1291 } 1292 if (!Cookies.get('pbid') && Facebook.isEnabled() && options.ajaxForServerEvent) { 1293 jQuery.ajax({ 1294 url: options.ajaxUrl, 1295 dataType: 'json', 1296 data: { 1297 action: 'pys_get_pbid' 1298 }, 1299 success: function (res) { 1300 if (res.data && res.data.pbid != false && options.send_external_id) { 1301 if(!(options.cookie.disabled_all_cookie || options.cookie.externalID_disabled_by_api)){ 1302 var expires = parseInt(options.external_id_expire || 180); 1303 Cookies.set('pbid', res.data.pbid, { expires: expires,path: '/',domain: domain }); 1304 } 1305 1306 if(options.hasOwnProperty('facebook')) { 1307 options.facebook.advancedMatching = { 1308 ...options.facebook.advancedMatching, // ÑаÑпÑлÑем ÑекÑÑие знаÑÐµÐ½Ð¸Ñ advancedMatching 1309 external_id: res.data.pbid 1310 }; 1311 } 1312 } 1313 } 1314 }); 1315 } else if (Cookies.get('pbid') && Facebook.isEnabled()){ 1316 if(options.hasOwnProperty('facebook')) { 1317 options.facebook.advancedMatching = { 1318 ...options.facebook.advancedMatching, 1319 external_id: Cookies.get('pbid') 1320 }; 1321 } 1322 } 1323 let expires = parseInt(options.cookie_duration); // days 1324 let queryVars = getQueryVars(); 1325 let landing = window.location.href.split('?')[0]; 1326 try { 1327 // save data for first visit 1328 if(Cookies.get('pys_first_visit') === undefined && (!options.cookie.disabled_all_cookie)) { 1329 1330 if(!options.cookie.disabled_first_visit_cookie) 1331 { 1332 Cookies.set('pys_first_visit', true, { expires: expires, path: '/',domain: domain }); 1333 } 1334 else { 1335 Cookies.remove('pys_first_visit') 1336 } 1337 1338 if(!options.cookie.disabled_trafficsource_cookie) 1339 { 1340 Cookies.set('pysTrafficSource', getTrafficSource(), { expires: expires,path: '/',domain: domain }); 1341 } 1342 else { 1343 Cookies.remove('pysTrafficSource') 1344 } 1345 1346 if(!options.cookie.disabled_landing_page_cookie) 1347 { 1348 Cookies.set('pys_landing_page',landing,{ expires: expires,path: '/',domain: domain }); 1349 } 1350 else { 1351 Cookies.remove('pys_landing_page') 1352 } 1353 1354 if(!options.cookie.disabled_utmTerms_cookie) 1355 { 1356 $.each(utmTerms, function (index, name) { 1357 if (queryVars.hasOwnProperty(name)) { 1358 Cookies.set('pys_' + name, queryVars[name], { expires: expires,path: '/',domain: domain }); 1359 } else { 1360 Cookies.remove('pys_' + name) 1361 } 1362 }); 1363 } 1364 else { 1365 $.each(utmTerms, function (index, name) { 1366 Cookies.remove('pys_' + name) 1367 }); 1368 } 1369 1370 if(!options.cookie.disabled_utmId_cookie) 1371 { 1372 $.each(utmId,function(index,name) { 1373 if (queryVars.hasOwnProperty(name)) { 1374 Cookies.set('pys_' + name, queryVars[name], { expires: expires,path: '/',domain: domain }); 1375 } else { 1376 Cookies.remove('pys_' + name) 1377 } 1378 }) 1379 } 1380 else { 1381 $.each(utmId, function (index, name) { 1382 Cookies.remove('pys_' + name) 1383 }); 1384 } 1385 1386 } 1387 1388 // save data for last visit if it new session 1389 if(isNewSession && (!options.cookie.disabled_all_cookie)) { 1390 if(!options.cookie.disabled_trafficsource_cookie) 1391 { 1392 Cookies.set('last_pysTrafficSource', getTrafficSource(), { expires: expires,path: '/',domain: domain }); 1393 } 1394 else { 1395 Cookies.remove('last_pysTrafficSource') 1396 } 1397 1398 if(!options.cookie.disabled_landing_page_cookie) 1399 { 1400 Cookies.set('last_pys_landing_page',landing,{ expires: expires,path: '/',domain: domain }); 1401 } 1402 else { 1403 Cookies.remove('last_pys_landing_page') 1404 } 1405 1406 if(!options.cookie.disabled_utmTerms_cookie) 1407 { 1408 $.each(utmTerms, function (index, name) { 1409 if (queryVars.hasOwnProperty(name)) { 1410 Cookies.set('last_pys_' + name, queryVars[name], { expires: expires,path: '/',domain: domain }); 1411 } else { 1412 Cookies.remove('last_pys_' + name) 1413 } 1414 }); 1415 } 1416 else { 1417 $.each(utmTerms, function (index, name) { 1418 Cookies.remove('last_pys_' + name) 1419 }); 1420 } 1421 1422 if(!options.cookie.disabled_utmId_cookie) 1423 { 1424 $.each(utmId,function(index,name) { 1425 if (queryVars.hasOwnProperty(name)) { 1426 Cookies.set('last_pys_' + name, queryVars[name], { expires: expires,path: '/',domain: domain }); 1427 } else { 1428 Cookies.remove('last_pys_' + name) 1429 } 1430 }) 1431 } 1432 else { 1433 $.each(utmId, function (index, name) { 1434 Cookies.remove('last_pys_' + name) 1435 }); 1436 } 1437 1438 } 1439 if(options.cookie.disabled_start_session_cookie) { 1440 Cookies.remove('pys_start_session') 1441 Cookies.remove('pys_session_limit') 1442 } 1443 if(options.cookie.disabled_all_cookie) 1444 { 1445 Cookies.remove('pys_first_visit') 1446 Cookies.remove('pysTrafficSource') 1447 Cookies.remove('pys_landing_page') 1448 Cookies.remove('last_pys_landing_page') 1449 Cookies.remove('last_pysTrafficSource') 1450 Cookies.remove('pys_start_session') 1451 Cookies.remove('pys_session_limit') 1452 $.each(Utils.utmTerms, function (index, name) { 1453 Cookies.remove('pys_' + name) 1454 }); 1455 $.each(Utils.utmId,function(index,name) { 1456 Cookies.remove('pys_' + name) 1457 }) 1458 $.each(Utils.utmTerms, function (index, name) { 1459 Cookies.remove('last_pys_' + name) 1460 }); 1461 $.each(Utils.utmId,function(index,name) { 1462 Cookies.remove('last_pys_' + name) 1463 }); 1464 } 1465 } catch (e) { 1466 console.error(e); 1467 } 1468 }, 1469
1470 initializeRequestParams: function () { 1471 1472 if (options.trackTrafficSource) { 1473 requestParams.traffic_source = getTrafficSourceValue(); 1474 } 1475 1476 if (options.trackUTMs) { 1477 1478 var utms = getUTMs(options.visit_data_model === "last_visit"); 1479 1480 $.each(utmTerms, function (index, term) { 1481 if (term in utms) { 1482 requestParams[term] = utms[term]; 1483 } 1484 }); 1485 1486 } 1487 1488 1489 var dateTime = getDateTime(); 1490 if(options.enable_event_time_param) { 1491 requestParams.event_hour = dateTime[0]; 1492 } 1493 1494 if(options.enable_event_day_param) { 1495 requestParams.event_day = dateTime[1]; 1496 } 1497 if(options.enable_event_month_param) { 1498 requestParams.event_month = dateTime[2]; 1499 } 1500 1501 if(options.enable_lading_page_param){ 1502 requestParams.landing_page = getLandingPageValue(); 1503 } 1504 }, 1505
1506 getRequestParams: function () { 1507 return requestParams; 1508 }, 1509 1510 /** 1511 * DOWNLOAD DOCS 1512 */ 1513 1514 getLinkExtension: function (link) { 1515 1516 // Remove anchor, query string and everything before last slash 1517 link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); 1518 link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); 1519 link = link.substring(link.lastIndexOf("/") + 1, link.length); 1520 1521 // If there's a period left in the URL, then there's a extension 1522 if (link.length > 0 && link.indexOf('.') !== -1) { 1523 link = link.substring(link.lastIndexOf(".") + 1); // Remove everything but what's after the first period 1524 return link; 1525 } else { 1526 return ""; 1527 } 1528 }, 1529 1530 getLinkFilename: function (link) { 1531 1532 // Remove anchor, query string and everything before last slash 1533 link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#")); 1534 link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?")); 1535 link = link.substring(link.lastIndexOf("/") + 1, link.length); 1536 1537 // If there's a period left in the URL, then there's a extension 1538 if (link.length > 0 && link.indexOf('.') !== -1) { 1539 return link; 1540 } else { 1541 return ""; 1542 } 1543 }, 1544 1545 /** 1546 * CUSTOM EVENTS 1547 */ 1548 1549 setupMouseOverClickEvents: function (eventId, triggers) { 1550 1551 // Non-default binding used to avoid situations when some code in external js 1552 // stopping events propagation, eg. returns false, and our handler will never called 1553 document.addEventListener('mouseover', function(event) { 1554 var matchedElements = Array.from(document.querySelectorAll(triggers)); 1555 var clickedElement = event.target; 1556 var closestMatch = clickedElement.closest(triggers); 1557 if (matchedElements.includes(clickedElement) || closestMatch){ 1558 if (event.target.classList.contains('pys-mouse-over-' + eventId)) { 1559 return true; 1560 } else { 1561 event.target.classList.add('pys-mouse-over-' + eventId); 1562 } 1563 1564 Utils.fireTriggerEvent(eventId); 1565 } 1566 }); 1567 1568 1569 }, 1570 1571 setupCSSClickEvents: function (eventId, triggers) { 1572 // Non-default binding used to avoid situations when some code in external js 1573 // stopping events propagation, eg. returns false, and our handler will never called 1574 // add event to document to support dyn class 1575 document.addEventListener('click', function(event) { 1576 let matchedElements = Array.from(document.querySelectorAll(triggers)), 1577 clickedElement = event.target, 1578 closestMatch = clickedElement.closest(triggers); 1579 1580 if (matchedElements.includes(clickedElement) || closestMatch){ 1581 Utils.fireTriggerEvent(eventId); 1582 } 1583 }, true); 1584 }, 1585 1586 setupURLClickEvents: function () { 1587 1588 if( !options.triggerEventTypes.hasOwnProperty('url_click') ) { 1589 return; 1590 } 1591 // Non-default binding used to avoid situations when some code in external js 1592 // stopping events propagation, eg. returns false, and our handler will never called 1593 document.addEventListener('click', function(event) { 1594 let anchor = event.target.closest('a'); 1595 1596 if (anchor) { 1597 var url = anchor.getAttribute('href'); 1598 if (url) { 1599 Object.entries(options.triggerEventTypes.url_click).forEac
1599h(function ([eventId, triggers]) { 1600 triggers.forEach(function (trigger) { 1601 if (Utils.compareUrl(url, trigger.value, trigger.rule)) { 1602 Utils.fireTriggerEvent(eventId); 1603 } 1604 }); 1605 }); 1606 } 1607 } 1608 }, true); 1609 1610 }, 1611 1612 removeUrlDomain(url) { 1613 if(url.indexOf("/#") > -1) { 1614 url = url.substring(0, url.indexOf("/#")); 1615 } 1616 return url.replace('http://','') 1617 .replace('https://','') 1618 .replace('www.','') 1619 .trim() 1620 .replace(/^\/+/g, '') 1621 1622 }, 1623 1624 compareUrl: function(base,url,rule){ 1625 1626 if(url == "*" || url == '') return true; 1627 1628 base = Utils.removeUrlDomain(base) 1629 url = Utils.removeUrlDomain(url) 1630 1631 if(rule == 'match') { 1632 return url == base; 1633 } else { 1634 return base.indexOf(url) !== -1 1635 } 1636 1637 }, 1638 1639 setupScrollPosEvents: function (eventId, triggers) { 1640 1641 var scrollPosThresholds = {}, 1642 docHeight = $(document).height() - $(window).height(); 1643 1644 // convert % to absolute positions 1645 $.each(triggers, function (index, scrollPos) { 1646 1647 // convert % to pixels 1648 scrollPos = docHeight * scrollPos / 100; 1649 scrollPos = Math.round(scrollPos); 1650 1651 scrollPosThresholds[scrollPos] = eventId; 1652 1653 }); 1654 1655 $(document).on("scroll",function () { 1656 1657 var scrollPos = $(window).scrollTop(); 1658 1659 $.each(scrollPosThresholds, function (threshold, eventId) { 1660 1661 // position has not reached yes 1662 if (scrollPos <= threshold) { 1663 return true; 1664 } 1665 1666 // fire event only once 1667 if (eventId === null) { 1668 return true; 1669 } else { 1670 scrollPosThresholds[threshold] = null; 1671 } 1672 1673 Utils.fireTriggerEvent(eventId); 1674 1675 }); 1676 1677 }); 1678 1679 }, 1680 setupCommentEvents : function (eventId,triggers) { 1681 $('form.comment-form').on("submit",function () { 1682 Utils.fireTriggerEvent(eventId); 1683 }); 1684 }, 1685 1686 setupEmailLinkEvents: function ( events ) { 1687 1688 $( document ).on( 'click', 'a', function ( event ) { 1689 let anchor = event.target.closest('a'); 1690 1691 if (anchor) { 1692 let url = anchor.getAttribute('href'); 1693 if (url && (url.startsWith('mailto:') || url.startsWith('tel:'))) { 1694 1695 let sendEventIds = [], 1696 disabled_for_pixels = [], 1697 disabled_email_action = false; 1698 1699 $.each(events, function (eventId, trigger_group) { 1700 url = url.replace('mailto:', '').replace('tel:', ''); 1701 trigger_group.forEach(function (triggers) {
1702 triggers.rules.forEach(function (trigger) { 1703 if (Utils.compareUrl(url, trigger.value, trigger.rule)) { 1704 sendEventIds.push(eventId); 1705 if (triggers.hasOwnProperty('disabled_email_link') && triggers.disabled_email_link) { 1706 disabled_email_action = true; 1707 if (options.triggerEvents.hasOwnProperty(eventId)) { 1708 disabled_for_pixels.push(...Object.keys(options.triggerEvents[eventId])); 1709 } 1710 } 1711 } 1712 }); 1713 }) 1714 }) 1715 1716 if (sendEventIds.length > 0) { 1717 sendEventIds.forEach(function (sendEventId) { 1718 Utils.fireTriggerEvent(sendEventId); 1719 }) 1720 } 1721 setupEmailLinks(disabled_for_pixels); 1722 } 1723 } 1724 } ) 1725 }, 1726 1727 /** 1728 * Events 1729 */ 1730 1731 isEventInTimeWindow: function (eventName, event, prefix) { 1732 1733 if(event.hasOwnProperty("hasTimeWindow") && event.hasTimeWindow) { 1734 var cookieName = prefix+"_"+eventName; 1735 var now = new Date().getTime(); 1736 1737 if(Cookies.get(cookieName) !== undefined) { 1738 1739 var lastTimeFire = Cookies.get(cookieName); 1740 var fireTime = event.timeWindow * 60*60*1000; 1741 1742 if( now - lastTimeFire > fireTime) { 1743 Cookies.set(cookieName,now, { expires: event.timeWindow / 24.0, path: '/'} ); 1744 } else { 1745 return false; 1746 } 1747 } else { 1748 Cookies.set(cookieName,now, { expires: event.timeWindow / 24.0, path: '/'} ); 1749 } 1750 } 1751 return true 1752 }, 1753 1754 fireTriggerEvent: function (eventId) { 1755 1756 if (!options.triggerEvents.hasOwnProperty(eventId)) { 1757 return; 1758 } 1759 1760 var event = {}; 1761 var events = options.triggerEvents[eventId]; 1762 1763 if (events.hasOwnProperty('facebook')) { 1764 event = events.facebook; 1765 if(Utils.isEventInTimeWindow(event.name,event,"dyn_facebook_"+eventId)) { 1766 event = Utils.getFormFilledData(event); 1767 Facebook.fireEvent(event.name, event); 1768 } 1769 } 1770 1771 if (events.hasOwnProperty('ga')) { 1772 event = events.ga; 1773 if(Utils.isEventInTimeWindow(event.name,event,"dyn_ga_"+eventId)) { 1774 event = Utils.getFormFilledData(event); 1775 Analytics.fireEvent(event.name, event); 1776 } 1777 } 1778 1779 if (events.hasOwnProperty('google_ads')) { 1780 event = events.google_ads; 1781 if(Utils.isEventInTimeWindow(event.name,event,"dyn_google_ads_"+eventId)) { 1782 event = Utils.getFormFilledData(event); 1783 GAds.fireEvent(event.name, event); 1784 } 1785 } 1786 1787 if (events.hasOwnProperty('pinterest')) { 1788 event = events.pinterest; 1789 if(Utils.isEventInTimeWindow(event.name,event,"dyn_pinterest_"+eventId)) { 1790 event = Utils.getFormFilledData(event); 1791 Pinterest.fireEvent(event.name, event);; 1792 } 1793 } 1794 1795 if (events.hasOwnProperty('bing')) { 1796 event = events.bing;
1797 if(Utils.isEventInTimeWindow(event.name,event,"dyn_bing_"+eventId)) { 1798 event = Utils.getFormFilledData(event); 1799 Bing.fireEvent(event.name, event);; 1800 } 1801 } 1802 if (events.hasOwnProperty('tiktok')) { 1803 event = events.tiktok; 1804 if(Utils.isEventInTimeWindow(event.name,event,"dyn_tiktok_"+eventId)) { 1805 event = Utils.getFormFilledData(event); 1806 TikTok.fireEvent(event.name, event); 1807 } 1808 } 1809 1810 if (events.hasOwnProperty('gtm')) { 1811 event = events.gtm; 1812 if(Utils.isEventInTimeWindow(event.name,event,"dyn_gtm_"+eventId)) { 1813 event = Utils.getFormFilledData(event); 1814 GTM.fireEvent(event.name, event); 1815 } 1816 } 1817 1818 1819 }, 1820 1821 isFirstPurchaseFire: function ($eventName,orderId,pixel) { 1822 1823 if(Cookies.get("pys_"+$eventName+"_order_id_"+pixel) == orderId) { 1824 return false; 1825 } else { 1826 Cookies.set("pys_"+$eventName+"_order_id_"+pixel, orderId, { expires: 1,path: '/' }); 1827 } 1828 return true; 1829 }, 1830 1831 fireStaticEvents: function (pixel, timeout = 0) { 1832 1833 if (options.staticEvents.hasOwnProperty(pixel)) { 1834 1835 $.each(options.staticEvents[pixel], function (eventId, events) { 1836 1837 //skip purchase event if this order was fired 1838 if( options.woo.hasOwnProperty('woo_purchase_on_transaction') && 1839 options.woo.woo_purchase_on_transaction && 1840 (eventId === "woo_purchase" || eventId === "woo_purchase_category") ) { 1841 if(!Utils.isFirstPurchaseFire(eventId,events[0].woo_order,pixel)) { 1842 return; 1843 } 1844 } 1845 1846 if( options.edd.hasOwnProperty('edd_purchase_on_transaction') && 1847 options.edd.edd_purchase_on_transaction && 1848 (eventId === "edd_purchase" || eventId === "edd_purchase_category") ) { 1849 if(!Utils.isFirstPurchaseFire(eventId,events[0].edd_order,pixel)) { 1850 return; 1851 } 1852 } 1853 1854 1855 $.each(events, function (index, event) { 1856 1857 event.fired = event.fired || false; 1858 1859 if (!event.fired && Utils.isEventInTimeWindow(event.name,event,'static_' + pixel+"_")) { 1860 event = Utils.getFormFilledData(event); 1861 1862 var fired = false; 1863 1864 // fire event 1865 if ( pixel === 'tiktok' ) { 1866 setTimeout(function() { 1867 getPixelBySlag(pixel).fireEvent(event.name, event); 1868 }, timeout * 500); 1869 timeout++; 1870 } else { 1871 getPixelBySlag(pixel).fireEvent(event.name, event); 1872 } 1873 1874 // prevent event double event firing 1875 event.fired = fired; 1876 } 1877 }); 1878 }); 1879 } 1880 }, 1881 1882 /** 1883 * Load tag's JS 1884 * 1885 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/ 1886 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets 1887 */ 1888 loadGoogleTag: function (id) { 1889 1890 if (!gtag_loaded) { 1891 let dataLayerName = this.dataLayerName; 1892 if(options.hasOwnProperty('GATags')){ 1893 switch (options.GATags.ga_datalayer_type) { 1894 case 'default': 1895 dataLayerName = 'dataLayerPYS'; 1896 break; 1897 case 'custom': 1898 dataLayerName = options.GATags.ga_datalayer_name; 1899 break; 1900 default: 1901 dataLayerName = 'dataLayer'; 1902 } 1903 } 1904 this.dataLayerName = dataLayerName; 1905 (function (window, document, src) { 1906 var a = document.createElement('script'), 1907 m = document.getElementsByTagName('script')[0]; 1908 a.async = 1; 1909 a.src = src; 1910 m.parentNode.insertBefore(a, m); 1911 }
1911)(window, document, '//www.googletagmanager.com/gtag/js?id=' + id+'&l='+this.dataLayerName); 1912 1913 window[dataLayerName] = window[dataLayerName] || []; 1914 window.gtag = window.gtag || function gtag() { 1915 window[dataLayerName].push(arguments); 1916 }; 1917 1918 if ( options.google_consent_mode ) { 1919 let data = {}; 1920 data[ 'analytics_storage' ] = options.gdpr.analytics_storage.enabled ? options.gdpr.analytics_storage.value : 'granted'; 1921 data[ 'ad_storage' ] = options.gdpr.ad_storage.enabled ? options.gdpr.ad_storage.value : 'granted'; 1922 data[ 'ad_user_data' ] = options.gdpr.ad_user_data.enabled ? options.gdpr.ad_user_data.value : 'granted'; 1923 data[ 'ad_personalization' ] = options.gdpr.ad_personalization.enabled ? options.gdpr.ad_personalization.value : 'granted'; 1924 1925 this.loadDefaultConsent( 'consent', 'default', data ); 1926 } 1927 1928 gtag('js', new Date()); 1929 gtag_loaded = true; 1930 1931 } 1932 1933 }, 1934 1935 loadDefaultConsent: function() { 1936 window[ this.dataLayerName ].push( arguments ); 1937 }, 1938 1939 loadGTMScript: function (id) { 1940 const domain = options.gtm.gtm_container_domain ?? 'www.googletagmanager.com'; 1941 const loader = options.gtm.gtm_container_identifier ?? 'gtm'; 1942 const gtm_auth = options.gtm.gtm_auth ?? ''; // Set this if needed 1943 const gtm_preview = options.gtm.gtm_preview ?? ''; // Set this if needed 1944 const datalayer_name = options.gtm.gtm_dataLayer_name ?? 'dataLayer'; 1945 1946 window[ datalayer_name ] = window[ datalayer_name ] || []; 1947 window.gtag = window.gtag || function gtag() { 1948 window[ datalayer_name ].push( arguments ); 1949 }; 1950 1951 if ( options.google_consent_mode ) { 1952 let data = {}; 1953 data[ 'analytics_storage' ] = options.gdpr.analytics_storage.enabled ? options.gdpr.analytics_storage.value : 'granted'; 1954 data[ 'ad_storage' ] = options.gdpr.ad_storage.enabled ? options.gdpr.ad_storage.value : 'granted'; 1955 data[ 'ad_user_data' ] = options.gdpr.ad_user_data.enabled ? options.gdpr.ad_user_data.value : 'granted'; 1956 data[ 'ad_personalization' ] = options.gdpr.ad_personalization.enabled ? options.gdpr.ad_personalization.value : 'granted'; 1957 1958 this.GTMdataLayerName = datalayer_name; 1959 this.loadDefaultGTMConsent( 'consent', 'default', data ); 1960 } 1961 1962 (function(w, d, s, l, i) { 1963 w[l] = w[l] || []; 1964 w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }); 1965 const f = d.getElementsByTagName(s)[0]; 1966 const j = d.createElement(s); 1967 const dl = l !== 'dataLayer' ? '&l=' + l : ''; 1968 j.async = true; 1969 j.src = 'https://' + domain + '/' + loader + '.js?id=' + i + dl; 1970 if (gtm_auth && gtm_preview) { 1971 j.src += '>m_auth=' + gtm_auth + '>m_preview=' + gtm_preview + '>m_cookies_win=x'; 1972 } 1973 f.parentNode.insertBefore(j, f); 1974 })(window, document, 'script', datalayer_name, id); 1975 1976 }, 1977 1978 loadDefaultGTMConsent: function() { 1979 window[ this.GTMdataLayerName ].push( arguments ); 1980 }, 1981 1982 /** 1983 * GDPR 1984 */ 1985 1986 loadPixels: function () { 1987 1988 if (options.gdpr.ajax_enabled && !options.gdpr.consent_magic_integration_enabled) { 1989 1990 // retrieves actual PYS GDPR filters values which allow to avoid cache issues 1991 $.get({ 1992 url: options.ajaxUrl, 1993 dataType: 'json', 1994 data: { 1995 action: 'pys_get_gdpr_filters_values' 1996 }, 1997 success: function (res) { 1998 1999 if (res.success) { 2000 2001 options.gdpr.all_disabled_by_api = res.data.all_disabled_by_api; 2002 options.gdpr.facebook_disabled_by_api = res.data.facebook_disabled_by_api; 2003 options.gdpr.tiktok_disabled_by_api = res.data.tiktok_disabled_by_api; 2004 options.gdpr.analytics_disabled_by_api = res.data.analytics_disabled_by_api; 2005 options.gdpr.google_ads_disabled_by_api = res.data.google_ads_disabled_by_api; 2006 options.gdpr.pinterest_disabled_by_api = res.data.pinterest_disabled_by_api; 2007 options.gdpr.bing_disabled_by_api = res.data.bing_disabled_by_api; 2008 2009 options.cookie.externalID_disabled_by_api = res.data.externalID_disabled_by_api; 2010 options.cookie.disabled_all_cookie = res.data.disabled_all_cookie; 2011 options.cookie.disabled_advanced_form_data_cookie = res.data.disabled_advanced_form_data_cookie; 2012 options.cookie.disabled_landing_page_cookie = res.data.disabled_landing_page_cookie; 2013 options.cookie.disabled_first_visit_cookie = res.data.disabled_first_visit_cookie; 2014 options.cookie.disabled_trafficsource_cookie = res.data.disabled_trafficsource_cookie; 2015 options.cookie.disabled_utmTerms_cookie = res.data.disabled_utmTerms_cookie; 2016 options.cookie.disabled_utmId_cookie = res.data.disabled_utmId_cookie; 2017 } 2018 loadPixels(); 2019 2020 } 2021 }); 2022 2023 } else { 2024 loadPixels(); 2025 } 2026 2027 }, 2028 2029 consentGiven: function (pixel) { 2030 2031 /** 2032 * Cookiebot 2033 */ 2034 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 2035 2036 var cookiebot_consent_category = options.gdpr['cookiebot_' + pixel + '_consent_category']; 2037 2038 if (options.gdpr[pixel + '_prior_consent_enabled']) { 2039 if (Cookiebot.consented === true || Cookiebot.consent[cookiebot_consent_category]) { 2040 return true; 2041 } 2042 } else { 2043 if (Cookiebot.consent[cookiebot_consent_category]) { 2044 return true; 2045 } 2046 } 2047 return false; 2048 2049 } 2050 2051 /** 2052 * Cookie Notice 2053 */ 2054 if (options.gdpr.cookie_notice_integration_enabled && typeof cnArgs !== 'undefined') { 2055 2056 var cn_cookie = Cookies.get(cnArgs.cookieName); 2057 2058 if (options.gdpr[pixel + '_prior_consent_enabled']) { 2059 if (typeof cn_cookie === 'undefined' || cn_cookie === 'true') { 2060 return true; 2061 } 2062 } else { 2063 if (cn_cookie === 'true') { 2064 return true; 2065 } 2066 } 2067 2068 return false; 2069 2070 } 2071 2072 /** 2073 * Cookie Law Info 2074 */ 2075 2076 if (options.gdpr.cookie_law_info_integration_enabled) { 2077 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 2078 if (options.gdpr[pixel + '_prior_consent_enabled']) { 2079 if (typeof cli_cookie === 'undefined') return true; 2080 if (cli_cookie && cli_cookie === Cookies.get('cookieyes-consent')) { 2081 if (getCookieYes('analytics') === 'yes') { 2082 return true; 2083 } 2084 } else if (cli_cookie && cli_cookie === Cookies.get('viewed_cookie_policy')) { 2085 if (Cookies.get('viewed_cookie_policy') === 'yes') { 2086 return true; 2087 } 2088 } 2089 } else { 2090 if (cli_cookie && cli_cookie === Cookies.get('cookieyes-consent')) { 2091 if (getCookieYes('analytics') === 'yes') { 2092 return true; 2093 } 2094 } else if (cli_cookie && cli_cookie === Cookies.get('viewed_cookie_policy')) { 2095 if (Cookies.get('viewed_cookie_policy') === 'yes') { 2096 return true; 2097 } 2098 } 2099 } 2100 return false; 2101 } 2102 2103 /** 2104 * ConsentMagic 2105 */ 2106 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined" ) { 2107 2108 var test_prefix = CS_Data.test_prefix; 2109 if ((typeof CS_Data.cs_google_consent_mode_enabled !== "undefined" && CS_Data.cs_google_consent_mode_enabled == 1) && ( pixel == 'analytics' || pixel == 'google_ads' ) ) { 2110 if ( CS_Data.cs_cache_enabled == 0 || ( CS_Data.cs_cache_enabled == 1 && window.CS_Cache && window.CS_Cache.check_status) ){ 2111 return true; 2112 } else { 2113 return false; 2114 } 2115 } 2116 2117 if( pixel == 'facebook' && ( CS_Data.cs_script_cat.facebook == 0 || CS_Data.cs_script_cat.facebook == CS_Data.cs_necessary_cat_id ) ) { 2118 return true; 2119 } else if( pixel == 'bing' && ( CS_Data.cs_script_cat.bing == 0 || CS_Data.cs_script_cat.bing == CS_Data.cs_necessary_cat_id ) ) { 2120 return true; 2121 } else if( pixel == 'analytics' && ( CS_Data.cs_script_cat.analytics == 0 || CS_Data.cs_script_cat.analytics == CS_Data.cs_necessary_cat_id ) ) { 2122 return true; 2123 } else if( pixel == 'google_ads' && ( CS_Data.cs_script_cat.gads == 0 || CS_Data.cs_script_cat.gads == CS_Data.cs_necessary_cat_id ) ) { 2124 return true; 2125 } else if( pixel == 'pinterest' && ( CS_Data.cs_script_cat.pinterest == 0 || CS_Data.cs_script_cat.pinterest == CS_Data.cs_necessary_cat_id ) ) { 2126 return true; 2127 } else if( pixel == 'tiktok' && ( CS_Data.cs_script_cat.tiktok == 0 || CS_Data.cs_script_cat.tiktok == CS_Data.cs_necessary_cat_id ) ) { 2128 return true; 2129 } 2130 2131 var substring = "cs_enabled_cookie_term"; 2132 var theCookies = document.cookie.split( ';' ); 2133 2134 for ( var i = 1; i <= theCookies.length; i++ ) { 2135 if ( theCookies[ i - 1 ].indexOf( substring ) !== -1 ) { 2136 var categoryCookie = theCookies[ i - 1 ].replace( 'cs_enabled_cookie_term' + test_prefix + '_', '' ); 2137 categoryCookie = Number( categoryCookie.replace( /\D+/g, "" ) ); 2138 var cs_cookie_val = Cookies.get( 'cs_enabled_cookie_term' + test_prefix + '_' + categoryCookie ); 2139 2140 if ( categoryCookie === CS_Data.cs_script_cat.facebook && pixel == 'facebook' ) { 2141 return cs_cookie_val == 'yes'; 2142 } else if ( categoryCookie === CS_Data.cs_script_cat.bing && pixel == 'bing' ) { 2143 return cs_cookie_val == 'yes'; 2144 } else if ( categoryCookie === CS_Data.cs_script_cat.analytics && pixel == 'analytics' ) { 2145 return cs_cookie_val == 'yes'; 2146 } else if ( categoryCookie === CS_Data.cs_script_cat.gads && pixel == 'google_ads' ) { 2147 return cs_cookie_val == 'yes'; 2148 } else if ( categoryCookie === CS_Data.cs_script_cat.pinterest && pixel == 'pinterest' ) { 2149 return cs_cookie_val == 'yes'; 2150 } else if ( categoryCookie === CS_Data.cs_script_cat.tiktok && pixel == 'tiktok' ) { 2151 return cs_cookie_val == 'yes'; 2152 } 2153 } 2154 } 2155 2156 return false; 2157 } 2158 2159 2160 /** 2161 * Real Cookie Banner 2162 */ 2163 if (options.gdpr.real_cookie_banner_integration_enabled) { 2164 var consentApi = window.consentApi; 2165 if (consentApi) { 2166 switch (pixel) { 2167 case "analytics": 2168 return consentApi.consentSync("http", "_ga", "*").cookieOptIn; 2169 case "facebook": 2170 return consentApi.consentSync("http", "_fbp", "*").cookieOptIn; 2171 case "pinterest": 2172 return consentApi.consentSync("http", "_pinterest_sess", ".pinterest.com").cookieOptIn; 2173 case "bing": 2174 return consentApi.consentSync("http", "_uetsid", "*").cookieOptIn; 2175 case "google_ads": 2176 return consentApi.consentSync("http", "1P_JAR", ".google.com").cookieOptIn; 2177 case 'tiktok': 2178 return consentApi.consentSync("http", "tt_webid_v2", ".tiktok.com").cookieOptIn; 2179 default: 2180 return true; 2181 } 2182 } 2183 } 2184 2185 return true; 2186 2187 }, 2188 2189 setupGdprCallbacks: function () { 2190 2191 var isConcent = false; 2192 2193 /** 2194 * Cookiebot 2195 */ 2196 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 2197 isConcent = true; 2198 window.addEventListener("CookiebotOnConsentReady", function() { 2199 2200 Utils.initializeVideoAPIs(options); 2201 2202 Utils.manageCookies(); 2203 if (Cookiebot.consent.marketing) { 2204 Facebook.loadPixel(); 2205 Bing.loadPixel(); 2206 Pinterest.loadPixel(); 2207 GAds.loadPixel(); 2208 TikTok.loadPixel(); 2209 } 2210 if (Cookiebot.consent.statistics) { 2211 Analytics.loadPixel(); 2212 } 2213 if (!Cookiebot.consent.marketing) { 2214 Facebook.disable(); 2215 Pinterest.disable(); 2216 Bing.disable() 2217 GAds.disable(); 2218 TikTok.disable(); 2219 } 2220 if (!Cookiebot.consent.statistics) { 2221 Analytics.disable(); 2222 } 2223 }); 2224 } 2225 2226 /** 2227 * Cookie Notice 2228 */ 2229 if (options.gdpr.cookie_notice_integration_enabled) { 2230 isConcent = true; 2231
2231 $(document).onFirst('click', '.cn-set-cookie', function () { 2232 2233 if ($(this).data('cookie-set') === 'accept') { 2234 2235 Utils.initializeVideoAPIs(options); 2236 2237 Facebook.loadPixel(); 2238 Analytics.loadPixel(); 2239 GAds.loadPixel(); 2240 Pinterest.loadPixel(); 2241 Bing.loadPixel(); 2242 TikTok.loadPixel(); 2243 } else { 2244 Facebook.disable(); 2245 Analytics.disable(); 2246 GAds.disable(); 2247 Pinterest.disable(); 2248 Bing.disable(); 2249 TikTok.disable(); 2250 } 2251 2252 }); 2253 2254 $(document).onFirst('click', '.cn-revoke-cookie', function () { 2255 Facebook.disable(); 2256 Analytics.disable(); 2257 GAds.disable(); 2258 Pinterest.disable(); 2259 Bing.disable(); 2260 TikTok.disable(); 2261 }); 2262 2263 } 2264 2265 /** 2266 * Cookie Law Info 2267 */ 2268 if (options.gdpr.cookie_law_info_integration_enabled) { 2269 isConcent = true; 2270 $(document).onFirst('click', '#wt-cli-accept-all-btn,#cookie_action_close_header, .cky-btn-accept', function () { 2271 Utils.initializeVideoAPIs(options); 2272 setTimeout(function (){ 2273 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 2274 if (typeof cli_cookie !== 'undefined') { 2275 if (cli_cookie === Cookies.get('cookieyes-consent') && getCookieYes('analytics') == 'yes') { 2276 Utils.manageCookies(); 2277 } else if (cli_cookie === Cookies.get('viewed_cookie_policy') && cli_cookie == 'yes') { 2278 Utils.manageCookies(); 2279 } 2280 } 2281 },1000) 2282 Facebook.loadPixel(); 2283 Analytics.loadPixel(); 2284 GAds.loadPixel(); 2285 Pinterest.loadPixel(); 2286 Bing.loadPixel(); 2287 TikTok.loadPixel(); 2288 }); 2289 2290 $(document).onFirst('click', '#cookie_action_close_header_reject, .cky-btn-reject', function () { 2291 Facebook.disable(); 2292 Analytics.disable(); 2293 GAds.disable(); 2294 Pinterest.disable(); 2295 Bing.disable(); 2296 TikTok.disable(); 2297 }); 2298 2299 } 2300 2301 /** 2302 * ConsentMagic 2303 */ 2304 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 2305 isConcent = true; 2306 var test_prefix = CS_Data.test_prefix, 2307 cs_refresh_after_consent = false, 2308 substring = "cs_enabled_cookie_term"; 2309 2310 if (CS_Data.cs_refresh_after_consent == 1) { 2311 cs_refresh_after_consent = CS_Data.cs_refresh_after_consent; 2312 } 2313 2314 if (!cs_refresh_after_consent) { 2315 var theCookies = document.cookie.split(';'); 2316 for (var i = 1 ; i <= theCookies.length; i++) { 2317 if (theCookies[i-1].indexOf(substring) !== -1) { 2318 var categoryCookie = theCookies[i-1].replace('cs_enabled_cookie_term'+test_prefix+'_',''); 2319 categoryCookie = Number(categoryCookie.replace(/\D+/g,"")); 2320 var cs_cookie_val = Cookies.get('cs_enabled_cookie_term'+test_prefix+'_'+categoryCookie); 2321 if(cs_cookie_val == 'yes') { 2322 2323 Utils.initializeVideoAPIs(options); 2324 2325 if (categoryCookie === CS_Data.cs_script_cat.facebook) { 2326 Facebook.loadPixel(); 2327 } 2328 2329 if (categoryCookie === CS_Data.cs_script_cat.bing) { 2330 Bing.loadPixel(); 2331 } 2332 2333 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)
2333) { 2334 2335 Analytics.loadPixel(); 2336 } 2337 if (categoryCookie === CS_Data.cs_script_cat.gads || (typeof CS_Data.cs_google_ads_consent_mode !== "undefined" && CS_Data.cs_google_ads_consent_mode == 1)) { 2338 GAds.loadPixel(); 2339 } 2340 2341 if (categoryCookie === CS_Data.cs_script_cat.pinterest) { 2342 Pinterest.loadPixel(); 2343 } 2344 2345 if (categoryCookie === CS_Data.cs_script_cat.tiktok) { 2346 TikTok.loadPixel(); 2347 } 2348 } else { 2349 if (categoryCookie === CS_Data.cs_script_cat.facebook) { 2350 Facebook.disable(); 2351 } 2352 2353 if (categoryCookie === CS_Data.cs_script_cat.bing) { 2354 Bing.disable(); 2355 } 2356 2357 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)) { 2358 Analytics.disable(); 2359 } 2360 2361 if (categoryCookie === CS_Data.cs_script_cat.gads && (typeof CS_Data.cs_google_ads_consent_mode == "undefined" || CS_Data.cs_google_ads_consent_mode == 0)) { 2362 GAds.disable(); 2363 } 2364 2365 if (categoryCookie === CS_Data.cs_script_cat.pinterest) { 2366 Pinterest.disable(); 2367 } 2368 2369 if (categoryCookie === CS_Data.cs_script_cat.tiktok) { 2370 TikTok.disable(); 2371 } 2372 } 2373 if (Cookies.get('cs_enabled_advanced_matching') == 'yes') { 2374 Facebook.loadPixel(); 2375 } 2376 } 2377 } 2378 2379 $(document).on('click','.cs_action_btn',function(e) { 2380 e.preventDefault(); 2381 var elm = $(this), 2382 button_action = elm.attr('data-cs_action'); 2383 2384 if(button_action === 'allow_all') { 2385 2386 Utils.initializeVideoAPIs(options); 2387 2388 Facebook.loadPixel(); 2389 Bing.loadPixel(); 2390 Analytics.loadPixel(); 2391 GAds.loadPixel(); 2392 Pinterest.loadPixel(); 2393 TikTok.loadPixel(); 2394 } else if(button_action === 'disable_all') { 2395 2396 Facebook.disable(); 2397 Bing.disable(); 2398 if(CS_Data.cs_google_analytics_consent_mode == 0 || typeof CS_Data.cs_google_analytics_consent_mode == "undefined") 2399 { 2400 Analytics.disable(); 2401 } 2402 if(CS_Data.cs_google_ads_consent_mode == 0 || typeof CS_Data.cs_google_ads_consent_mode == "undefined") 2403 { 2404 GAds.disable(); 2405 } 2406 Pinterest.disable(); 2407 TikTok.disable(); 2408 } 2409 }); 2410 } 2411 } 2412 2413 /** 2414 * Real Cookie Banner 2415 */ 2416 if (options.gdpr.real_cookie_banner_integration_enabled) { 2417 isConcent = true; 2418 var consentApi = window.consentApi; 2419 if (consentApi) { 2420 consentApi.consent("http", "_ga", "*") 2421 .then(Analytics.loadPixel.bind(Analytics), Analytics.disable.bind(Analytics)); 2422 consentApi.consent("http", "1P_JAR", ".google.com") 2423 .then(GAds.loadPixel.bind(GAds), GAds.disable.bind(GAds)); 2424 consentApi.consent("http", "_fbp", "*") 2425 .then(Facebook.loadPixel.bind(Facebook), Facebook.disable.bind(Facebook)); 2426 consentApi.consent("http", "_pinterest_sess", ".pinterest.com") 2427 .then(Pinterest.loadPixel.bind(Pinterest), Pinterest.disable.bind(Pinterest)); 2428 consentApi.consent("http", "_uetsid", "*") 2429 .then(Bing.loadPixel.bind(Bing), Bing.disable.bind(Bing)); 2430 consentApi.consent("http", "tt_webid_v2", ".tiktok.com") 2431 .then(TikTok.loadPixel.bind(TikTok), TikTok.disable.bind(TikTok)); 2432 2433 // load WatchVideo event APIs for Auto 2434 /** 2435 * Real Cookie Banner. 2436 */ 2437 if(options.hasOwnProperty('automatic') && options.automatic.enable_video && options.automatic.enable_youtube){ 2438 consentApi.consent( "http", "CONSENT", ".youtube.com" ).then( Utils.initYouTubeAPI ); 2439 } 2440 2441 if(options.hasOwnProperty('automatic') && options.automatic.enable_video && options.automatic.enable_vimeo){ 2442 consentApi.consent( "http", "player", ".vimeo.com" ).then( Utils.initVimeoAPI ); 2443 } 2444 } 2445 } 2446 2447 if(!isConcent) { 2448 Utils.initializeVideoAPIs(options); 2449 } 2450 2451 }, 2452 2453 /** 2454 * Enrich 2455 */ 2456 isCheckoutPage: function () { 2457 return $('body').hasClass('woocommerce-checkout') || document.querySelector('.woocommerce-checkout') || 2458 $('body').hasClass('edd-checkout'); 2459 }, 2460 addCheckoutFields : function() { 2461 var utm = ""; 2462 var utms = getUTMs() 2463 $.each(utmTerms, function (index, name) { 2464 if(index > 0) { 2465 utm+="|"; 2466 } 2467 utm+=name+":"+utms[name]; 2468 }); 2469 var utmIdList = ""; 2470 var utmsIds = getUTMId() 2471 $.each(utmId, function (index, name) { 2472 if(index > 0) { 2473 utmIdList+="|"; 2474 } 2475 utmIdList+=name+":"+utmsIds[name]; 2476 }); 2477 var utmIdListLast = ""; 2478 var utmsIdsLast = getUTMId(true) 2479 $.each(utmId, function (index, name) { 2480 if(index > 0) { 2481 utmIdListLast+="|"; 2482 } 2483 utmIdListLast+=name+":"+utmsIdsLast[name]; 2484 }); 2485 2486 2487 var utmLast = ""; 2488 var utmsLast = getUTMs(true) 2489 $.each(utmTerms, function (index, name) { 2490 if(index > 0) { 2491 utmLast+="|"; 2492 }
2493 utmLast+=name+":"+utmsLast[name]; 2494 }); 2495 2496 var dateTime = getDateTime(); 2497 var landing = Cookies.get('pys_landing_page'); 2498 var lastLanding = Cookies.get('last_pys_landing_page'); 2499 var trafic = Cookies.get('pysTrafficSource'); 2500 var lastTrafic = Cookies.get('last_pysTrafficSource'); 2501 2502 var $form = null; 2503 if($('body').hasClass('woocommerce-checkout')) { 2504 $form = $("form.woocommerce-checkout"); 2505 } else { 2506 $form = $("#edd_purchase_form"); 2507 } 2508 var inputs = {'pys_utm':utm, 2509 'pys_utm_id':utmIdList, 2510 'pys_browser_time':dateTime.join("|"), 2511 'pys_landing':landing, 2512 'pys_source':trafic, 2513 'pys_order_type': $(".wcf-optin-form").length > 0 ? "wcf-optin" : "normal", 2514 2515 'last_pys_landing':lastLanding, 2516 'last_pys_source':lastTrafic, 2517 'last_pys_utm':utmLast, 2518 'last_pys_utm_id':utmIdListLast, 2519 } 2520 2521 Object.keys(inputs).forEach(function(key,index) { 2522 $form.append("<input type='hidden' name='"+key+"' value='"+inputs[key]+"' /> "); 2523 }); 2524 2525 2526 }, 2527 2528 /** 2529 * Advanced From Data 2530 */ 2531 saveAdvancedFormData: function ( email, phone, firstName, lastName, override = true ) { 2532 2533 if ( !options.cookie.disabled_advanced_form_data_cookie ) { 2534 let data = Utils.getAdvancedFormData(); 2535 // Ensure data["address"] is an object 2536 2537 if ( email != null ) { 2538 if ( !override ) { 2539 if ( typeof data[ "email" ] === 'undefined' || !data[ "email" ] ) { 2540 data[ "email" ] = email; 2541 } 2542 } else { 2543 data[ "email" ] = email; 2544 } 2545 2546 if ( typeof data[ "emails" ] === 'object' ) { 2547 if ( override ) { 2548 data[ "emails" ] = [ email, ...Object.values( data[ "emails" ] ) ]; 2549 } else { 2550 data[ "emails" ] = [ ...Object.values( data[ "emails" ] ), email ]; 2551 } 2552 } else { 2553 data[ "emails" ] = [ email ]; 2554 } 2555 data[ "emails" ] = [ ...new Set( data[ "emails" ] ) ]; 2556 data[ "emails" ] = data[ "emails" ].slice( 0, 3 ); 2557 } 2558 2559 if ( phone != null ) { 2560 if ( !override ) { 2561 if ( typeof data[ "phone" ] === 'undefined' || !data[ "phone" ] ) { 2562 data[ "phone" ] = phone; 2563 } 2564 } else { 2565 data[ "phone" ] = phone; 2566 } 2567 2568 if ( typeof data[ "phones" ] === 'object' ) { 2569 if ( override ) { 2570 data[ "phones" ] = [ phone, ...Object.values( data[ "phones" ] ) ]; 2571 } else { 2572 data[ "phones" ] = [ ...Object.values( data[ "phones" ] ), phone ]; 2573 } 2574 } else { 2575 data[ "phones" ] = [ phone ]; 2576 } 2577 data[ "phones" ] = [ ...new Set( data[ "phones" ] ) ]; 2578 data[ "phones" ] = data[ "phones" ].slice( 0, 3 ); 2579 } 2580 2581 if ( firstName != null ) { 2582 if ( !override ) { 2583 if ( typeof data[ "first_name" ] === 'undefined' || !data[ "first_name" ] ) { 2584 data[ "first_name" ] = firstName; 2585 } 2586 } else { 2587 data[ "first_name" ] = firstName; 2588 } 2589 2590 if ( typeof data[ "fns" ] === 'object' ) { 2591 if ( override ) { 2592 data[ "fns" ] = [ firstName, ...Object.values( data[ "fns" ] ) ]; 2593 } else { 2594 data[ "fns" ] = [ ...Object.values( data[ "fns" ] ), firstName ]; 2595 } 2596 } else { 2597 data[ "fns" ] = [ firstName ]; 2598 } 2599 data[ "fns" ] = [ ...new Set( data[ "fns" ] ) ]; 2600 data[ "fns" ] = data[ "fns" ].slice( 0, 2 ); 2601 } 2602 2603 if ( lastName != null ) { 2604 if ( !override ) { 2605 if ( typeof data[ "last_name" ] === 'undefined' || !data[ "last_name" ] ) { 2606 data[ "last_name" ] = lastName; 2607 } 2608 } else { 2609 data[ "last_name" ] = lastName; 2610 } 2611
2612 if ( typeof data[ "lns" ] === 'object' ) { 2613 if ( override ) { 2614 data[ "lns" ] = [ lastName, ...Object.values( data[ "lns" ] ) ]; 2615 } else { 2616 data[ "lns" ] = [ ...Object.values( data[ "fns" ] ), lastName ]; 2617 } 2618 } else { 2619 data[ "lns" ] = [ lastName ]; 2620 } 2621 data[ "lns" ] = [ ...new Set( data[ "lns" ] ) ]; 2622 data[ "lns" ] = data[ "lns" ].slice( 0, 2 ); 2623 } 2624 2625 Cookies.set( 'pys_advanced_form_data', JSON.stringify( data ), { expires: 300,path: '/',domain: domain } ); 2626 } else { 2627 Cookies.remove( 'pys_advanced_form_data' ) 2628 } 2629 if(GTM.isEnabled()){ 2630 GTM.updateEnhancedConversionData(); 2631 } 2632 if(Analytics.isEnabled()){ 2633 Analytics.updateEnhancedConversionData(); 2634 } else if ( GAds.isEnabled() ) { 2635 GAds.updateEnhancedConversionData(); 2636 } 2637 }, 2638 getAdvancedMergeFormData: function (allways_provided_data = false) { 2639 const advanced = Utils.getAdvancedFormData(); 2640 let mergedData = {}, 2641 limit = options.tracking_analytics.use_multiple_provided_data || allways_provided_data ? 3 : 1, 2642 address_limit = options.tracking_analytics.use_multiple_provided_data || allways_provided_data ? 2 : 1; 2643 2644 if ( options.tracking_analytics.use_encoding_provided_data || allways_provided_data) { 2645 mergedData.sha256_email_address = []; 2646 mergedData.sha256_phone_number = []; 2647 mergedData.address = []; 2648 if ( options.tracking_analytics.hasOwnProperty( "userData" ) ) { 2649 if ( options.tracking_analytics.userData.hasOwnProperty( "emails" ) && Object.keys( options.tracking_analytics.userData.emails ).length > 0 ) { 2650 Object.keys( options.tracking_analytics.userData.emails ).forEach( ( key ) => { 2651 mergedData.sha256_email_address.push( sha256( options.tracking_analytics.userData.emails[ key ] ) ); 2652 } ) 2653 } 2654 if ( options.tracking_analytics.userData.hasOwnProperty( "phones" ) && Object.keys( options.tracking_analytics.userData.phones ).length > 0 ) { 2655 Object.keys( options.tracking_analytics.userData.phones ).forEach( ( key ) => { 2656 mergedData.sha256_phone_number.push( sha256( options.tracking_analytics.userData.phones[ key ] ) ); 2657 } ) 2658 } 2659 if ( options.tracking_analytics.userData.hasOwnProperty( "addresses" ) && Object.keys( options.tracking_analytics.userData.addresses ).length > 0 ) { 2660 Object.keys( options.tracking_analytics.userData.addresses ).forEach( ( key ) => { 2661 let address = Object.assign( {}, options.tracking_analytics.userData.addresses[ key ] ); 2662 2663 if ( address.first_name ) { 2664 address.sha256_first_name = address.first_name !== '' ? sha256( address.first_name ) : ''; 2665 delete address.first_name; 2666 } 2667 if ( address.last_name ) { 2668 address.sha256_last_name = address.last_name !== '' ? sha256( address.last_name ) : ''; 2669 delete address.last_name; 2670 } 2671 mergedData.address.push( address ); 2672 } ) 2673 } 2674 } 2675 2676 let data_persistency = options.data_persistency; 2677 2678 //emails 2679 if ( advanced.emails && Object.keys( advanced.emails ).length > 0 ) { 2680 Object.keys( advanced.emails ).forEach( ( ke
2680y ) => { 2681 if ( data_persistency === 'recent_data' ) { 2682 mergedData.sha256_email_address.push( sha256( advanced.emails[ key ] ) ); 2683 } else { 2684 mergedData.sha256_email_address.unshift( sha256( advanced.emails[ key ] ) ); 2685 } 2686 } ) 2687 } 2688 if ( advanced.email && advanced.email !== '' ) { 2689 if ( data_persistency === 'recent_data' ) { 2690 mergedData.sha256_email_address.push( sha256( advanced.email ) ); 2691 } else { 2692 mergedData.sha256_email_address.unshift( sha256( advanced.email ) ); 2693 } 2694 } 2695 mergedData.sha256_email_address = [ ...new Set( mergedData.sha256_email_address ) ]; 2696 mergedData.sha256_email_address = mergedData.sha256_email_address.slice( 0, limit ); 2697 2698 //phones 2699 if ( advanced.phones && Object.keys( advanced.phones ).length > 0 ) { 2700 Object.keys( advanced.phones ).forEach( ( key ) => { 2701 if ( data_persistency === 'recent_data' ) { 2702 mergedData.sha256_phone_number.push( sha256( advanced.phones[ key ] ) ); 2703 } else { 2704 mergedData.sha256_phone_number.unshift( sha256( advanced.phones[ key ] ) ); 2705 } 2706 } ) 2707 } 2708 if ( advanced.phone && advanced.phone !== '' ) { 2709 if ( data_persistency === 'recent_data' ) { 2710 mergedData.sha256_phone_number.push( sha256( advanced.phone ) ); 2711 } else { 2712 mergedData.sha256_phone_number.unshift( sha256( advanced.phone ) ); 2713 } 2714 } 2715 mergedData.sha256_phone_number = [ ...new Set( mergedData.sha256_phone_number ) ]; 2716 mergedData.sha256_phone_number = mergedData.sha256_phone_number.slice( 0, limit ); 2717 2718 //first and last names 2719 if ( advanced.fns && Object.keys( advanced.fns ).length > 0 ) { 2720 Object.entries( advanced.fns ).forEach( ( item ) => { 2721 if ( mergedData.address.length < address_limit ) { 2722 let first_name = item[ 1 ]; 2723 let last_name = ( advanced.lns && Object.keys( advanced.lns ).length > 0 ) ? ( advanced.lns[ item[ 0 ] ] ? advanced.lns[ item[ 0 ] ] : advanced.lns[ 0 ] ) : ''; 2724 let address = { 2725 sha256_first_name: first_name !== '' ? sha256( first_name ) : '', 2726 sha256_last_name: last_name !== '' ? sha256( last_name ) : '', 2727 // Add other address properties here if they exist in advanced 2728 }; 2729 mergedData.address.push( address ); 2730 } 2731 } ) 2732 } 2733 2734 if ( advanced.first_name || advanced.last_name ) { 2735 if ( mergedData.address.length < address_limit ) { 2736 let address = { 2737 sha256_first_name: advanced.first_name !== '' ? sha256( advanced.first_name ) : '', 2738 sha256_last_name: advanced.last_name !== '' ? sha256( advanced.last_name ) : '', 2739 // Add other address properties here if they exist in advanced 2740 }; 2741 mergedData.address.push( address ); 2742 } 2743 } 2744 } else { 2745 mergedData.email = []; 2746 mergedData.phone_number = []; 2747 mergedData.address = []; 2748 if ( options.tracking_analytics.hasOwnProperty( "userData" ) ) { 2749 if ( options.tracking_analytics.userData.hasOwnProperty( "emails" ) && Object.keys( options.tracking_analytics.userData.emails ).length > 0 ) { 2750 Object.keys( options.tracking_analytics.userData.emails ).forEach( ( ke
2750y ) => { 2751 mergedData.email.push( options.tracking_analytics.userData.emails[ key ] ); 2752 } ) 2753 } 2754 if ( options.tracking_analytics.userData.hasOwnProperty( "phones" ) && Object.keys( options.tracking_analytics.userData.phones ).length > 0 ) { 2755 Object.keys( options.tracking_analytics.userData.phones ).forEach( ( key ) => { 2756 mergedData.phone_number.push( options.tracking_analytics.userData.phones[ key ] ); 2757 } ) 2758 } 2759 if ( options.tracking_analytics.userData.hasOwnProperty( "addresses" ) && Object.keys( options.tracking_analytics.userData.addresses ).length > 0 ) { 2760 Object.keys( options.tracking_analytics.userData.addresses ).forEach( ( key ) => { 2761 mergedData.address.push( options.tracking_analytics.userData.addresses[ key ] ); 2762 } ) 2763 } 2764 } 2765 2766 let data_persistency = options.data_persistency; 2767 2768 //emails 2769 if ( advanced.emails && Object.keys( advanced.emails ).length > 0 ) { 2770 Object.keys( advanced.emails ).forEach( ( key ) => { 2771 if ( data_persistency === 'recent_data' ) { 2772 mergedData.email.push( advanced.emails[ key ] ); 2773 } else { 2774 mergedData.email.unshift( advanced.emails[ key ] ); 2775 } 2776 } ) 2777 } 2778 if ( advanced.email && advanced.email !== '' ) { 2779 if ( data_persistency === 'recent_data' ) { 2780 mergedData.email.push( advanced.email ); 2781 } else { 2782 mergedData.email.unshift( advanced.email ); 2783 } 2784 } 2785 mergedData.email = [ ...new Set( mergedData.email ) ]; 2786 mergedData.email = mergedData.email.slice( 0, limit ); 2787 2788 //phones 2789 if ( advanced.phones && Object.keys( advanced.phones ).length > 0 ) { 2790 Object.keys( advanced.phones ).forEach( ( key ) => { 2791 if ( data_persistency === 'recent_data' ) { 2792 mergedData.phone_number.push( advanced.phones[ key ] ); 2793 } else { 2794 mergedData.phone_number.unshift( advanced.phones[ key ] ); 2795 } 2796 } ) 2797 } 2798 if ( advanced.phone && advanced.phone !== '' ) { 2799 if ( data_persistency === 'recent_data' ) { 2800 mergedData.phone_number.push( advanced.phone ); 2801 } else { 2802 mergedData.phone_number.unshift( advanced.phone ); 2803 } 2804 } 2805 mergedData.phone_number = [ ...new Set( mergedData.phone_number ) ]; 2806 mergedData.phone_number = mergedData.phone_number.slice( 0, limit ); 2807 2808 //first and last names 2809 if ( advanced.fns && Object.keys( advanced.fns ).length > 0 ) { 2810 Object.entries( advanced.fns ).forEach( ( item ) => { 2811 if ( mergedData.address.length < address_limit ) { 2812 let first_name = item[ 1 ]; 2813 let last_name = ( advanced.lns && Object.keys( advanced.lns ).length > 0 ) ? ( advanced.lns[ item[ 0 ] ] ? advanced.lns[ item[ 0 ] ] : advanced.lns[ 0 ] ) : ''; 2814 let address = { 2815 first_name: first_name || '', 2816 last_name: last_name || '', 2817 // Add other address properties here if they exist in advanced 2818 }; 2819 mergedData.address.push( address ); 2820 } 2821 } ) 2822 } 2823 2824 if ( advanced.first_name || advanced.last_name ) { 2825 if ( mergedData.address.length < address_limit ) { 2826 let address = { 2827 first_name: advanced.first_name || '', 2828 last_name: advanced.last_name || '', 2829 // Add other address properties here if they exist in advanced 2830 }; 2831 mergedData.address.push( address ); 2832 } 2833 } 2834 } 2835 2836 Utils.removeEmptyProperties( mergedData ); 2837 return mergedData; 2838 }, 2839 removeEmptyProperties : function(obj) { 2840 2841 if (obj.hasOwnProperty('address')) { 2842 // ÐÑÐ¾Ñ Ð¾Ð´Ð¸Ð¼ по ÐºÐ°Ð¶Ð´Ð¾Ð¼Ñ Ð¼Ð°ÑÑÐ¸Ð²Ñ Ð² 'address' 2843 for (let i = 0; i < obj['address'].length; i++) { 2844 let address1 = obj['address'][i]; 2845 2846 // СÑавниваем Ñ ÐºÐ°Ð¶Ð´Ñм дÑÑгим маÑÑивом в 'address' 2847 for (let j = i + 1; j < obj['address'].length; j++) { 2848 let address2 = obj['address'][j]; 2849 2850 // ÐÑли Ð½Ð°Ñ Ð¾Ð´Ð¸Ð¼ дÑблиÑÑÑÑиеÑÑ ÑвойÑÑва, ÑдалÑем Ð¸Ñ Ð¸Ð· address2 2851 for (let prop in address1) { 2852 if (address1[prop] === address2[prop]) { 2853 delete address2[prop]; 2854 } 2855 } 2856 } 2857 } 2858 } 2859 2860 for (let key in obj) { 2861 if (obj[key] === null || obj[key] === undefined || obj[key] === '') { 2862 delete obj[key]; 2863 } else if (Array.isArray(obj[key])) { 2864 obj[key] = [...new Set(obj[key])]; // Удаление дÑбликаÑов из маÑÑива 2865 obj[key] = obj[key].filter(item => item !== null && item !== undefined && item !== ''); 2866 // ÐбÑабоÑка обÑекÑов внÑÑÑи маÑÑивов 2867 obj[key] = obj[key].map(item => { 2868 if (item === null) { 2869 return; // ÐÑопÑÑкаем null ÑлеменÑÑ 2870 } else if (Array.isArray(item)) { 2871 return this.removeEmptyProperties(item); 2872 } else if (typeof item === 'object') { 2873 let cleanedItem = this.removeEmptyProperties(item); 2874 if (Object.keys(cleanedItem).length > 0) { 2875 return cleanedItem; 2876 } 2877 } else { 2878 return item; 2879 } 2880 }); 2881 // УдалÑем пÑÑÑÑе обÑекÑÑ Ð¸ null из маÑÑива 2882 obj[key] = obj[key].filter(item => item !== undefined && !(typeof item === 'object' && Object.keys(item).length === 0)); 2883 if (obj[key].length === 0) { 2884 delete obj[key]; 2885 } 2886 } else if (typeof obj[key] === 'object') { 2887 this.removeEmptyProperties(obj[key]); 2888 if (Object.keys(obj[key]).length === 0) { 2889 delete obj[key]; 2890 } 2891 } 2892 } 2893 return obj;
2894 }, 2895 getAdvancedFormData: function () { 2896 let dataStr = Cookies.get("pys_advanced_form_data"); 2897 if(dataStr === undefined) { 2898 return {'first_name':"",'last_name':"",'email':"",'phone':"",'fns':[],'lns':[],'emails':[],'phones':[]}; 2899 } else { 2900 return JSON.parse(dataStr); 2901 } 2902 }, 2903 2904 getFormFilledData: function ( event ) { 2905 if ( Object.keys(options.track_dynamic_fields).length > 0 && Object.keys(event.params).length > 0 ) { 2906 Object.entries(event.params).forEach((item) => { 2907 2908 if ( options.track_dynamic_fields.hasOwnProperty(item[0]) ) { 2909 let fieldData = Cookies.get('pys_dyn_field_' + item[1] ); 2910 2911 if(fieldData !== undefined && fieldData !== '') { 2912 event.params[item[0]] = fieldData; 2913 } else { 2914 delete event.params[item[0]]; 2915 } 2916 } 2917 }) 2918 } 2919 return event; 2920 } 2921 2922 }; 2923 2924 }(options); 2925 2926 var TikTok = function (options) { 2927 2928 var initialized = false; 2929 2930 function fireEvent(name, event) { 2931 2932 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'tiktok')) { 2933 return; 2934 } 2935 2936 var data = event.params; 2937 2938 var ids = event.pixelIds.filter(function (pixelId) { 2939 return !Utils.hideMatchingPixel(pixelId, 'tiktok'); 2940 }) 2941 var params = {}; 2942 Utils.copyProperties(data, params); 2943 2944 params.eventID = Utils.generateUniqueId(event); 2945 2946 if(ids.length > 0){ 2947 TikTok.fireEventAPI(name, event, params); 2948 } 2949 ids.forEach(function(pixelId){ 2950 if (options.debug) { 2951 console.log('[TikTok] ' + name, params,"pixel_id",pixelId); 2952 } 2953 2954 ttq.instance(pixelId).track(name,params) 2955 2956 }); 2957 2958 var customEvent = new CustomEvent('tiktok_event_sent', { 2959 detail: { 2960 eventName: name, 2961 params: params, 2962 pixel_ids: ids 2963 } 2964 }); 2965 window.dispatchEvent(customEvent); 2966 } 2967 2968 return { 2969 tag: function() { 2970 return "tiktok"; 2971 }, 2972 isEnabled: function () { 2973 return options.hasOwnProperty('tiktok'); 2974 }, 2975 getHidePixel: function(){ 2976 if(this.isEnabled() && options.tiktok.hasOwnProperty('hide_pixels')) 2977 { 2978 return options.tiktok.hide_pixels; 2979 } 2980 return []; 2981 }, 2982 disable: function () { 2983 initialized = false; 2984 }, 2985 2986 loadPixel:function () { 2987 if (initialized || !this.isEnabled() || !Utils.consentGiven('tiktok')) { 2988 return; 2989 } 2990 for (var i = 0; i < options.tiktok.pixelIds.length; i++) { 2991 var trackingId = options.tiktok.pixelIds[i]; 2992 if (!Utils.hideMatchingPixel(trackingId, 'tiktok')) { 2993 !function (w, d, t) { 2994 w.TiktokAnalyticsObject=t; 2995 var ttq=w[t]=w[t]||[]; 2996 ttq.methods=["page","track","identify","instances","debug","on","off","once","ready","alias","group","enableCookie","disableCookie"]; 2997 ttq.setAndDefer=function(t,e){t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}; 2998 for(var i=0;i<ttq.methods.length;i++) 2999 ttq.setAndDefer(ttq,ttq.methods[i]); 3000 ttq.instance=function(t){for(var e=ttq._i[t]||[],n=0;n<ttq.methods.length;n++)ttq.setAndDefer(e,ttq.methods[n]);return e}; 3001 ttq.load=function(e,n){var i="https://analytics.tiktok.com/i18n/pixel/events.js";ttq._i=ttq._i||{},ttq._i[e]=[],ttq._i[e]._u=i,ttq._t=ttq._t||{},ttq._t[e]=+new Date,ttq._o=ttq._o||{},ttq._o[e]=n||{};var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=i+"?sdkid="+e+"&lib="+t;var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(o,a)}; 3002 3003 //ttq.load('C60QSCQRVDG9JAKNPK2G'); 3004 //ttq.page(); 3005 }(window, document, 'ttq'); 3006 break; 3007 } 3008 } 3009 3010 3011 var ids = options.tiktok.pixelIds.filter(function (pixelId) { 3012 return !Utils.hideMatchingPixel(pixelId, 'tiktok'); 3013 }) 3014 ids.forEach(function (pixelId) { 3015 3016 ttq.load(pixelId); 3017 ttq.page(); 3018 let advancedMatching = {}; 3019 if(options.tiktok.hasOwnProperty('advanced_matching') 3020 && Object.keys(options.tiktok.advanced_matching).length > 0) { 3021 advancedMatching = options.tiktok.advanced_matching; 3022 if(!advancedMatching.hasOwnProperty("external_id")){ 3023 if (Cookies.get('pbid')) { 3024 advancedMatching["external_id"] = Cookies.get('pbid'); 3025 } 3026 } 3027 else if(advancedMatching.hasOwnProperty("external_id") && advancedMatching.external_id != Cookies.get('pbid')) 3028 { 3029 advancedMatching["external_id"] = Cookies.get('pbid') ? Cookies.get('pbid') : advancedMatching.external_id; 3030 } 3031 3032 ttq.instance(pixelId).identify(advancedMatching) 3033 } 3034 }); 3035 initialized = true; 3036 3037 if (options.staticEvents.hasOwnProperty('tiktok')) { 3038 var timeout = 1; 3039 setTimeout(function (timeout) { 3040 Utils.fireStaticEvents('tiktok', timeout); 3041 }, 1500, timeout) 3042 } 3043 }, 3044 3045 fireEvent: function (name, data) { 3046 if (!initialized || !this.isEnabled()) { 3047 return false; 3048 } 3049 data.delay = data.delay || 0; 3050 3051 if (data.delay === 0) { 3052 fireEvent(name, data); 3053 } else { 3054 setTimeout(function (name, params) { 3055 fireEvent(name, params); 3056 }, data.delay * 1000, name, data); 3057 } 3058 return true; 3059 }, 3060 3061 fireEventAPI: function (name, event, params) { 3062 3063 var ids = event.pixelIds.filter(function (pixelId) { 3064 return !Utils.hideMatchingPixel(pixelId, 'tiktok'); 3065 }) 3066 var notCachedEventsIds = new Array(); 3067 var isAddToCartFromJs = options.woo.hasOwnProperty("addToCartCatchMethod") 3068 && options.woo.addToCartCatchMethod === "add_cart_js"; 3069 if(!isAddToCartFromJs) { 3070 notCachedEventsIds.push('woo_add_to_cart_on_button_click') 3071 } 3072 3073 if(options.tiktok.serverApiEnabled) { 3074 if(!notCachedEventsIds.includes(event.e_id)) { 3075 3076 var isApiDisabled = options.gdpr.all_disabled_by_api || 3077 options.gdpr.tiktok_disabled_by_api || 3078 options.gdpr.cookiebot_integration_enabled || 3079 options.gdpr.cookie_notice_integration_enabled || 3080 options.gdpr.consent_magic_integration_enabled || 3081 options.gdpr.cookie_law_info_integration_enabled; 3082 // Update eventID 3083 3084 // send event from server if they were block by gdpr or need send with delay 3085 if( options.ajaxForServerEvent || isApiDisabled || event.delay > 0 || event.type !== "static" ){ 3086 3087 var json = { 3088 action: 'pys_tiktok_api_event', 3089 pixel: TikTok.tag(), 3090 event: name, 3091 ids: ids, 3092 data:params, 3093 url:window.location.href, 3094 event_id:params.eventID, 3095 ajax_event:options.ajax_event 3096 }; 3097 3098 let delay = 0; 3099 Object.keys(sessionStorage).forEach((key) => { 3100 let value = sessionStorage.getItem(key); 3101 if ( key.startsWith( 'wc_fragments_' ) && event.e_id == 'woo_add_to_cart_on_button_click' ) {
3102 delay = 2000; 3103 } 3104 }); 3105 3106 3107 if(event.hasOwnProperty('woo_order')) { 3108 json['woo_order'] = event.woo_order; 3109 } 3110 3111 if(event.hasOwnProperty('edd_order')) { 3112 json['edd_order'] = event.edd_order; 3113 } 3114 if(event.e_id === "automatic_event_internal_link" 3115 || event.e_id === "automatic_event_outbound_link" 3116 || name == 'PageView' 3117 ) { 3118 setTimeout(function(){ 3119 delay = delay === 0 ? 500 : delay; 3120 Utils.sendServerAjaxRequest(options.ajaxUrl, json) 3121 },delay) 3122 } else { 3123 setTimeout( () => Utils.sendServerAjaxRequest( options.ajaxUrl, json ), delay ); 3124 } 3125 } 3126 } 3127 } 3128 }, 3129 3130 onClickEvent: function (event) { 3131 this.fireEvent(event.name, event); 3132 }, 3133 3134 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, is_external, $form) { 3135 3136 window.pysWooProductData = window.pysWooProductData || []; 3137 if (!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 3138 return; 3139 3140 if (window.pysWooProductData.hasOwnProperty(product_id)) { 3141 if (window.pysWooProductData[product_id].hasOwnProperty(this.tag())) { 3142 3143 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 3144 3145 Utils.copyProperties(window.pysWooProductData[product_id][this.tag()]['params'], event.params); 3146 3147 // maybe customize value option 3148 if (options.woo.addToCartOnButtonValueEnabled && options.woo.addToCartOnButtonValueOption !== 'global') { 3149 3150 if (product_type === Utils.PRODUCT_BUNDLE) { 3151 var data = $(".bundle_form .bundle_data").data("bundle_form_data"); 3152 var items_sum = getBundlePriceOnSingleProduct(data); 3153 event.params.value = (parseFloat(data.base_price) + items_sum) * qty; 3154 } else { 3155 event.params.value = event.params.value * qty; 3156 } 3157 } 3158 3159 event.params.quantity = qty; 3160 3161 this.fireEvent(event.name, event); 3162 3163 } 3164 } 3165 }, 3166 3167 onWooAddToCartOnButtonEvent: function (product_id) { 3168 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 3169 return; 3170 3171 if (window.pysWooProductData.hasOwnProperty(product_id)) { 3172 if (window.pysWooProductData[product_id].hasOwnProperty(this.tag())) { 3173 var productData = window.pysWooProductData[product_id][this.tag()] 3174 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]) 3175 3176 Utils.copyProperties(productData['params'], event.params) 3177 event.pixelIds = productData['pixelIds']; 3178 this.fireEvent(event.name, event); 3179 } 3180 } 3181 }, 3182 3183 onEddAddToCartOnButtonEvent : function (download_id, price_index, qty) { 3184 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 3185 return; 3186 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 3187 3188 3189 if (window.pysEddProductData.hasOwnProperty(download_id)) { 3190 3191 var index; 3192 3193 if (price_index) { 3194 index = download_id + '_' + price_index; 3195 } else { 3196 index = download_id; 3197 } 3198 3199 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 3200 if (window.pysEddProductData[download_id][index].hasOwnProperty(this.tag())) { 3201 3202 Utils.copyProperties(window.pysEddProductData[download_id][index][this.tag()].params, event.params); 3203 this.fireEvent(event.name,event); 3204 3205 } 3206 } 3207 3208 } 3209 }, 3210 3211 onPageScroll: function (event) { 3212 if (initialized && this.isEnabled()) { 3213 this.fireEvent(event.name, event); 3214 } 3215 }, 3216 3217 onWatchVideo: function (event) { 3218 if (initialized && this.isEnabled() && !event.fired) { 3219 this.fireEvent(event.name, event); 3220 } 3221 }, 3222 3223 onCommentEvent: function (event) { 3224 if (initialized && this.isEnabled()) { 3225 this.fireEvent(event.name, event); 3226 } 3227 }, 3228 3229 onAdSenseEvent: function (event) { 3230 if (initialized && this.isEnabled()) { 3231 this.fireEvent(event.name, event); 3232 } 3233 }, 3234 3235 onTime: function (event) { 3236 if (initialized && this.isEnabled()) { 3237 this.fireEvent(event.name, event); 3238 } 3239 }, 3240 } 3241 }(options); 3242 3243 var Facebook = function (options) { 3244 3245 var defaultEventTypes = [ 3246 'PageView', 3247 'ViewContent', 3248 'Search', 3249 'AddToCart', 3250 'AddToWishlist',
3251 'InitiateCheckout', 3252 'AddPaymentInfo', 3253 'Purchase', 3254 'Lead', 3255 3256 'Subscribe', 3257 'CustomizeProduct', 3258 'FindLocation', 3259 'StartTrial', 3260 'SubmitApplication', 3261 'Schedule', 3262 'Contact', 3263 'Donate' 3264 ]; 3265 3266 var notCachedEventsIds = new Array(); 3267 var isAddToCartFromJs = options.woo.hasOwnProperty("addToCartCatchMethod") 3268 && options.woo.addToCartCatchMethod === "add_cart_js"; 3269 if(!isAddToCartFromJs) { 3270 notCachedEventsIds.push('woo_add_to_cart_on_button_click') 3271 } 3272 3273 var initialized = false; 3274 3275 var genereateFbp = function (){ 3276 return !Cookies.get('_fbp') ? 'fb.1.'+Date.now()+'.'+Math.floor(1000000000 + Math.random() * 9000000000) : Cookies.get('_fbp'); 3277 }; 3278 var genereateFbc = function (){ 3279 return getUrlParameter('fbclid') ? 'fb.1.'+Date.now()+'.'+getUrlParameter('fbclid') : '' 3280 }; 3281 3282 var configuredPixels = new Array(); 3283 function fireEvent(name, event) { 3284 3285 3286 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'facebook')) { 3287 return; 3288 } 3289 3290 var data = event.params; 3291 var ids = event.pixelIds.filter(function (pixelId) { 3292 return !Utils.hideMatchingPixel(pixelId, 'facebook'); 3293 }); 3294 3295 var actionType = defaultEventTypes.includes(name) ? 'trackSingle' : 'trackSingleCustom'; 3296 3297 var params = {}; 3298 3299 Utils.copyProperties(data, params);
3300 Utils.copyProperties(Utils.getRequestParams(), params); 3301 3302 Utils.copyProperties(Utils.getRequestParams(), data); 3303 3304 3305 if(options.facebook.serverApiEnabled) { 3306 if(event.e_id === "woo_remove_from_cart" ) { 3307 Facebook.updateEventId(event.name); 3308 event.eventID = Facebook.getEventId(event.name); 3309 } else if(!notCachedEventsIds.includes(event.e_id)) { 3310 var isApiDisabled = options.gdpr.all_disabled_by_api || 3311 options.gdpr.facebook_disabled_by_api || 3312 options.gdpr.cookiebot_integration_enabled || 3313 options.gdpr.cookie_notice_integration_enabled || 3314 options.gdpr.consent_magic_integration_enabled || 3315 options.gdpr.cookie_law_info_integration_enabled; 3316 // Update eventID 3317 3318 event.eventID = Utils.generateUniqueId(event); 3319 3320 if(Cookies.get('_fbp')){ 3321 params._fbp = Cookies.get('_fbp'); 3322 } 3323 if(Cookies.get('_fbc')){ 3324 params._fbc = Cookies.get('_fbc'); 3325 } 3326 // send event from server if they was bloc by gdpr or need send with delay 3327 if( options.ajaxForServerEvent || isApiDisabled ){ 3328 3329 var json = { 3330 action: 'pys_api_event', 3331 pixel: 'facebook', 3332 event: name, 3333 ids: ids, 3334 data:params, 3335 url:window.location.href, 3336 eventID:event.eventID, 3337 ajax_event:options.ajax_event 3338 }; 3339 3340 if(event.hasOwnProperty('woo_order')) { 3341 json['woo_order'] = event.woo_order; 3342 } 3343 3344 if(event.hasOwnProperty('edd_order')) { 3345 json['edd_order'] = event.edd_order; 3346 } 3347 3348 let delay = 0; 3349 Object.keys(sessionStorage).forEach((key) => { 3350 let value = sessionStorage.getItem(key); 3351 if ( key.startsWith( 'wc_fragments_' ) && event.e_id == 'woo_add_to_cart_on_button_click' ) { 3352 delay = 2000; 3353 } 3354 }); 3355 3356 if (event.e_id === "automatic_event_internal_link" || event.e_id === "automatic_event_outbound_link") { 3357 delay = delay === 0 ? 500 : delay; 3358 setTimeout(() => Utils.sendServerAjaxRequest(options.ajaxUrl, json), delay); 3359 } else if (event.type != 'static') { 3360 setTimeout(() => Utils.sendServerAjaxRequest(options.ajaxUrl, json), delay); 3361 } 3362 3363 if(event.type == 'static' && options.ajaxForServerStaticEvent) { 3364 setTimeout(() => Utils.sendServerAjaxRequest(options.ajaxUrl, json), delay); 3365 } 3366 } 3367 3368 if( event.e_id !== "automatic_event_signup" && name == "CompleteRegistration" && options.facebook.wooCRSendFromServer ) { 3369 return; 3370 } 3371 } 3372 3373 } 3374 delete params._fbp; 3375 delete params._fbc; 3376 if (options.debug) { 3377 console.log('[Facebook] ' + name, params,"pixel_ids",ids,"eventID",event.eventID); 3378 } 3379 // fire event for each pixel id 3380 ids.forEach(function (pixelId) { 3381 // add eventID for deduplicate events @see https://developers.facebook.com/docs/marketing-api/conversions-api/deduplicate-pixel-and-server-events/ 3382 var args = {}; 3383 if(options.facebook.serverApiEnabled && event.hasOwnProperty('eventID')) { 3384 args.eventID = event.eventID; 3385 } 3386 Facebook.maybeInitPixel(pixelId); 3387 fbq(actionType,pixelId, name, params,args); 3388 }); 3389 var customEvent = new CustomEvent('facebook_event_sent', { 3390 detail: { 3391 eventName: name, 3392 params: params, 3393 pixel_ids: ids 3394 } 3395 }); 3396 window.dispatchEvent(customEvent); 3397 } 3398 3399 /** 3400 * Public API 3401 */ 3402 return { 3403 tag: function() { 3404 return "facebook"; 3405 }, 3406 isEnabled: function () { 3407 return options.hasOwnProperty('facebook'); 3408 }, 3409 getHidePixel: function(){ 3410 if(this.isEnabled() && options.facebook.hasOwnProperty('hide_pixels')) 3411 { 3412 return options.facebook.hide_pixels; 3413 } 3414 return []; 3415 },
3416 initEventIdCookies: function (key) { 3417 var ids = {}; 3418 ids[key] = pys_generate_token(36) 3419 Cookies.set('pys_fb_event_id', JSON.stringify(ids), {path: '/',domain: domain}); 3420 }, 3421 3422 updateEventId:function(key) { 3423 var cooData = Cookies.get("pys_fb_event_id") 3424 if(cooData === undefined) { 3425 this.initEventIdCookies(key); 3426 } else { 3427 var data = JSON.parse(cooData); 3428 data[key] = pys_generate_token(36); 3429 Cookies.set('pys_fb_event_id', JSON.stringify(data), {path: '/',domain: domain} ); 3430 } 3431 }, 3432 3433 getEventId:function (key) { 3434 var data = Cookies.get("pys_fb_event_id"); 3435 if(data === undefined) { 3436 this.initEventIdCookies(key); 3437 data = Cookies.get("pys_fb_event_id"); 3438 } 3439 return JSON.parse(data)[key]; 3440 }, 3441 3442 disable: function () { 3443 initialized = false; 3444 }, 3445 3446 /** 3447 * Load pixel's JS 3448 */ 3449 loadPixel: function () { 3450 if (initialized || !this.isEnabled() || !Utils.consentGiven('facebook')) { 3451 return; 3452 } 3453 3454 ! function (f, b, e, v, n, t, s) { 3455 if (f.fbq) return; 3456 n = f.fbq = function () { 3457 n.callMethod ? 3458 n.callMethod.apply(n, arguments) : n.queue.push(arguments) 3459 }; 3460 if (!f._fbq) f._fbq = n; 3461 n.push = n; 3462 n.loaded = !0; 3463 n.version = '2.0'; 3464 n.agent = 'dvpixelyoursite'; 3465 n.queue = []; 3466 t = b.createElement(e); 3467 t.async = !0; 3468 t.src = v; 3469 s = b.getElementsByTagName(e)[0]; 3470 s.parentNode.insertBefore(t, s) 3471 }(window, 3472 document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); 3473 let expires = parseInt(options.cookie_duration); 3474 if(!Cookies.get('_fbp')) { 3475 Cookies.set('_fbp',genereateFbp(), { expires: expires,path: '/',domain: domain }); 3476 } 3477 3478 if(getUrlParameter('fbclid')) { 3479 Cookies.set('_fbc',genereateFbc(), { expires: expires,path: '/',domain: domain }); 3480 } 3481 var ids = options.facebook.pixelIds.filter(function (pixelId) { 3482 return !Utils.hideMatchingPixel(pixelId, 'facebook'); 3483 }); 3484 // initialize default pixel 3485 ids.forEach(function (pixelId) { 3486 Facebook.maybeInitPixel(pixelId); 3487 }); 3488 initialized = true; 3489 3490 Utils.fireStaticEvents('facebook'); 3491 3492 }, 3493 advancedMatching: function () { 3494 if(options.facebook.advancedMatchingEnabled) { 3495 let advancedMatchingForm = Utils.getAdvancedFormData(); 3496 let advancedMatching = {}; 3497 if(Object.keys(options.facebook.advancedMatching).length > 0) { 3498 advancedMatching = options.facebook.advancedMatching; 3499 } 3500 3501 if(!advancedMatching.hasOwnProperty("em") 3502 && advancedMatchingForm.hasOwnProperty("email") && advancedMatchingForm["email"].length > 0) { 3503 advancedMatching["em"] = advancedMatchingForm["email"]; 3504 } 3505 if(!advancedMatching.hasOwnProperty("ph") 3506 && advancedMatchingForm.hasOwnProperty("phone") && advancedMatchingForm["phone"].length > 0) { 3507 advancedMatching["ph"] = advancedMatchingForm["phone"]; 3508 } 3509 if(!advancedMatching.hasOwnProperty("fn") 3510 && advancedMatchingForm.hasOwnProperty("first_name") && advancedMatchingForm["first_name"].length > 0) { 3511 advancedMatching["fn"] = advancedMatchingForm["first_name"]; 3512 } 3513 if(!advancedMatching.hasOwnProperty("ln") 3514 && advancedMatchingForm.hasOwnProperty("last_name") && advancedMatchingForm["last_name"].length > 0) { 3515 advancedMatching["ln"] = advancedMatchingForm["last_name"]; 3516 } 3517 if(!advancedMatching.hasOwnProperty("external_id")){ 3518 if (Cookies.get('pbid')) { 3519 advancedMatching["external_id"] = Cookies.get('pbid'); 3520 } 3521 } 3522 else if(advancedMatching.hasOwnProperty("external_id") && advancedMatching.external_id != Cookies.get('pbid')) 3523 { 3524 advancedMatching["external_id"] = Cookies.get('pbid') ? Cookies.get('pbid') : advancedMatching.external_id; 3525 } 3526 3527 if(Object.keys(advancedMatching).length > 0) { 3528 return advancedMatching; 3529 } 3530 } 3531 return false 3532 }, 3533 maybeInitPixel: function(pixelId) { 3534 3535 if(configuredPixels.includes(pixelId)) return; 3536 3537 if (options.facebook.removeMetadata || Utils.hideMatchingPixel(pixelId, this.tag())) { 3538 fbq('set', 'autoConfig', false, pixelId); 3539 } 3540 let advancedMatching = Facebook.advancedMatching(); 3541 3542 if (options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined") { 3543 if(!advancedMatching) { 3544 fbq('init', pixelId); 3545 } else { 3546 var test_prefix = CS_Data.test_prefix; 3547 var cs_advanced_matching = Cookies.get('cs_enabled_advanced_matching'+test_prefix); 3548 if (jQuery('#cs_enabled_advanced_matching'+test_prefix).length > 0) { 3549 if (cs_advanced_matching == 'yes') { 3550 fbq('init', pixelId, advancedMatching); 3551 } else { 3552 fbq('init', pixelId); 3553 } 3554 } else { 3555 fbq('init', pixelId, advancedMatching); 3556 } 3557 } 3558 } else { 3559 if(!advancedMatching) { 3560 fbq('init', pixelId); 3561 } else { 3562 fbq('init', pixelId, advancedMatching); 3563 } 3564 } 3565 configuredPixels.push(pixelId); 3566 }, 3567 3568 fireEvent: function (name, data) { 3569 3570 if (!initialized || !this.isEnabled()) { 3571 return false; 3572 } 3573 3574 data.delay = data.delay || 0; 3575 data.params = data.params || {}; 3576 3577 if (data.delay === 0) { 3578 3579 fireEvent(name, data); 3580 3581 } else { 3582 3583 setTimeout(function (name, params) { 3584 fireEvent(name, params); 3585 }, data.delay * 1000, name, data); 3586 3587 } 3588 3589 return true; 3590 3591 }, 3592 3593 onAdSenseEvent: function (event) { 3594 this.fireEvent(event.name, event); 3595 }, 3596 3597 onClickEvent: function (event) { 3598 this.fireEvent(event.name, event); 3599 }, 3600 3601 onWatchVideo: function (event) { 3602 this.fireEvent(event.name, event); 3603 }, 3604 3605 onCommentEvent: function (event) { 3606 this.fireEvent(event.name, event); 3607 }, 3608 3609 onFormEvent: function (event) { 3610 this.fireEvent(event.name, event); 3611 }, 3612 3613 onDownloadEvent: function (event) { 3614 this.fireEvent(event.name, event); 3615 3616 }, 3617 3618 3619 onWooAddToCartOnButtonEvent: function (product_id) { 3620 3621 window.pysWooProductData = window.pysWooProductData || []; 3622 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 3623 return; 3624 3625 if (window.pysWooProductData.hasOwnProperty(product_id)) { 3626 if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { 3627 3628 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]) 3629 3630 Utils.copyProperties(window.pysWooProductData[product_id]['facebook']['params'], event.params) 3631 event.pixelIds = window.pysWooProductData[product_id]['facebook']['pixelIds']; 3632 this.fireEvent(event.name, event); 3633 } 3634 } 3635 }, 3636 3637 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, is_external, $form) { 3638 3639 window.pysWooProductData = window.pysWooProductData || []; 3640 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 3641 return; 3642 3643 if (product_type === Utils.PRODUCT_VARIABLE && !options.facebook.wooVariableAsSimple) { 3644 product_id = parseInt($form.find('input[name="variation_id"]').val()); 3645 } 3646 3647 if (window.pysWooProductData.hasOwnProperty(product_id)) { 3648 if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { 3649 3650 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click.facebook); 3651 3652 3653 Utils.copyProperties(window.pysWooProductData[product_id]['facebook']['params'], event.params); 3654 3655 var groupValue = 0; 3656 if(product_type === Utils.PRODUCT_GROUPED ) { 3657 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 3658 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 3659 var quantity = parseInt($(this).val()); 3660 if(isNaN(quantity)) { 3661 quantity = 0; 3662 } 3663 var childItem = window.pysWooProductData[product_id]['facebook'].grouped[childId]; 3664 3665 if(quantity == 0) { 3666 event.params.content_ids.forEach(function(el,index,array) { 3667 if(el == childItem.content_id) { 3668 array.splice(index, 1); 3669 } 3670 }); 3671 } 3672 3673 if(event.params.hasOwnProperty('contents')) { 3674 event.params.contents.forEac
3674h(function(el,index,array) { 3675 if(el.id == childItem.content_id) { 3676 if(quantity > 0){ 3677 el.quantity = quantity; 3678 } else { 3679 array.splice(index, 1); 3680 } 3681 } 3682 }); 3683 } 3684 3685 3686 groupValue += childItem.price * quantity; 3687 }); 3688 if(groupValue == 0) return; // skip if no items selected 3689 } 3690 3691 3692 3693 // maybe customize value option 3694 if (options.woo.addToCartOnButtonValueEnabled && options.woo.addToCartOnButtonValueOption !== 'global') { 3695 3696 if(product_type === Utils.PRODUCT_GROUPED) { 3697 event.params.value = groupValue; 3698 } else if(product_type === Utils.PRODUCT_BUNDLE) { 3699 var data = $(".bundle_form .bundle_data").data("bundle_form_data"); 3700 var items_sum = getBundlePriceOnSingleProduct(data); 3701 event.params.value = (parseFloat(data.base_price) + items_sum )* qty; 3702 } else { 3703 event.params.value = event.params.value * qty; 3704 } 3705 } 3706 3707 // only when non Facebook for WooCommerce logic used 3708 if (event.params.hasOwnProperty('contents') && product_type !== Utils.PRODUCT_GROUPED) { 3709 event.params.contents[0].quantity = qty; 3710 3711 } 3712 3713 var event_name = is_external ? options.woo.affiliateEventName : event.name; 3714 3715 this.fireEvent(event_name, event); 3716 3717 } 3718 } 3719 3720 }, 3721 3722 onWooRemoveFromCartEvent: function (event) { 3723 this.fireEvent(event.name, event); 3724 }, 3725 3726 onWooAffiliateEvent: function (product_id) { 3727 if(!options.dynamicEvents.woo_affiliate.hasOwnProperty(this.tag())) 3728 return; 3729 var event = Utils.clone(options.dynamicEvents.woo_affiliate[this.tag()]); 3730 3731 3732 if (window.pysWooProductData.hasOwnProperty(product_id)) { 3733 if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) { 3734 3735 Utils.copyProperties(window.pysWooProductData[product_id][this.tag()].params, event.params) 3736 this.fireEvent(options.woo.affiliateEventName, event); 3737 3738 } 3739 } 3740 3741 }, 3742 3743 onWooPayPalEvent: function (event) { 3744 this.fireEvent(event.name, event); 3745 }, 3746 3747 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 3748 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 3749 return; 3750 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 3751 3752 if (window.pysEddProductData.hasOwnProperty(download_id)) { 3753 3754 var index; 3755 3756 if (price_index) { 3757 index = download_id + '_' + price_index; 3758 } else { 3759 index = download_id; 3760 } 3761 3762 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 3763 if (window.pysEddProductData[download_id][index].hasOwnProperty('facebook')) { 3764 3765 Utils.copyProperties(window.pysEddProductData[download_id][index]['facebook']["params"], event.params) 3766 3767 // maybe customize value option 3768 if (options.edd.addToCartOnButtonValueEnabled && options.edd.addToCartOnButtonValueOption !== 'global') { 3769 event.params.value = event.params.value * qty; 3770 } 3771 3772 // update contents qty param 3773 var contents = event.params.contents; 3774 contents[0].quantity = qty; 3775 event.params.contents = contents; 3776 3777 this.fireEvent(event.name,event); 3778 3779 } 3780 } 3781 3782 } 3783 3784 }, 3785 3786 onEddRemoveFromCartEvent: function (event) { 3787 this.fireEvent(event.name, event); 3788 }, 3789 onPageScroll: function (event) { 3790 this.fireEvent(event.name, event); 3791 }, 3792 onTime: function (event) { 3793 this.fireEvent(event.name, event); 3794 }, 3795 }; 3796 3797 }(options); 3798 3799 var Analytics = function (options) { 3800 3801 var initialized = false; 3802 var isAllowEnhancedConversions = false; 3803 /** 3804 * Fires event 3805 * 3806 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data 3807 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/events 3808 * @link: https://developers.google.com/gtagjs/reference/event 3809 * @link: https://developers.google.com/gtagjs/reference/parameter 3810 * 3811 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dim
3811s-mets 3812 * 3813 * @param name 3814 * @param data 3815 */ 3816 function fireEvent(name, event) { 3817 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'ga')) { 3818 return; 3819 } 3820 3821 var eventParams = event.params; 3822 var valuesArray = Object.values(event.trackingIds); 3823 var ids = valuesArray.filter(function (pixelId) { 3824 return loadTags.some(loadTag => pixelId.startsWith(loadTag)) && !Utils.hideMatchingPixel(pixelId, 'ga') && !Utils.hideMatchingPixel(pixelId, 'google_ads'); 3825 }) 3826 3827 Utils.copyProperties(Utils.getRequestParams(), eventParams); 3828 var _fireEvent = function (tracking_ids,name,params) { 3829 3830 params['send_to'] = tracking_ids; 3831 if (options.debug) { 3832 console.log('[Google Analytics #' + tracking_ids + '] ' + name, params); 3833 } 3834 3835 gtag('event', name, params); 3836 3837 var customEvent = new CustomEvent('gtag_event_sent', { 3838 detail: { 3839 eventName: name, 3840 params: params, 3841 pixel_ids: tracking_ids 3842 } 3843 }); 3844 window.dispatchEvent(customEvent); 3845 3846 }; 3847 3848 var copyParams = Utils.copyProperties(eventParams, {}); // copy params because mapParamsTov4 can modify it 3849 3850 var params = mapParamsTov4(ids,name,copyParams) 3851 3852 params.event_id = Utils.generateUniqueId(event); 3853 3854 3855 delete params.analytics_storage; 3856 delete params.ad_storage; 3857 delete params.ad_user_data; 3858 delete params.ad_personalization; 3859 3860 _fireEvent(ids, name, params); 3861 isTrackEventForGA.push(name); 3862 3863 3864 3865 } 3866 3867 function normalizeEventName(eventName) { 3868 3869 var matches = { 3870 ViewContent: 'view_item', 3871 AddToCart: 'add_to_cart', 3872 AddToWishList: 'add_to_wishlist', 3873 InitiateCheckout: 'begin_checkout', 3874 Purchase: 'purchase', 3875 Lead: 'generate_lead', 3876 CompleteRegistration: 'sign_up', 3877 AddPaymentInfo: 'set_checkout_option' 3878 }; 3879 3880 return matches.hasOwnProperty(eventName) ? matches[eventName] : eventName; 3881 3882 } 3883 3884 function mapParamsTov4(tag,name,param) { 3885 //GA4 automatically collects a number of parameters for all events 3886 var hasGA4Tag = false; 3887 3888 // end 3889 if (Array.isArray(tag)) { 3890 hasGA4Tag = tag.some(function (element) { 3891 return isv4(element); 3892 }); 3893 } else if(isv4(tag)) { 3894 // tag ÑвлÑеÑÑÑ ÑÑÑокой и ÑооÑвеÑÑÑвÑÐµÑ GA4 3895 hasGA4Tag = true; 3896 } 3897 if(hasGA4Tag) { 3898 delete param.event_category; 3899 delete param.event_label; 3900 delete param.ecomm_prodid; 3901 delete param.ecomm_pagetype; 3902 delete param.ecomm_totalvalue; 3903 if(name === 'search') { 3904 param['search'] = param.search_term; 3905 delete param.search_term; 3906 delete param.dynx_itemid; 3907 delete param.dynx_pagetype; 3908 delete param.dynx_totalvalue; 3909 } 3910 } 3911 return param; 3912 } 3913 3914 function isv4(tag) { 3915 return tag.indexOf('G') === 0; 3916 } 3917 3918 /** 3919 * Public API 3920 */ 3921 return { 3922 tag: function() { 3923 return "ga"; 3924 }, 3925 isEnabled: function () { 3926 return options.hasOwnProperty('ga'); 3927 }, 3928 getHidePixel: function(){ 3929 if(this.isEnabled() && options.ga.hasOwnProperty('hide_pixels')) 3930 { 3931 return options.ga.hide_pixels; 3932 } 3933 return []; 3934 }, 3935 disable: function () { 3936 initialized = false; 3937 }, 3938 updateEnhancedConversionData : function () { 3939 if (!initialized || !this.isEnabled()) { 3940 return; 3941 } 3942 if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.hasOwnProperty("userDataEnable") && options.tracking_analytics.userDataEnable) { 3943 var advanced = Utils.getAdvancedMergeFormData(); 3944 if (Object.keys(advanced).length > 0) { 3945 gtag('set', 'user_data', advanced); 3946 } 3947 } 3948 }, 3949 loadPixel: function () { 3950 if (initialized || !this.isEnabled() || !Utils.consentGiven('analytics')) { 3951 return; 3952 } 3953 3954 3955 for (var i = 0; i < options.ga.trackingIds.length; i++) { 3956 var trackingId = options.ga.trackingIds[i]; 3957 if (!Utils.hideMatchingPixel(trackingId, 'ga')) { 3958 Utils.loadGoogleTag(trackingId); 3959 break; 3960 } 3961 } 3962 3963 var cd = { 3964 'dimension1': 'event_hour', 3965 'dimension2': 'event_day', 3966 'dimension3': 'event_month' 3967 }; 3968 3969 // configure Dynamic Remarketing CDs 3970 if (options.ga.retargetingLogic === 'ecomm') { 3971 cd.dimension4 = 'ecomm_prodid';
3972 cd.dimension5 = 'ecomm_pagetype'; 3973 cd.dimension6 = 'ecomm_totalvalue'; 3974 } else { 3975 cd.dimension4 = 'dynx_itemid'; 3976 cd.dimension5 = 'dynx_pagetype'; 3977 cd.dimension6 = 'dynx_totalvalue'; 3978 } 3979 3980 if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.hasOwnProperty("userDataEnable") && options.tracking_analytics.userDataEnable){ 3981 var advanced = Utils.getAdvancedMergeFormData(); 3982 if(Object.keys(advanced).length > 0){ 3983 gtag('set', 'user_data', advanced); 3984 } 3985 } 3986 3987 var config = { 3988 'custom_map': cd 3989 }; 3990 3991 if(options.user_id && options.user_id != 0) { 3992 config.user_id = options.user_id; 3993 } 3994 config.url_passthrough = options.ga.url_passthrough; 3995 // Cross-Domain tracking 3996 if (options.ga.crossDomainEnabled) { 3997 config.linker = { 3998 accept_incoming: options.ga.crossDomainAcceptIncoming, 3999 domains: options.ga.crossDomainDomains 4000 }; 4001 } 4002 4003 var ids = options.ga.trackingIds.filter(function (pixelId) { 4004 return !Utils.hideMatchingPixel(pixelId, 'ga'); 4005 }); 4006 loadTags.push(...ids); 4007 ids.forEach(function (trackingId,index) { 4008 4009 var obj = options.ga.isDebugEnabled; 4010 var searchValue = "index_"+index; 4011 var config_for_tag = Object.assign({}, config); 4012 config_for_tag.debug_mode = false; 4013 config_for_tag.send_page_view = !options.ga.custom_page_view_event; 4014 for (var key in obj) { 4015 if (obj[key] === searchValue) { 4016 config_for_tag.debug_mode = true; 4017 break; 4018 } 4019 } 4020 if(!config_for_tag.debug_mode) 4021 { 4022 delete config_for_tag.debug_mode; 4023 } 4024 4025 if(isv4(trackingId)) { 4026 if(options.ga.disableAdvertisingPersonalization) { 4027 config_for_tag.allow_ad_personalization_signals = false 4028 } 4029 } 4030 if(options.ga.hasOwnProperty('additionalConfig')){ 4031 if(options.ga.additionalConfig.hasOwnProperty(trackingId) && options.ga.additionalConfig[trackingId]){ 4032 config_for_tag.first_party_collection = options.ga.additionalConfig[trackingId].first_party_collection; 4033 } 4034 4035 } 4036 if(options.ga.hasOwnProperty('serverContainerUrls')){ 4037 if(options.ga.serverContainerUrls.hasOwnProperty(trackingId) && options.ga.serverContainerUrls[trackingId].enable_server_container != false){ 4038 if(options.ga.serverContainerUrls[trackingId].server_container_url != ''){ 4039 config_for_tag.server_container_url = options.ga.serverContainerUrls[trackingId].server_container_url; 4040 } 4041 if(options.ga.serverContainerUrls[trackingId].transport_url != ''){ 4042 config_for_tag.transport_url = options.ga.serverContainerUrls[trackingId].transport_url; 4043 } 4044 } 4045 } 4046 if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') { 4047 var cookiebot_consent_category = options.gdpr['cookiebot_analytics_consent_category']; 4048 if (options.gdpr['analytics_prior_consent_enabled']) { 4049 if (Cookiebot.consented === true && Cookiebot.consent[cookiebot_consent_category]) { 4050 gtag('config', trackingId, config_for_tag); 4051 } 4052 } else { 4053 if (Cookiebot.consent[cookiebot_consent_category]) { 4054 gtag('config', trackingId, config_for_tag); 4055 } 4056 } 4057 } 4058 else 4059 { 4060 gtag('config', trackingId, config_for_tag); 4061 } 4062 }); 4063 if(!isAdsLoad && GAds.isEnabled() && options.google_ads.conversion_ids.length > 0 && Utils.consentGiven('google_ads')) { 4064 for (var i = 0; i < options.google_ads.conversion_ids.length; i++) { 4065 var trackingId = options.google_ads.conversion_ids[i]; 4066 if (!Utils.hideMatchingPixel(trackingId, 'google_ads')) { 4067 Utils.loadGoogleTag(trackingId); 4068 break; 4069 } 4070 } 4071 var ids = options.google_ads.conversion_ids.filter(function (pixelId) { 4072 return !Utils.hideMatchingPixel(pixelId, 'google_ads'); 4073 }); 4074 loadTags.push(...ids); 4075 // configure conversion ids 4076 ids.forEach(function (conversion_id,index) { 4077 4078 gtag('config', conversion_id); 4079 4080 if(options.google_ads.enhanced_conversion.includes("index_"+index)) { 4081 isAllowEnhancedConversions = true 4082 gtag('config', conversion_id,{ 'allow_enhanced_conversions':true });
4083 } 4084 4085 }); 4086 isAdsLoad = true; 4087 } 4088 4089 4090 initialized = true; 4091 4092 Utils.fireStaticEvents('ga'); 4093 $( document).trigger( "analytics_initialized") 4094 }, 4095 4096 fireEvent: function (name, data) { 4097 4098 if (!initialized || !this.isEnabled()) { 4099 return false; 4100 } 4101 4102 data.delay = data.delay || 0; 4103 data.params = data.params || {}; 4104 4105 if (data.delay === 0) { 4106 4107 fireEvent(name, data); 4108 4109 } else { 4110 4111 setTimeout(function (name, params) { 4112 fireEvent(name, params); 4113 }, data.delay * 1000, name, data); 4114 4115 } 4116 4117 return true; 4118 4119 }, 4120 4121 onAdSenseEvent: function (event) { 4122 this.fireEvent(event.name, event); 4123 }, 4124 4125 onClickEvent: function (event) { 4126 this.fireEvent(event.name, event); 4127 }, 4128 4129 onWatchVideo: function (event) { 4130 if(!event.hasOwnProperty("youtube_disabled") 4131 || !event.youtube_disabled 4132 || event.params.video_type !== "youtube") { 4133 this.fireEvent(event.name, event); 4134 } 4135 }, 4136 4137 onCommentEvent: function (event) { 4138 4139 this.fireEvent(event.name, event); 4140 4141 }, 4142 4143 onFormEvent: function (event) { 4144 4145 this.fireEvent(event.name, event); 4146 4147 }, 4148 4149 onDownloadEvent: function (event) { 4150 4151 this.fireEvent(event.name, event); 4152 4153 }, 4154 4155 onWooAddToCartOnButtonEvent: function (product_id, prod_info = null) { 4156 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 4157 return; 4158 4159 if (window.pysWooProductData.hasOwnProperty(product_id)) { 4160 if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { 4161 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 4162 Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params) 4163 event.trackingIds = window.pysWooProductData[product_id]['ga']['trackingIds']; 4164 if(prod_info) 4165 { 4166 if(prod_info['pys_list_name_productlist_id']) 4167 { 4168 event.params.items[0]['item_list_id'] = prod_info['pys_list_name_productlist_id'] 4169 } 4170 if(prod_info['pys_list_name_productlist_name']) 4171 { 4172 event.params.items[0]['item_list_name'] =prod_info['pys_list_name_productlist_name'] 4173 } 4174 } 4175 this.fireEvent(event.name, event); 4176 } 4177 } 4178 4179 }, 4180 4181 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, is_external, $form, prod_info) { 4182 4183 window.pysWooProductData = window.pysWooProductData || []; 4184 4185 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 4186 return; 4187 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 4188 4189 if (product_type === Utils.PRODUCT_VARIABLE && !options.ga.wooVariableAsSimple) { 4190 product_id = parseInt($form.find('input[name="variation_id"]').val()); 4191 } 4192 4193 if (window.pysWooProductData.hasOwnProperty(product_id)) { 4194 if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { 4195 4196 Utils.copyProperties(window.pysWooProductData[product_id]['ga'].params, event.params); 4197 4198 4199 if(product_type === Utils.PRODUCT_GROUPED ) { 4200 var groupValue = 0; 4201 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 4202 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 4203 var quantity = parseInt($(this).val()); 4204 if(isNaN(quantity)) { 4205 quantity = 0; 4206 } 4207 var childItem = window.pysWooProductData[product_id]['ga'].grouped[childId];
4208 event.params.items.forEach(function(el,index,array) { 4209 if(el.id == childItem.content_id) { 4210 if(quantity > 0){ 4211 el.quantity = quantity; 4212 el.price = childItem.price; 4213 } else { 4214 array.splice(index, 1); 4215 } 4216 } 4217 }); 4218 groupValue += childItem.price * quantity; 4219 }); 4220 4221 if(options.woo.addToCartOnButtonValueEnabled && 4222 options.woo.addToCartOnButtonValueOption !== 'global' && 4223 event.params.hasOwnProperty('value')) { 4224 event.params.value = groupValue; 4225 } 4226 4227 if(groupValue == 0) return; // skip if no items selected 4228 } else { 4229 // update items qty param 4230 event.params.items[0].quantity = qty; 4231 } 4232 4233 // maybe customize value option 4234 if (options.woo.addToCartOnButtonValueEnabled && 4235 options.woo.addToCartOnButtonValueOption !== 'global' && 4236 product_type !== Utils.PRODUCT_GROUPED) 4237 { 4238 if(event.params.hasOwnProperty('value')) { 4239 event.params.value = event.params.items[0].price * qty; 4240 } 4241 } 4242 4243 if(prod_info) 4244 { 4245 if(prod_info['pys_list_name_productlist_id']) 4246 { 4247 event.params.items[0]['item_list_id'] = prod_info['pys_list_name_productlist_id'] 4248 } 4249 if(prod_info['pys_list_name_productlist_name']) 4250 { 4251 event.params.items[0]['item_list_name'] =prod_info['pys_list_name_productlist_name'] 4252 } 4253 } 4254 4255 var eventName = is_external ? options.woo.affiliateEventName : event.name; 4256 eventName = normalizeEventName(eventName); 4257 4258 this.fireEvent(eventName, event); 4259 4260 } 4261 } 4262 4263 }, 4264 4265 onWooCheckoutProgressStep: function (event) { 4266 this.fireEvent(event.name, event); 4267 }, 4268 4269 onWooSelectContent: function (event) { 4270 const select_prod_list = {}; 4271 4272 if (event.params.items[0].item_list_name !== undefined) { 4273 select_prod_list.list_name = event.params.items[0].item_list_name; 4274 } 4275 4276 if (event.params.items[0].item_list_id !== undefined) { 4277 select_prod_list.list_id = event.params.items[0].item_list_id; 4278 } 4279 const url = new URL(window.location.href); 4280 select_prod_list.url = url.origin + url.pathname; 4281 Cookies.set('select_prod_list', JSON.stringify(select_prod_list), { expires: 1,path: '/' }); 4282 this.fireEvent(event.name, event); 4283 }, 4284 4285 onWooRemoveFromCartEvent: function (event) { 4286 this.fireEvent(event.name, event); 4287 }, 4288 4289 onWooAffiliateEvent: function (product_id) { 4290 if(!options.dynamicEvents.woo_affiliate.hasOwnProperty(this.tag())) 4291 return; 4292 var event = options.dynamicEvents.woo_affiliate[this.tag()]; 4293 4294 if (window.pysWooProductData.hasOwnProperty(product_id)) { 4295 if (window.pysWooProductData[product_id].hasOwnProperty('ga')) { 4296 4297 event = Utils.clone(event ); 4298 Utils.copyProperties(window.pysWooProductData[product_id][this.tag()], event.params) 4299 this.fireEvent(normalizeEventName(options.woo.affiliateEventName), event); 4300 4301 } 4302 } 4303 4304 }, 4305 4306 onWooPayPalEvent: function (event) { 4307 this.fireEvent(event.name, event); 4308 }, 4309 4310 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 4311 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 4312 return; 4313 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 4314 4315 4316 if (window.pysEddProductData.hasOwnProperty(download_id)) { 4317 4318 var index; 4319 4320 if (price_index) { 4321 index = download_id + '_' + price_index; 4322 } else { 4323 index = download_id; 4324 } 4325 4326 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 4327 if (window.pysEddProductData[download_id][index].hasOwnProperty('ga')) { 4328 4329 Utils.copyProperties(window.pysEddProductData[download_id][index]['ga'].params, event.params); 4330 4331 // update items qty param 4332 event.params.items[0].quantity = qty; 4333 4334 this.fireEvent(event.name,event); 4335 4336 } 4337 } 4338 4339 } 4340 4341 }, 4342 4343 onEddRemoveFromCartEvent: function (event) { 4344 this.fireEvent(event.name, event); 4345 }, 4346 4347 onPageScroll: function (event) { 4348 if (initialized && this.isEnabled()) { 4349 this.fireEvent(event.name, event); 4350 } 4351 }, 4352 onTime: function (event) { 4353 if (initialized && this.isEnabled()) { 4354 this.fireEvent(event.name, event); 4355 } 4356 }, 4357 }; 4358 4359 }(options); 4360 4361 var GAds = function (options) { 4362 4363 var initialized = false; 4364 var isAllowEnhancedConversions = false 4365 /** 4366 * Fires event 4367 * 4368 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data 4369 * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/events 4370 * @link: https://developers.google.com/gtagjs/reference/event 4371 * @link: https://developers.google.com/gtagjs/reference/parameter 4372 */ 4373 function fireEvent(name, data) { 4374 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(event_name,'google_ads')) { 4375 return; 4376 } 4377 var _params = Utils.copyProperties(data.params,{}); 4378 4379 _params.event_id = Utils.generateUniqueId(data); 4380 4381 var ids = data.ids.filter(function (pixelId) { 4382 return !Utils.hideMatchingPixel(pixelId, 'google_ads'); 4383 }); 4384 4385 var conversionIds = data.hasOwnProperty('conversion_ids') ? data.conversion_ids.filter(function (conversion_id) { 4386 return !Utils.hideMatchingPixel(conversion_id, 'google_ads'); 4387 }) : []; 4388 var conversion_labels = data.hasOwnProperty('conversion_labels') ? data.conversion_labels.filter(function (conversion_label) { 4389 conversion_id = conversion_label.split('/')[0]; 4390 return !Utils.hideMatchingPixel(conversion_id, 'google_ads'); 4391 }) : []; 4392
4393 Utils.copyProperties(Utils.getRequestParams(), _params); 4394 var _fireEvent = function (conversion_id,event_name) { 4395 4396 params = Utils.copyProperties(_params, { send_to: conversion_id }); 4397 4398 if("conversion" === event_name) { 4399 delete params.items; 4400 delete params.ecomm_pagetype; 4401 delete params.ecomm_prodid; 4402 delete params.ecomm_totalvalue; 4403 } 4404 4405 if (options.debug) { 4406 console.log('[Google Ads #' + conversion_id + '] ' + event_name, params); 4407 } 4408 gtag('event', event_name, params); 4409 var customEvent = new CustomEvent('gtag_event_sent', { 4410 detail: { 4411 eventName: event_name, 4412 params: params, 4413 pixel_ids: conversion_id 4414 } 4415 }); 4416 window.dispatchEvent(customEvent); 4417 4418 }; 4419 4420 4421 if ( conversion_labels.length > 0 ) { 4422 ids = conversion_labels; 4423 if ( !isTrackEventForGA.includes( name ) ) { 4424 _fireEvent( ids, name ); 4425 } 4426 } else { 4427 var conversion_event_name = data.e_id; 4428 switch ( conversion_event_name ) { 4429 case "woo_add_to_cart_on_cart_page": 4430 case "woo_add_to_cart_on_checkout_page": 4431 case "woo_add_to_cart_on_button_click": 4432 conversion_event_name = 'woo_add_to_cart'; 4433 break; 4434 case "edd_add_to_cart_on_cart_page": 4435 case "edd_add_to_cart_on_checkout_page": 4436 case "edd_add_to_cart_on_button_click": 4437 conversion_event_name = 'edd_add_to_cart'; 4438 break; 4439 case "automatic_event_adsense": 4440 case "automatic_event_comment": 4441 case "automatic_event_download": 4442 case "automatic_event_email_link": 4443 case "automatic_event_form": 4444 case "automatic_event_internal_link": 4445 case "automatic_event_outbound_link": 4446 case "automatic_event_scroll": 4447 case "automatic_event_tel_link": 4448 case "automatic_event_time_on_page": 4449 case "automatic_event_video": 4450 conversion_event_name = 'automatic_event'; 4451 break; 4452 } 4453 4454 if ( ids.length ) { 4455 if ( conversion_event_name !== 'automatic_event' && options.google_ads[ conversion_event_name + '_conversion_track' ] ) { 4456 const conversionTrack = options.google_ads[ conversion_event_name + '_conversion_track' ]; 4457 4458 if ( conversionTrack === 'conversion' ) { 4459 _fireEvent( ids, "conversion" ); 4460 } 4461 } 4462 4463 } else { 4464 ids = conversionIds; 4465 } 4466 4467 if ( !isTrackEventForGA.includes( name ) ) { 4468 _fireEvent( ids, name ); 4469 } 4470 } 4471 } 4472 4473 function normalizeEventName(eventName) { 4474 4475 var matches = { 4476 ViewContent: 'view_item', 4477 AddToCart: 'add_to_cart', 4478 AddToWishList: 'add_to_wishlist', 4479 InitiateCheckout: 'begin_checkout', 4480 Purchase: 'purchase', 4481 Lead: 'generate_lead', 4482 CompleteRegistration: 'sign_up', 4483 AddPaymentInfo: 'set_checkout_option' 4484 }; 4485 4486 return matches.hasOwnProperty(eventName) ? matches[eventName] : eventName; 4487 4488 } 4489 4490 /** 4491 * Public API 4492 */ 4493 return { 4494 tag: function() { 4495 return "google_ads"; 4496 }, 4497 isEnabled: function () { 4498 return options.hasOwnProperty('google_ads'); 4499 }, 4500 getHidePixel: function(){ 4501 if(this.isEnabled() && options.google_ads.hasOwnProperty('hide_pixels')) 4502 { 4503 return options.google_ads.hide_pixels; 4504 } 4505 return []; 4506 }, 4507 disable: function () { 4508 initialized = false; 4509 }, 4510 4511 updateEnhancedConversionData : function () { 4512 4513 if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.hasOwnProperty("userDataEnable") && options.tracking_analytics.userDataEnable){ 4514 var advanced = Utils.getAdvancedMergeFormData() 4515 gtag('set', 'user_data', advanced); 4516 } 4517 }, 4518 4519 loadPixel: function () { 4520 4521 if (initialized || !this.isEnabled() || !Utils.consentGiven('google_ads')) { 4522 return; 4523 } 4524 var ids = options.google_ads.conversion_ids.filter(function (pixelId) { 4525 return !Utils.hideMatchingPixel(pixelId, 'google_ads'); 4526 }); 4527 loadTags.push(...ids); 4528 if(!isAdsLoad && options.google_ads.conversion_ids.length > 0){ 4529 for (var i = 0; i < options.google_ads.conversion_ids.length; i++) { 4530 var trackingId = options.google_ads.conversion_ids[i]; 4531 if (!Utils.hideMatchingPixel(trackingId, 'google_ads')) { 4532 Utils.loadGoogleTag(trackingId); 4533 break; 4534 } 4535 } 4536 4537 // configure conversion ids 4538 ids.forEach(function (conversion_id,index) { 4539 4540 let config = {}; 4541 4542 if(options.google_ads.enhanced_conversion.includes("index_"+index)) { 4543 isAllowEnhancedConversions = true; 4544 config.allow_enhanced_conversions = true 4545 } 4546 4547 // Cross-Domain tracking 4548 if (options.google_ads.crossDomainEnabled) { 4549 config.linker = { 4550 accept_incoming: options.google_ads.crossDomainAcceptIncoming, 4551 domains: options.google_ads.crossDomainDomains 4552 }; 4553 } 4554 4555 gtag('config', conversion_id, config ); 4556 4557 if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.hasOwnProperty("userDataEnable") && options.tracking_analytics.userDataEnableuserDataEnable){ 4558 var advanced = Utils.getAdvancedMergeFormData() 4559 gtag('set', 'user_data', advanced); 4560 } 4561 4562 }); 4563 isAdsLoad = true; 4564 } 4565 4566 initialized = true; 4567 4568 Utils.fireStaticEvents('google_ads'); 4569 4570 }, 4571 4572 fireEvent: function (name, data) { 4573 4574 if (!initialized || !this.isEnabled()) { 4575 return false; 4576 } 4577 4578 data.delay = data.delay || 0; 4579 data.params = data.params || {}; 4580 data.ids = data.ids || []; 4581 data.conversion_labels = data.conversion_labels || []; 4582 4583 if (data.delay === 0) { 4584 fireEvent(name, data); 4585 } else { 4586 setTimeout(function (name, data) { 4587 fireEvent(name, data); 4588 }, data.delay * 1000, name, data); 4589 } 4590 4591 return true; 4592 4593 }, 4594 4595 onAdSenseEvent: function (event) { 4596 this.fireEvent(event.name, event); 4597 }, 4598 4599 onClickEvent: function (action, params) { 4600 //disabled 4601 }, 4602 4603 onWatchVideo: function (event) { 4604 this.fireEvent(event.name, event); 4605 }, 4606 4607 onCommentEvent: function (event) { 4608 this.fireEvent(event.name, event); 4609 }, 4610 4611 onFormEvent: function (event) { 4612 this.fireEvent(event.name, event); 4613 }, 4614 4615 onDownloadEvent: function (event) { 4616 this.fireEvent(event.name, event); 4617 }, 4618 4619 4620 4621 4622 onWooAddToCartOnButtonEvent: function (product_id) { 4623 4624 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 4625 return; 4626 4627 if (window.pysWooProductData.hasOwnProperty(product_id)) { 4628 if (window.pysWooProductData[product_id].hasOwnProperty('google_ads')) { 4629 4630 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]) 4631 Utils.copyProperties(window.pysWooProductData[product_id]['google_ads']['params'].params, event.params) 4632 event["ids"] = window.pysWooProductData[product_id]['google_ads']['ids'] 4633 event["conversion_labels"] = window.pysWooProductData[product_id]['google_ads']['conversion_labels'] 4634 this.fireEvent(event.name, event); 4635 } 4636 } 4637 4638 }, 4639 4640 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, is_external, $form) { 4641 4642 window.pysWooProductData = window.pysWooProductData || []; 4643 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 4644 return; 4645 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 4646 4647 if (product_type === Utils.PRODUCT_VARIABLE && !options.google_ads.wooVariableAsSimple) { 4648 product_id = parseInt($form.find('input[name="variation_id"]').val()); 4649 } 4650 4651 if (window.pysWooProductData.hasOwnProperty(product_id)) { 4652 if (window.pysWooProductData[product_id].hasOwnProperty('google_ads')) { 4653 4654 Utils.copyProperties(window.pysWooProductData[product_id]['google_ads']["params"], event.params); 4655 event["ids"] = window.pysWooProductData[product_id]['google_ads']['ids'] 4656 event["conversion_labels"] = window.pysWooProductData[product_id]['google_ads']['conversion_labels'] 4657 4658 var groupValue = 0; 4659 if(product_type === Utils.PRODUCT_GROUPED ) { 4660 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 4661 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 4662 var quantity = parseInt($(this).val()); 4663 if(isNaN(quantity)) { 4664 quantity = 0; 4665 } 4666 4667 var childItem = window.pysWooProductData[product_id]['google_ads'].grouped[childId]; 4668 4669 if(options.woo.addToCartOnButtonValueEnabled && 4670 options.woo.addToCartOnButtonValueOption !== 'global') { 4671
4672 event.params.items.forEach(function(el,index,array) { 4673 if(el.id == childItem.content_id) { 4674 if(quantity > 0){ 4675 el.quantity = quantity; 4676 el.price = childItem.price; 4677 } else { 4678 array.splice(index, 1); 4679 } 4680 } 4681 }); 4682 } 4683 groupValue += childItem.price * quantity; 4684 }); 4685 if(groupValue == 0) return; 4686 event.params.value = groupValue; 4687 } else { 4688 // update items qty param 4689 event.params.items[0].quantity = qty; 4690 } 4691 4692 4693 4694 // maybe customize value option 4695 if (options.woo.addToCartOnButtonValueEnabled && 4696 options.woo.addToCartOnButtonValueOption !== 'global' && 4697 product_type !== Utils.PRODUCT_GROUPED) { 4698 event.params.value = event.params.value * qty; 4699 } 4700 4701 4702 4703 var eventName = is_external ? options.woo.affiliateEventName : event.name; 4704 eventName = normalizeEventName(eventName); 4705 4706 this.fireEvent(eventName, event); 4707 4708 } 4709 } 4710 4711 }, 4712 4713 onWooRemoveFromCartEvent: function (event) { 4714 this.fireEvent(event.name, event); 4715 }, 4716 4717 onWooAffiliateEvent: function (product_id) { 4718 if(!options.dynamicEvents.woo_affiliate.hasOwnProperty(this.tag())) 4719 return; 4720 var event = options.dynamicEvents.woo_affiliate[this.tag()]; 4721 4722 if (window.pysWooProductData.hasOwnProperty(product_id)) { 4723 if (window.pysWooProductData[product_id].hasOwnProperty('google_ads')) { 4724 4725 event = Utils.clone(event) 4726 Utils.copyProperties(window.pysWooProductData[product_id][this.tag()], event.params) 4727 this.fireEvent(normalizeEventName(options.woo.affiliateEventName), event); 4728 4729 } 4730 } 4731 4732 }, 4733 4734 onWooPayPalEvent: function (event) { 4735 this.fireEvent(event.name, event); 4736 }, 4737 4738 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 4739 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 4740 return; 4741 var event = options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]; 4742 4743 4744 if (window.pysEddProductData.hasOwnProperty(download_id)) { 4745 4746 var index; 4747 4748 if (price_index) { 4749 index = download_id + '_' + price_index; 4750 } else { 4751 index = download_id; 4752 } 4753 4754 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 4755 if (window.pysEddProductData[download_id][index].hasOwnProperty('google_ads')) { 4756 4757 event = Utils.clone(event) 4758 Utils.copyProperties(window.pysEddProductData[download_id][index]['google_ads']['params'], event.params); 4759 event.ids = window.pysEddProductData[download_id][index]['google_ads']['ids'] 4760 // update items qty param 4761 //params.items[0].quantity = qty; 4762 4763 this.fireEvent(event.name, event); 4764 4765 } 4766 } 4767 4768 } 4769 4770 }, 4771 4772 onEddRemoveFromCartEvent: function (event) { 4773 this.fireEvent(event.name, event); 4774 }, 4775 onPageScroll: function (event) { 4776 if (initialized && this.isEnabled()) { 4777 this.fireEvent(event.name, event); 4778 } 4779 }, 4780 onTime: function (event) { 4781 if (initialized && this.isEnabled()) { 4782 this.fireEvent(event.name, event); 4783 } 4784 }, 4785 4786 }; 4787 4788 }(options); 4789 4790 var GTM = function (options) { 4791 4792 var initialized = false; 4793 4794 var datalayer_name = 'dataLayer'; 4795 /* 4796 * @param name 4797 * @param data 4798 */ 4799 function fireEvent(name, event) { 4800 if(typeof window.pys_event_data_filter === "function" && window.pys_disable_event_filter(name,'gtm')) { 4801 return; 4802 } 4803 4804
4805 var eventParams = event.params; 4806 var data = event.params; 4807 var valuesArray = Object.values(event.trackingIds); 4808 var ids = valuesArray.filter(function (pixelId) { 4809 return !Utils.hideMatchingPixel(pixelId, 'gtm'); 4810 }) 4811 Utils.copyProperties(Utils.getRequestParams(), eventParams); 4812 var _fireEvent = function (tracking_id,name,params, event=null) { 4813 4814 var eventData = {}; 4815 var ContainerCodeHasTag = !options.gtm.gtm_just_data_layer && tracking_id.length > 0; 4816 if(ContainerCodeHasTag) { 4817 params['send_to'] = tracking_id; 4818 } 4819 else if(!options.gtm.gtm_just_data_layer){ 4820 return 4821 } 4822 4823 if (params.hasOwnProperty('ecommerce')) { 4824 eventData.ecommerce = params.ecommerce; 4825 delete params.ecommerce; 4826 } 4827 4828 var automatedParams = { ...params }; 4829 [params['manualName'], 'manualName', 'triggerType'].forEach(key => delete automatedParams[key]); 4830 if(event && (!event.hasOwnProperty('hasAutoParam') || (event.hasOwnProperty('hasAutoParam') && event.hasAutoParam))) { 4831 eventData.automatedParameters = automatedParams; 4832 } 4833 4834// Move custom parameters to eventData 4835 4836 if (params.hasOwnProperty(params['manualName'])) { 4837 eventData[params['manualName']] = params[params['manualName']]; 4838 delete params[params['manualName']]; 4839 } 4840 4841 ['manualName','triggerType'].forEach(key => { 4842 if (params.hasOwnProperty(key)) { 4843 eventData[key] = params[key]; 4844 delete params[key]; 4845 } 4846 }); 4847 4848 eventData.manualDataLayer = options.gtm.gtm_dataLayer_name ?? 'dataLayer'; 4849 4850 eventData.event = name; 4851 4852 if (options.debug) { 4853 if (ContainerCodeHasTag){ 4854 console.log('[Google GTM #' + tracking_id + '] ' + name, eventData); 4855 } 4856 else { 4857 console.log('[Google GTM push to "'+datalayer_name+'"] ' + name, eventData); 4858 } 4859 } 4860 window[datalayer_name].push(eventData); 4861 4862 var customEvent = new CustomEvent('gtm_event_sent', { 4863 detail: { 4864 eventName: name, 4865 params: eventData, 4866 pixel_ids: tracking_id 4867 } 4868 }); 4869 window.dispatchEvent(customEvent); 4870 4871 }; 4872 4873 var copyParams = Utils.copyProperties(eventParams, {}); // copy params because mapParamsToGTM can modify it 4874 4875 var params = mapParamsToGTM(ids,name,copyParams) 4876 4877 params.event_id = Utils.generateUniqueId(event); 4878 4879 _fireEvent(ids, name, params, event); 4880 } 4881 4882 function normalizeEventName(eventName) { 4883 4884 var matches = { 4885 ViewContent: 'view_item', 4886 AddToCart: 'add_to_cart', 4887 AddToWishList: 'add_to_wishlist', 4888 InitiateCheckout: 'begin_checkout', 4889 Purchase: 'purchase', 4890 Lead: 'generate_lead', 4891 CompleteRegistration: 'sign_up', 4892 AddPaymentInfo: 'set_checkout_option' 4893 }; 4894 4895 return matches.hasOwnProperty(eventName) ? matches[eventName] : eventName; 4896 4897 } 4898 4899 function mapParamsToGTM(tag,name,param) { 4900 var hasGTM = false; 4901 4902 // end 4903 if (Array.isArray(tag)) { 4904 hasGTM = tag.some(function (element) { 4905 return isGTM(element); 4906 }); 4907 } else if(isGTM(tag)) { 4908 hasGTM = true; 4909 } 4910 if(hasGTM) { 4911 delete param.event_category; 4912 delete param.event_label; 4913 4914 delete param.analytics_storage; 4915 delete param.ad_storage; 4916 delete param.ad_user_data; 4917 delete param.ad_personalization; 4918 4919 if(name === 'search') { 4920 param['search'] = param.search_term; 4921 delete param.search_term; 4922 delete param.dynx_itemid; 4923 delete param.dynx_pagetype; 4924 delete param.dynx_totalvalue; 4925 } 4926 } 4927 return param; 4928 } 4929 4930 function isGTM(tag) { 4931 return tag.indexOf('GTM') === 0; 4932 } 4933 /** 4934 * Public API 4935 */ 4936 return { 4937 tag: function() { 4938 return "gtm"; 4939 }, 4940 isEnabled: function () { 4941 return options.hasOwnProperty('gtm'); 4942 }, 4943 getHidePixel: function(){ 4944 if(this.isEnabled() && options.gtm.hasOwnProperty('hide_pixels')) 4945 { 4946 return options.gtm.hide_pixels; 4947 } 4948 return []; 4949 }, 4950 disable: function () { 4951 initialized = false; 4952 }, 4953 updateEnhancedConversionData : function () { 4954 if (!initialized || !this.isEnabled()) { 4955 return; 4956 } 4957 if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.hasOwnProperty("userDataEnable") && options.tracking_analytics.userDataEnable) { 4958 var advanced = Utils.getAdvancedMergeFormData(true); 4959 if (Object.keys(advanced).length > 0) { 4960 window[datalayer_name].push({'user_data' : advanced}); 4961 } 4962 } 4963 }, 4964 loadPixel: function () { 4965 4966 if (initialized || !this.isEnabled() || !Utils.consentGiven('analytics')) { 4967 return; 4968 } 4969 datalayer_name = options.gtm.gtm_dataLayer_name ?? 'dataLayer'; 4970 4971 for (var i = 0; i < options.gtm.trackingIds.length; i++) { 4972 var trackingId = options.gtm.trackingIds[i]; 4973 if (!Utils.hideMatchingPixel(trackingId, 'gtm') && !options.gtm.gtm_just_data_layer) { 4974 console.log('[PYS] Google Tag Manager container code loaded'); 4975 Utils.loadGTMScript(trackingId); 4976 break; 4977 } 4978 } 4979 if(options.gtm.gtm_just_data_layer) { 4980 console.warn && console.warn("[PYS] Google Tag Manager container code placement set to OFF !!!"); 4981 console.warn && console.warn("[PYS] Data layer codes are active but GTM container must be loaded using custom coding !!!"); 4982 } 4983 4984 if(options.hasOwnProperty("tracking_analytics") && options.tracking_analytics.hasOwnProperty("userDataEnable") && options.tracking_analytics.userDataEnable){ 4985 var advanced = Utils.getAdvancedMergeFormData(true); 4986 if(Object.keys(advanced).length > 0){ 4987 window[datalayer_name].push({'user_data' : advanced}); 4988 } 4989 } 4990 4991 4992 var config = {}; 4993 4994 if(options.user_id && options.user_id != 0) { 4995 config.user_id = options.user_id; 4996 } 4997 4998 // Cross-Domain tracking 4999 5000 var ids = options.gtm.trackingIds.filter(function (pixelId) { 5001 return !Utils.hideMatchingPixel(pixelId, 'gtm'); 5002 }); 5003 5004 5005 initialized = true; 5006 5007 Utils.fireStaticEvents('gtm'); 5008 }, 5009 5010 fireEvent: function (name, data) { 5011 5012 if (!initialized || !this.isEnabled()) { 5013 return false; 5014 } 5015 5016 data.delay = data.delay || 0; 5017 data.params = data.params || {}; 5018 5019 if (data.delay === 0) { 5020 5021 fireEvent(name, data); 5022 5023 } else { 5024 5025 setTimeout(function (name, params) { 5026 fireEvent(name, params); 5027 }, data.delay * 1000, name, data); 5028 5029 } 5030 5031 return true; 5032 5033 }, 5034 5035 onAdSenseEvent: function (event) { 5036 this.fireEvent(event.name, event); 5037 }, 5038 5039 onClickEvent: function (event) { 5040 this.fireEvent(event.name, event); 5041 }, 5042 5043 onWatchVideo: function (event) { 5044 if(!event.hasOwnProperty("youtube_disabled") 5045 || !event.youtube_disabled 5046 || event.params.video_type !== "youtube") { 5047 this.fireEvent(event.name, event); 5048 } 5049 }, 5050 5051 onCommentEvent: function (event) { 5052 5053 this.fireEvent(event.name, event); 5054 5055 }, 5056 5057 onFormEvent: function (event) { 5058 5059 this.fireEvent(event.name, event); 5060 5061 }, 5062 5063 onDownloadEvent: function (event) { 5064 5065 this.fireEvent(event.name, event); 5066 5067 }, 5068 5069 onWooAddToCartOnButtonEvent: function (product_id, prod_info = null) { 5070 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 5071 return; 5072 if (window.pysWooProductData.hasOwnProperty(product_id)) { 5073 if (window.pysWooProductData[product_id].hasOwnProperty('gtm')) { 5074 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 5075 Utils.copyProperties(window.pysWooProductData[product_id]['gtm'].params, event.params) 5076 event.trackingIds = window.pysWooProductData[product_id]['gtm']['trackingIds']; 5077 5078 5079 if(prod_info) 5080 { 5081 item = event.params.hasOwnProperty('ecommerce') ? event.params.ecommerce.items[0] : event.params.items[0]; 5082 5083 if(prod_info['pys_list_name_productlist_id']) 5084 { 5085 item['item_list_id'] = prod_info['pys_list_name_productlist_id'] 5086 } 5087 if(prod_info['pys_list_name_productlist_name']) 5088 { 5089 item['item_list_name'] =prod_info['pys_list_name_productlist_name'] 5090 } 5091 } 5092 this.fireEvent(event.name, event); 5093 } 5094 } 5095 5096 }, 5097 5098 onWooAddToCartOnSingleEvent: function (product_id, qty, product_type, is_external, $form, prod_info) { 5099 window.pysWooProductData = window.pysWooProductData || []; 5100 5101 if(!options.dynamicEvents.woo_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 5102 return; 5103 var event = Utils.clone(options.dynamicEvents.woo_add_to_cart_on_button_click[this.tag()]); 5104 5105 if (product_type === Utils.PRODUCT_VARIABLE && !options.gtm.wooVariableAsSimple) { 5106 product_id = parseInt($form.find('input[name="variation_id"]').val()); 5107 } 5108 5109 if (window.pysWooProductData.hasOwnProperty(product_id)) { 5110 if (window.pysWooProductData[product_id].hasOwnProperty('gtm')) { 5111 5112 Utils.copyProperties(window.pysWooProductData[product_id]['gtm'].params, event.params); 5113 5114 params = event.params.hasOwnProperty('ecommerce') ? event.params.ecommerce : event.params; 5115 5116 if(product_type === Utils.PRODUCT_GROUPED ) { 5117 var groupValue = 0; 5118 $form.find(".woocommerce-grouped-product-list .qty").each(function(index){ 5119 var childId = $(this).attr('name').replaceAll("quantity[","").replaceAll("]",""); 5120 var quantity = parseInt($(this).val()); 5121 if(isNaN(quantity)) { 5122 quantity = 0; 5123 } 5124 var childItem = window.pysWooProductData[product_id]['gtm'].grouped[childId]; 5125
5126 params.items.forEach(function(el,index,array) { 5127 if(el.id == childItem.content_id) { 5128 if(quantity > 0){ 5129 el.quantity = quantity; 5130 el.price = childItem.price; 5131 } else { 5132 array.splice(index, 1); 5133 } 5134 } 5135 }); 5136 groupValue += childItem.price * quantity; 5137 }); 5138 5139 5140 5141 if(options.woo.addToCartOnButtonValueEnabled && 5142 options.woo.addToCartOnButtonValueOption !== 'global' && 5143 params.hasOwnProperty('value')) { 5144 params.value = groupValue; 5145 } 5146 5147 if(groupValue == 0) return; // skip if no items selected 5148 } else { 5149 // update items qty param 5150 params.items[0].quantity = qty; 5151 } 5152 5153 // maybe customize value option 5154 if (options.woo.addToCartOnButtonValueEnabled && 5155 options.woo.addToCartOnButtonValueOption !== 'global' && 5156 product_type !== Utils.PRODUCT_GROUPED) 5157 { 5158 if(params.hasOwnProperty('value')) { 5159 params.value = params.items[0].price * qty; 5160 } 5161 } 5162 5163 if(prod_info) 5164 { 5165 if(prod_info['pys_list_name_productlist_id']) 5166 { 5167 params.items[0]['item_list_id'] = prod_info['pys_list_name_productlist_id'] 5168 } 5169 if(prod_info['pys_list_name_productlist_name']) 5170 { 5171 params.items[0]['item_list_name'] =prod_info['pys_list_name_productlist_name'] 5172 } 5173 } 5174 5175 var eventName = is_external ? options.woo.affiliateEventName : event.name; 5176 eventName = normalizeEventName(eventName); 5177 5178 this.fireEvent(eventName, event); 5179 5180 } 5181 } 5182 5183 }, 5184 5185 onWooCheckoutProgressStep: function (event) { 5186 this.fireEvent(event.name, event); 5187 }, 5188 5189 onWooSelectContent: function (event) { 5190 const select_prod_list = {}; 5191 5192 if (event.params.items[0].item_list_name !== undefined) { 5193 select_prod_list.list_name = event.params.items[0].item_list_name; 5194 } 5195 5196 if (event.params.items[0].item_list_id !== undefined) { 5197 select_prod_list.list_id = event.params.items[0].item_list_id; 5198 } 5199 const url = new URL(window.location.href); 5200 select_prod_list.url = url.origin + url.pathname; 5201 Cookies.set('select_prod_list', JSON.stringify(select_prod_list), { expires: 1,path: '/' }); 5202 this.fireEvent(event.name, event); 5203 }, 5204 5205 onWooRemoveFromCartEvent: function (event) { 5206 this.fireEvent(event.name, event); 5207 }, 5208 5209 onWooAffiliateEvent: function (product_id) { 5210 if(!options.dynamicEvents.woo_affiliate.hasOwnProperty(this.tag())) 5211 return; 5212 var event = options.dynamicEvents.woo_affiliate[this.tag()]; 5213 5214 if (window.pysWooProductData.hasOwnProperty(product_id)) { 5215 if (window.pysWooProductData[product_id].hasOwnProperty('gtm')) { 5216 5217 event = Utils.clone(event ); 5218 Utils.copyProperties(window.pysWooProductData[product_id][this.tag()], event.params) 5219 this.fireEvent(normalizeEventName(options.woo.affiliateEventName), event); 5220 5221 } 5222 } 5223 5224 }, 5225 5226 onWooPayPalEvent: function (event) { 5227 this.fireEvent(event.name, event); 5228 }, 5229 5230 onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) { 5231 if(!options.dynamicEvents.edd_add_to_cart_on_button_click.hasOwnProperty(this.tag())) 5232 return; 5233 var event = Utils.clone(options.dynamicEvents.edd_add_to_cart_on_button_click[this.tag()]); 5234 5235 5236 if (window.pysEddProductData.hasOwnProperty(download_id)) { 5237 5238 var index; 5239 5240 if (price_index) { 5241 index = download_id + '_' + price_index; 5242 } else { 5243 index = download_id; 5244 } 5245 5246 if (window.pysEddProductData[download_id].hasOwnProperty(index)) { 5247 if (window.pysEddProductData[download_id][index].hasOwnProperty('gtm')) { 5248 5249 Utils.copyProperties(window.pysEddProductData[download_id][index]['gtm'].params, event.params); 5250 item = event.params.hasOwnProperty('ecommerce') ? event.params.ecommerce.items[0] : event.params.items[0]; 5251 // update items qty param 5252 item.quantity = qty; 5253 5254 this.fireEvent(event.name,event); 5255 5256 } 5257 } 5258 5259 } 5260 5261 }, 5262 5263 onEddRemoveFromCartEvent: function (event) { 5264 this.fireEvent(event.name, event); 5265 }, 5266 5267 onPageScroll: function (event) { 5268 if (initialized && this.isEnabled()) { 5269 this.fireEvent(event.name, event); 5270 } 5271 }, 5272 onTime: function (event) { 5273 if (initialized && this.isEnabled()) { 5274 this.fireEvent(event.name, event); 5275 } 5276 }, 5277 }; 5278 5279 }(options); 5280
5281 window.pys = window.pys || {}; 5282 window.pys.Facebook = Facebook; 5283 window.pys.Analytics = Analytics; 5284 window.pys.GAds = GAds; 5285 window.pys.GTM = GTM; 5286 window.pys.Utils = Utils; 5287 window.pys.TikTok = TikTok; 5288 5289 5290 5291 $(document).ready(function () { 5292 5293 if(Cookies.get('form_track')) 5294 { 5295 Cookies.remove('form_track') 5296 } 5297 5298 if($("#pys_late_event").length > 0) { 5299 var events = JSON.parse($("#pys_late_event").attr("dir")); 5300 for(var key in events) { 5301 var event = {}; 5302 event[events[key].e_id] = [events[key]]; 5303 if(options.staticEvents.hasOwnProperty(key)) { 5304 Object.assign(options.staticEvents[key], event); 5305 } else { 5306 options.staticEvents[key] = event; 5307 } 5308 5309 } 5310 } 5311 5312 var Pinterest = Utils.setupPinterestObject(); 5313 var Bing = Utils.setupBingObject(); 5314 if(options.hasOwnProperty('cookie')) 5315 { 5316 if(options.cookie.externalID_disabled_by_api || options.cookie.disabled_all_cookie) 5317 { 5318 Cookies.remove('pbid') 5319 } 5320 if(options.cookie.disabled_advanced_form_data_cookie || options.cookie.disabled_all_cookie) 5321 { 5322 Cookies.remove('pys_advanced_form_data') 5323 } 5324 if(options.cookie.disabled_landing_page_cookie || options.cookie.disabled_all_cookie) 5325 { 5326 Cookies.remove('pys_landing_page') 5327 Cookies.remove('last_pys_landing_page') 5328 } 5329 if(options.cookie.disabled_trafficsource_cookie || options.cookie.disabled_all_cookie) 5330 { 5331 Cookies.remove('pysTrafficSource') 5332 Cookies.remove('last_pysTrafficSource') 5333 } 5334 if(options.cookie.disabled_first_visit_cookie || options.cookie.disabled_all_cookie) 5335 { 5336 Cookies.remove('pys_first_visit') 5337 5338 } 5339 if(options.cookie.disabled_utmTerms_cookie || options.cookie.disabled_all_cookie) 5340 { 5341 $.each(Utils.utmTerms, function (index, name) { 5342 Cookies.remove('pys_' + name) 5343 }); 5344 $.each(Utils.utmTerms, function (index, name) { 5345 Cookies.remove('last_pys_' + name) 5346 }); 5347 } 5348 if(options.cookie.disabled_utmId_cookie || options.cookie.disabled_all_cookie) 5349 { 5350 $.each(Utils.utmId,function(index,name) { 5351 Cookies.remove('pys_' + name) 5352 }) 5353 $.each(Utils.utmId,function(index,name) { 5354 Cookies.remove('last_pys_' + name) 5355 }); 5356 } 5357 } 5358 5359 if (options.gdpr.cookie_law_info_integration_enabled) { 5360 var cli_cookie = Cookies.get('cookieyes-consent') ?? Cookies.get('viewed_cookie_policy'); 5361 5362 if (typeof cli_cookie !== 'undefined') { 5363 if (cli_cookie === Cookies.get('cookieyes-consent') && getCookieYes('analytics') == 'yes') { 5364 Utils.manageCookies(); 5365 } else if (cli_cookie === Cookies.get('viewed_cookie_policy') && cli_cookie == 'yes') { 5366 Utils.manageCookies(); 5367 } 5368 } 5369 } 5370 5371 if ( options.gdpr.consent_magic_integration_enabled && typeof CS_Data !== "undefined" ) { 5372 if ( CS_Data.cs_script_cat.pys == CS_Data.cs_necessary_cat_id || CS_Data.cs_script_cat.pys == 0 ) { 5373 Utils.manageCookies(); 5374 } else if ( Cookies.get( 'cs_enabled_cookie_term' + CS_Data.test_prefix + '_' + CS_Data.cs_script_cat.pys ) == 'yes' ) { 5375 Utils.manageCookies(); 5376 } 5377 } else { 5378 Utils.manageCookies(); 5379 } 5380
5381 Utils.initializeRequestParams(); 5382 Utils.setupGdprCallbacks(); 5383 5384 if ( options.enable_auto_save_advance_matching ) { 5385 let override = options.data_persistency == 'recent_data'; 5386 5387 //Setup Advanced Form Data 5388 if ( options.advance_matching_form.enable_advance_matching_forms ) { 5389 $( document ).on( "blur", "input[type='email']", function () { 5390 let email = $( this ).val().trim().toLowerCase(); 5391 if ( Utils.validateEmail( email ) ) { 5392 Utils.saveAdvancedFormData( email, null, null, null, override ); 5393 } 5394 } ) 5395 $( document ).on( "blur", "input[type='tel']", function () { 5396 let phone = $( this ).val().trim().replace( /\D/g, "" ); 5397 if ( phone.length > 5 ) { 5398 Utils.saveAdvancedFormData( null, phone, null, null, override ); 5399 } 5400 } ) 5401 $( document ).on( "blur", "input[type='text']", function () { 5402 let name; 5403 if ( $( this ).attr( "name" ) && $( this ).attr( "name" ) != '' ) { 5404 name = $( this ).attr( "name" ).trim() 5405 } 5406 if ( name && options.advance_matching_form.advance_matching_fn_names.includes( name ) ) { 5407 let value = $( this ).val().trim(); 5408 if ( value.length > 0 ) { 5409 Utils.saveAdvancedFormData( null, null, value, null, override ); 5410 } 5411 } 5412 if ( name && options.advance_matching_form.advance_matching_ln_names.includes( name ) ) { 5413 let value = $( this ).val().trim(); 5414 if ( value.length > 0 ) { 5415 Utils.saveAdvancedFormData( null, null, null, value, override ); 5416 } 5417 } 5418 if ( name && options.advance_matching_form.advance_matching_tel_names.includes( name ) ) { 5419 let value = $( this ).val().trim(); 5420 if ( value.length > 0 ) { 5421 Utils.saveAdvancedFormData( null, value, null, null, override ); 5422 } 5423 } 5424 if ( name && options.advance_matching_form.advance_matching_em_names.includes( name ) ) { 5425 let email = $( this ).val().trim().toLowerCase(); 5426 5427 if ( Utils.validateEmail( email ) ) { 5428 Utils.saveAdvancedFormData( email, null, null, null, false ); 5429 } 5430 } 5431 } ) 5432 } 5433 5434 //Setup Advanced Url Data 5435 if ( Object.keys( options.advance_matching_url ).length > 0 && options.advance_matching_url.enable_advance_matching_url ) { 5436 const url_params = new URLSearchParams( window.location.search ); 5437 url_params.forEach( ( value, key ) => { 5438 if ( options.advance_matching_url.advance_matching_fn_names.includes( key ) ) { 5439 Utils.saveAdvancedFormData( null, null, value.trim(), null, override ); 5440 } 5441 5442 if ( options.advance_matching_url.advance_matching_ln_names.includes( key ) ) { 5443 Utils.saveAdvancedFormData( null, null, null, value.trim(), override ); 5444 } 5445 5446 if ( options.advance_matching_url.advance_matching_tel_names.includes( key ) ) { 5447 Utils.saveAdvancedFormData( null, value.trim(), null, null, override ); 5448 } 5449 5450 if ( options.advance_matching_url.advance_matching_em_names.includes( key ) ) { 5451 let email = value.trim().toLowerCase() 5452 if ( Utils.validateEmail( email ) ) { 5453 Utils.saveAdvancedFormData( email, null, null, null, override ); 5454 } 5455 } 5456 } ); 5457 } 5458 } 5459 5460 // setup Click Event 5461 if ( 5462 options.dynamicEvents.hasOwnProperty("automatic_event_internal_link") || 5463 options.dynamicEvents.hasOwnProperty("automatic_event_outbound_link") || 5464 options.dynamicEvents.hasOwnProperty("automatic_event_tel_link") || 5465 options.dynamicEvents.hasOwnProperty("automatic_event_email_link") || 5466 options.dynamicEvents.hasOwnProperty("automatic_event_download") 5467 ) { 5468 5469 $(document).onFirst('click', 'a, button, input[type="button"], input[type="submit"]', function (e) { 5470 5471 var $elem = $(this); 5472 5473 5474 // Download 5475 if(options.dynamicEvents.hasOwnProperty("automatic_event_download")) { 5476 var isFired = false; 5477 if ($elem.is('a')) { 5478 var href = $elem.attr('href'); 5479 if (typeof href !== "string") { 5480 return; 5481 } 5482 href = href.trim(); 5483 var extension = Utils.getLinkExtension(href); 5484 var track_download = false; 5485 5486 if (extension.length > 0) { 5487 5488 if(options.dynamicEvents.hasOwnProperty("automatic_event_download") ) { 5489 var pixels = Object.keys(options.dynamicEvents.automatic_event_download); 5490 for (var i = 0; i < pixels.length; i++) { 5491 var event = Utils.clone(options.dynamicEvents.automatic_event_download[pixels[i]]); 5492 var extensions = event.extensions; 5493 if (extensions.includes(extension)) { 5494 5495 if(pixels[i] == "tiktok") { 5496 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5497 } else { 5498 if (options.enable_remove_download_url_param) { 5499 href = href.split('?')[0]; 5500 } 5501 event.params.download_url = href; 5502 event.params.download_type = extension; 5503 event.params.download_name = Utils.getLinkFilename(href); 5504 getPixelBySlag(pixels[i]).onDownloadEvent(event); 5505 } 5506 5507 isFired = true; 5508 } 5509 } 5510 } 5511 } 5512 } 5513 if(isFired) { // prevent duplicate events on the same element 5514 return; 5515 } 5516 } 5517 5518 5519 if (!e.hasOwnProperty('originalEvent')) { 5520 return; 5521 } 5522 if($elem.hasClass("add_to_cart_button") || 5523 $elem.hasClass("single_add_to_cart_button") ) { // add_to_cart_button fire in woo 5524 return; 5525 } 5526 5527 if(options.dynamicEvents.hasOwnProperty("wcf_add_to_cart_on_next_step_click") 5528 && $elem.hasClass("wcf-next-step-link")) { 5529 return;// add_to_cart_button fire in woo cf 5530 } 5531 if(options.dynamicEvents.hasOwnProperty("wcf_add_to_cart_on_bump_click") 5532 && $elem.hasClass("wcf-bump-order-cb")) { 5533 return;// add_to_cart_button fire in woo cf 5534 } 5535 5536 if($elem.hasClass("remove_from_cart_button") ) { // cancel remove from cart 5537 return; 5538 } 5539 if($elem.hasClass("remove") ) { // cancel remove from cart 5540 if($elem.parents('.cart_item').length || $elem.parents('.mini_cart_item').length) 5541 return; 5542 } 5543 if($elem.attr("name") == "update_cart" || $elem.attr("name") == "apply_coupon") { // cancel update c
5543art or coupon button 5544 return; 5545 } 5546 5547 5548 if ($elem.hasClass('pys_block')) { 5549 return; // avoiding fake double clicks from Affiliate event 5550 } 5551 var text = ""; 5552 var target_url = ""; 5553 var linkType = "Internal Click"; 5554 5555 if ($elem.is('a')) { 5556 var href = $elem.attr('href'); 5557 5558 // fixes #112 5559 if (typeof href !== "string") { 5560 return; 5561 } 5562 href = href.trim(); 5563 5564 text = $elem.contents().filter(function() { 5565 return this.nodeType === 3; // ФилÑÑÑÑем ÑолÑко ÑекÑÑовÑе ÑÐ·Ð»Ñ 5566 }).text().trim(); 5567 if(options.enable_remove_target_url_param) { 5568 target_url = href.split('?')[0]; 5569 } else { 5570 target_url = href 5571 } 5572 5573 5574 //Email Event 5575 if ( href.startsWith( 'mailto:' ) ) { 5576 if ( options.triggerEventTypes.hasOwnProperty( "email_link" ) ) { 5577 return; 5578 } else { 5579 setupEmailLinks(); 5580 } 5581 5582 return; // not fire next 5583 } 5584 5585 // Phone 5586 if (href.startsWith('tel:')) { 5587 if(options.dynamicEvents.hasOwnProperty("automatic_event_tel_link")) { 5588 var pixels = Object.keys(options.dynamicEvents.automatic_event_tel_link); 5589 for(var i = 0;i<pixels.length;i++) { 5590 var event = Utils.clone(options.dynamicEvents.automatic_event_tel_link[pixels[i]]); 5591 if ( pixels[i] !== 'tiktok') { 5592 Utils.copyProperties(Utils.getRequestParam
5592s(), event.params); 5593 } 5594 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5595 } 5596 } 5597 return; // not fire next 5598 } 5599 5600 if (href.startsWith('http')) { 5601 // link type 5602 var host = $elem.context != undefined ? $elem.context.host : $elem[0].host; 5603 if (document.location.host != host) { 5604 linkType = 'External Click'; 5605 } 5606 } 5607 } else if ($elem.is('button')) { 5608 if( $elem.hasClass("forminator-button-submit")) { 5609 //disable duplicate events 5610 return; 5611 } 5612 text = $elem.contents().filter(function() { 5613 return this.nodeType === 3; // ФилÑÑÑÑем ÑолÑко ÑекÑÑовÑе ÑÐ·Ð»Ñ 5614 }).text().trim(); 5615 } else if ($elem.is('input[type="button"]')) { 5616 text = $elem.val(); 5617 } else if ($elem.is('input[type="submit"]')) { 5618 if ( $elem.parents("form.comment-form")) { 5619 //disable duplicate events 5620 return; 5621 } 5622 if ($elem.parents("form")) { 5623 //disable duplicate events 5624 return; 5625 } 5626 text = $elem.val(); 5627 } else { 5628 return; 5629 } 5630 5631 5632 5633 text = Utils.filterEmails(text); 5634 5635 5636 if( linkType === "Internal Click" 5637 && options.dynamicEvents.hasOwnProperty("automatic_event_internal_link") 5638 ) { 5639 var pixels = Object.keys(options.dynamicEvents.automatic_event_internal_link); 5640 5641 for(var i = 0;i<pixels.length;i++) { 5642 var event = Utils.clone(options.dynamicEvents.automatic_event_internal_link[pixels[i]]); 5643 5644 if(pixels[i] !== "tiktok") { // TT doesn't support custom parameters 5645 event.params["text"] = text; 5646 if(target_url){ 5647 event.params["target_url"] = target_url; 5648 } 5649 Utils.copyProperties(Utils.getRequestParam
5649s(), event.params); 5650 } 5651 5652 5653 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5654 } 5655 } 5656 5657 if( linkType === "External Click" 5658 && options.dynamicEvents.hasOwnProperty("automatic_event_outbound_link") 5659 ) { 5660 var pixels = Object.keys(options.dynamicEvents.automatic_event_outbound_link); 5661 5662 for(var i = 0;i<pixels.length;i++) { 5663 var event = Utils.clone(options.dynamicEvents.automatic_event_outbound_link[pixels[i]]); 5664 5665 if(pixels[i] !== "tiktok") { // TT doesn't support custom parameters 5666 event.params["text"] = text; 5667 if(target_url){ 5668 event.params["target_url"] = target_url; 5669 } 5670 Utils.copyProperties(Utils.getRequestParams(), event.params); 5671 } 5672 5673 5674 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5675 } 5676 } 5677 5678 5679 5680 5681 }); 5682 5683 } 5684 5685 // setup AdSense Event 5686 if (options.dynamicEvents.hasOwnProperty("automatic_event_adsense")) { 5687 5688 var isOverGoogleAd = false; 5689 5690 $(document) 5691 .on('mouseover', 'ins iframe', function () { //class adsbygoogle adsbygoogle-noablate ?? 5692 isOverGoogleAd = true; 5693 }) 5694 .on('mouseout', 'iframe', function () { 5695 isOverGoogleAd = false; 5696 }); 5697 5698 $(window) 5699 .on( "blur",function () { 5700 if (isOverGoogleAd) { 5701 console.log('automatic_event_adsense') 5702 if(options.dynamicEvents.hasOwnProperty("automatic_event_adsense")) { 5703 var pixels = Object.keys(options.dynamicEvents.automatic_event_adsense); 5704 for (var i = 0; i < pixels.length; i++) { 5705 var event = Utils.clone(options.dynamicEvents.automatic_event_adsense[pixels[i]]); 5706 if ( pixels[i] !== 'tiktok') { 5707 Utils.copyProperties(Utils.getRequestParam
5707s(), event.params); 5708 } 5709 getPixelBySlag(pixels[i]).onAdSenseEvent(event); 5710 } 5711 } 5712 5713 $.each(options.triggerEventTypes, function (triggerType, events) { 5714 $.each(events, function (eventId, triggers) { 5715 switch (triggerType) { 5716 case 'ad_sense_click': 5717 Utils.fireTriggerEvent(eventId); 5718 break; 5719 } 5720 }); 5721 }); 5722 } 5723 }) 5724 .trigger("focus"); 5725 5726 } 5727 5728 //setup adsense for custom events 5729 var dynamicAdsenseEventsTriggers = 0 5730 $.each(options.triggerEventTypes, function (triggerType, events) { 5731 if(triggerType == "ad_sense_click") { 5732 dynamicAdsenseEventsTriggers++; 5733 } 5734 }); 5735 if (dynamicAdsenseEventsTriggers > 0) { 5736 5737 var isOverGoogleAd = false; 5738 5739 $(document) 5740 .on('mouseover', 'ins > ins > iframe', function () { 5741 isOverGoogleAd = true; 5742 }) 5743 .on('mouseout', 'iframe', function () { 5744 isOverGoogleAd = false; 5745 }); 5746 5747 $(window) 5748 .on( "blur",function () { 5749 if (isOverGoogleAd) { 5750 5751 $.each(options.triggerEventTypes, function (triggerType, events) { 5752 $.each(events, function (eventId, triggers) { 5753 switch (triggerType) { 5754 case 'ad_sense_click': 5755 Utils.fireTriggerEvent(eventId); 5756 break; 5757 } 5758 }); 5759 }); 5760 } 5761 }) 5762 .trigger("focus"); 5763 5764 } 5765 5766 5767 // page scroll event 5768 if (options.dynamicEvents.hasOwnProperty("automatic_event_scroll") 5769 ) { 5770 5771 var singlePageScroll = function () { 5772 5773 5774 var docHeight = $(document).height() - $(window).height(); 5775 var isFired = false; 5776 5777 if (options.dynamicEvents.hasOwnProperty("automatic_event_scroll")) { 5778 var pixels = Object.keys(options.dynamicEvents.automatic_event_scroll); 5779 for(var i = 0;i<pixels.length;i++) { 5780 var event = Utils.clone(options.dynamicEvents.automatic_event_scroll[pixels[i]]); 5781 var scroll = Math.round(docHeight * event.scroll_percent / 100)// convert % to absolute positions 5782 5783 if(scroll < $(window).scrollTop()) { 5784 if ( pixels[i] !== 'tiktok') { 5785 Utils.copyProperties(Utils.getRequestParam
5785s(), event.params); 5786 } 5787 getPixelBySlag(pixels[i]).onPageScroll(event); 5788 isFired = true 5789 } 5790 } 5791 } 5792 if(isFired) { 5793 $(document).off("scroll",singlePageScroll); 5794 } 5795 } 5796 $(document).on("scroll",singlePageScroll); 5797 } 5798 5799 5800 if (options.dynamicEvents.hasOwnProperty("automatic_event_time_on_page")) { 5801 var pixels = Object.keys(options.dynamicEvents.automatic_event_time_on_page); 5802 var time = options.dynamicEvents.automatic_event_time_on_page[pixels[0]].time_on_page; // the same for all pixel 5803 setTimeout(function(){ 5804 for(var i = 0;i<pixels.length;i++) { 5805 var event = Utils.clone(options.dynamicEvents.automatic_event_time_on_page[pixels[i]]); 5806 if ( pixels[i] !== 'tiktok') { 5807 Utils.copyProperties(Utils.getRequestParam
5807s(), event.params); 5808 } 5809 getPixelBySlag(pixels[i]).onTime(event); 5810 } 5811 },time*1000); 5812 } 5813 5814 // setup Dynamic events 5815 5816 $.each(options.triggerEventTypes, function (triggerType, events) { 5817 5818 $.each(events, function (eventId, triggers) { 5819 switch (triggerType) { 5820 case 'url_click': 5821 //@see: Utils.setupURLClickEvents() 5822 break; 5823 5824 case 'css_click': 5825 Utils.setupCSSClickEvents(eventId, triggers); 5826 break; 5827 5828 case 'css_mouseover': 5829 Utils.setupMouseOverClickEvents(eventId, triggers); 5830 break; 5831 5832 case 'scroll_pos': 5833 Utils.setupScrollPosEvents(eventId, triggers); 5834 break; 5835 case 'comment': 5836 Utils.setupCommentEvents(eventId, triggers); 5837 break; 5838 case 'video_view': 5839 //@see: Utils.checkYouTubeCompletion() and Utils.addYouTubeEvents() 5840 break; 5841 } 5842 5843 }); 5844 5845 if ( triggerType == "email_link" ) { 5846 Utils.setupEmailLinkEvents( events ) 5847 } 5848 5849 }); 5850 5851 // setup WooCommerce events 5852 if (options.woo.enabled) { 5853 5854 // Woo CartFlow AddToCart 5855 if (options.dynamicEvents.hasOwnProperty("wcf_add_to_cart_on_next_step_click")) { 5856 $("body").on("click",'.wcf-next-step-link',function () { 5857 var pixels = Object.keys(options.dynamicEvents.wcf_add_to_cart_on_next_step_click); 5858 for(var i = 0;i<pixels.length;i++) { 5859 var event = Utils.clone(options.dynamicEvents.wcf_add_to_cart_on_next_step_click[pixels[i]]) 5860 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5861 } 5862 }); 5863 } 5864 // Woo CartFlow Bump AddToCart 5865 if(options.dynamicEvents.hasOwnProperty("wcf_add_to_cart_on_bump_click") || 5866 options.dynamicEvents.hasOwnProperty("wcf_bump")) { 5867 $("body").on('change','.wcf-bump-order-cb',function () { 5868 5869 if(this.checked) { 5870 if(options.dynamicEvents.hasOwnProperty("wcf_add_to_cart_on_bump_click")) { 5871 var pixels = Object.keys(options.dynamicEvents.wcf_add_to_cart_on_bump_click); 5872 for(var i = 0;i<pixels.length;i++) { 5873 var event = Utils.clone(options.dynamicEvents.wcf_add_to_cart_on_bump_click[pixels[i]]); 5874 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5875 } 5876 } 5877 5878 5879 if(options.dynamicEvents.hasOwnProperty("wcf_bump")) { 5880 var pixels = Object.keys(options.dynamicEvents.wcf_bump); 5881 for(var i = 0;i<pixels.length;i++) { 5882 var event = Utils.clone(options.dynamicEvents.wcf_bump[pixels[i]]); 5883 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5884 } 5885 } 5886 5887 } else { 5888 if(options.dynamicEvents.hasOwnProperty("wcf_remove_from_cart_on_bump_click")) { 5889 var pixels = Object.keys(options.dynamicEvents.wcf_remove_from_cart_on_bump_click); 5890 for(var i = 0;i<pixels.length;i++) { 5891 var event = Utils.clone(options.dynamicEvents.wcf_remove_from_cart_on_bump_click[pixels[i]]); 5892 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 5893 } 5894 } 5895 5896 } 5897 5898 5899 }); 5900 } 5901 5902 5903 // WooCommerce AddToCart 5904 if (options.dynamicEvents.hasOwnProperty("woo_add_to_cart_on_button_click") 5905 && options.woo.hasOwnProperty("addToCartCatchMethod") 5906 && options.woo.addToCartCatchMethod === "add_cart_js" 5907 ) { 5908 5909 // Loop, any kind of "simple" product, except external 5910 $('.add_to_cart_button:not(.product_type_variable,.product_type_bundle,.single_add_to_cart_button)').on("click",function (e) { 5911 var $button = $(this); 5912 var $prod_info = $button.siblings('.pys_list_name_productdata').data(); 5913 var product_id = $(this).data('product_id'); 5914 Cookies.set('productlist', JSON.stringify($prod_info), { expires: 1,path: '/' }) 5915 var product_id = $(this).data('product_id'); 5916 if (typeof product_id !== 'undefined') { 5917 Facebook.onWooAddToCartOnButtonEvent(product_id,$(this)); 5918 Analytics.onWooAddToCartOnButtonEvent(product_id, $prod_info); 5919 GTM.onWooAddToCartOnButtonEvent(product_id, $prod_info); 5920 GAds.onWooAddToCartOnButtonEvent(product_id); 5921 Pinterest.onWooAddToCartOnButtonEvent(product_id); 5922 Bing.onWooAddToCartOnButtonEvent(product_id); 5923 TikTok.onWooAddToCartOnButtonEvent(product_id); 5924 } 5925 5926 }); 5927 5928 // Single Product 5929 // tap try to https://stackoverflow.com/questions/30990967/on-tap-click-event-firing-twice-how-to-avoid-it 5930 // $(document) not work 5931 $('body').onFirst('click','button.single_add_to_cart_button,.single_add_to_cart_button',function (e) { 5932 5933 var $button = $(this); 5934 var $prod_info = $button.siblings('.pys_list_name_productdata').data(); 5935 var product_id = $(this).data('product_id'); 5936 Cookies.set('productlist', JSON.stringify($prod_info), { expires: 1,path: '/' }) 5937 if ($button.hasClass('disabled')) { 5938 return; 5939 } 5940 5941 var $form = $button.closest('form'); 5942 5943 var product_type = Utils.PRODUCT_SIMPLE; 5944 var is_external = false; 5945 5946 if ($form.length === 0) { 5947 is_external = true; 5948 } else if ($form.hasClass('variations_form')) { 5949 product_type = Utils.PRODUCT_VARIABLE; 5950 } else if($form.hasClass('bundle_form')) { 5951 product_type = Utils.PRODUCT_BUNDLE; 5952 } else if($form.hasClass('grouped_form')) { 5953 product_type = Utils.PRODUCT_GROUPED; 5954 } 5955 5956 5957 5958 var product_id; 5959 var qty; 5960 if (product_type === Utils.PRODUCT_GROUPED) { 5961 qty = 1; 5962 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 5963 } else if (product_type === Utils.PRODUCT_VARIABLE) { 5964 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 5965 var qtyTag = $form.find('input[name="quantity"]'); 5966 if(qtyTag.length <= 0) { 5967 qtyTag = $form.find('select[name="quantity"]'); 5968 } 5969 qty = parseInt(qtyTag.val()); 5970 } else if (is_external) { 5971 product_id = options.woo.singleProductId; 5972 qty = 1; 5973 } else { 5974 product_id = parseInt($form.find('*[name="add-to-cart"]').val()); 5975 var qtyTag = $form.find('input[name="quantity"]'); 5976 if(qtyTag.length <= 0) { 5977 qtyTag = $form.find('select[name="quantity"]'); 5978 } 5979 qty = parseInt(qtyTag.val()); 5980 } 5981 5982 Facebook.onWooAddToCartOnSingleEvent(product_id, qty, product_type, is_external, $form); 5983 Analytics.onWooAddToCartOnSingleEvent(product_id, qty, product_type, is_external, $form, $prod_info); 5984 GTM.onWooAddToCartOnSingleEvent(product_id, qty, product_type, is_external, $form, $prod_info); 5985 GAds.onWooAddToCartOnSingleEvent(product_id, qty, product_type, is_external, $form); 5986 Pinterest.onWooAddToCartOnSingleEvent(product_id, qty, product_type, is_external, $form); 5987 Bing.onWooAddToCartOnSingleEvent(product_id, qty, product_type, is_external, $form); 5988 TikTok.onWooAddToCartOnSingleEvent(product_id, qty, product_type, is_external, $form); 5989 }); 5990 5991 } else { 5992 $('.add_to_cart_button:not(.product_type_variable,.product_type_bundle,.single_add_to_cart_button)').on("click",function (e) { 5993 var $button = $(this); 5994 var $prod_info = $button.siblings('.pys_list_name_productdata').data(); 5995 var product_id = $(this).data('product_id'); 5996 Cookies.set('productlist', JSON.stringify($prod_info), { expires: 1,path: '/' }) 5997 }); 5998 5999 // Single Product 6000 // tap try to https://stackoverflow.com/questions/30990967/on-tap-click-event-firing-twice-how-to-avoid-it 6001 // $(document) not work 6002 $('body').onFirst('click','button.single_add_to_cart_button,.single_add_to_cart_button',function (e) { 6003 6004 var $button = $(this); 6005 var $prod_info = $button.siblings('.pys_list_name_productdata').data(); 6006 Cookies.set('productlist', $prod_info, { expires: 1,path: '/' }) 6007 }); 6008 } 6009 6010 // WooCommerce Affiliate 6011 if (options.dynamicEvents.hasOwnProperty("woo_affiliate")) { 6012 6013 // Loop, external 6014 $('.product_type_external').on("click",function (e) { 6015 6016 var product_id = $(this).data('product_id'); 6017 6018 if (typeof product_id !== 'undefined') { 6019 Facebook.onWooAffiliateEvent(product_id); 6020 Analytics.onWooAffiliateEvent(product_id); 6021 GTM.onWooAffiliateEvent(product_id); 6022 GAds.onWooAffiliateEvent(product_id); 6023 Pinterest.onWooAffiliateEvent(product_id); 6024 Bing.onWooAffiliateEvent(product_id); 6025 } 6026 6027 }); 6028 6029 } 6030 6031 // WooCommerce RemoveFromCart 6032 if (options.dynamicEvents.hasOwnProperty("woo_remove_from_cart")) { 6033 6034 $('body').on('click', options.woo.removeFromCartSelector, function (e) { 6035 6036 var $a = $(e.currentTarget), 6037 href = $a.attr('href'); 6038 6039 // extract cart item hash from remove button URL 6040 var regex = new RegExp("[\\?&]remove_item=([^&#]*)"), 6041 results = regex.exec(href); 6042 6043 if (results !== null) { 6044 6045 var item_hash = results[1]; 6046 6047 if (options.dynamicEvents["woo_remove_from_cart"].hasOwnProperty(item_hash)) { 6048 var events = options.dynamicEvents["woo_remove_from_cart"][item_hash]; 6049 Utils.fireEventForAllPixel("onWooRemoveFromCartEvent",events) 6050 } 6051 6052 } 6053 6054 }); 6055 6056 } 6057 6058 // WooCommerce PayPal 6059 if (options.dynamicEvents.hasOwnProperty("woo_paypal")) { 6060 6061 // Non-default binding used to avoid situations when some code in external js 6062 // stopping events propagation, eg. returns false, and our handler will never called 6063 $(document).onFirst('submit click', '#place_order', function (e) { 6064 6065 var method = $('form[name="checkout"] input[name="payment_method"]:checked').val(); 6066 6067 if (method !== 'paypal') { 6068 return; 6069 } 6070 var events = options.dynamicEvents.woo_paypal; 6071 Utils.fireEventForAllPixel("onWooPayPalEvent",events) 6072 6073 }); 6074 6075 } 6076 6077 // WooCommerce checkout progress 6078 if(options.dynamicEvents.hasOwnProperty("woo_initiate_checkout_progress_f") ) { 6079 6080 $(document).on("change",".woocommerce-validated #billing_first_name",function () { 6081 Analytics.onWooCheckoutProgressStep(options.dynamicEvents.woo_initiate_checkout_progress_f[Analytics.tag()]); 6082 }); 6083 } 6084 if(options.dynamicEvents.hasOwnProperty("woo_initiate_checkout_progress_l")) { 6085 6086 $(document).on("change",".woocommerce-validated #billing_last_name",function () { 6087 Analytics.onWooCheckoutProgressStep(options.dynamicEvents.woo_initiate_checkout_progress_l[Analytics.tag()]); 6088 }); 6089 } 6090 6091 if(options.dynamicEvents.hasOwnProperty("woo_initiate_checkout_progress_e")) { 6092 6093 $(document).on("change",".woocommerce-validated #billing_email",function () { 6094 Analytics.onWooCheckoutProgressStep(options.dynamicEvents.woo_initiate_checkout_progress_e[Analytics.tag()]); 6095 }); 6096 } 6097 if(options.dynamicEvents.hasOwnProperty("woo_initiate_checkout_progress_o")) { 6098 $(document).onFirst('submit click', '#place_order', function () { 6099 Analytics.onWooCheckoutProgressStep(options.dynamicEvents.woo_initiate_checkout_progress_o[Analytics.tag()]); 6100 }); 6101 } 6102 6103 6104 // WooCommerce 6105 6106 $('.product.type-product a.woocommerce-loop-product__link').onFirst('click', function (evt) { 6107 var productId = $(this).closest('.product').find(".add_to_cart_button").attr("data-product_id"); 6108 var eventTypes = ["woo_select_content_search", "woo_select_content_shop", "woo_select_content_tag", "woo_select_content_single", "woo_select_content_category"]; 6109 var isEventFired = false; 6110 6111 for (var i = 0; i < eventTypes.length; i++) { 6112 var eventType = eventTypes[i];
6113 if (options.dynamicEvents.hasOwnProperty(eventType) && options.dynamicEvents[eventType].hasOwnProperty(productId)) { 6114 if(Analytics.isEnabled()){ 6115 Analytics.onWooSelectContent(options.dynamicEvents[eventType][productId][Analytics.tag()]); 6116 } 6117 if(GTM.isEnabled()){ 6118 GTM.onWooSelectContent(options.dynamicEvents[eventType][productId][GTM.tag()]); 6119 } 6120 isEventFired = true; 6121 break; 6122 } 6123 } 6124 6125 if (!isEventFired) { 6126 let prod_info = $(this).parent().find('.pys_list_name_productdata').data(); 6127 if (prod_info) { 6128 const select_prod_list = {}; 6129 if (prod_info['pys_list_name_productlist_name']) { 6130 select_prod_list.list_name = prod_info['pys_list_name_productlist_name'] 6131 } 6132 if (prod_info['pys_list_name_productlist_id']) { 6133 select_prod_list.list_id = prod_info['pys_list_name_productlist_id'] 6134 } 6135 const url = new URL(window.location.href); 6136 select_prod_list.url = url.origin + url.pathname; 6137 Cookies.set('select_prod_list', JSON.stringify(select_prod_list), { expires: 1,path: '/' }); 6138 } 6139 } 6140 }); 6141 6142 } 6143 6144 // setup EDD events 6145 if (options.edd.enabled) { 6146 6147 // EDD AddToCart 6148 if (options.dynamicEvents.hasOwnProperty("edd_add_to_cart_on_button_click")) { 6149 6150 $('form.edd_download_purchase_form .edd-add-to-cart').on("click",function (e) { 6151 6152 var $button = $(this); 6153 var $form = $button.closest('form'); 6154 var variable_price = $button.data('variablePrice'); // yes/no 6155 var price_mode = $button.data('priceMode'); // single/multi 6156 var ids = []; 6157 var quantities = []; 6158 var qty; 6159 var id; 6160 6161 if (variable_price === 'yes' && price_mode === 'multi') { 6162 6163 id = $form.find('input[name="download_id"]').val(); 6164 6165 // get selected variants 6166 $.each($form.find('input[name="edd_options[price_id][]"]:checked'), function (i, el) { 6167 ids.push(id + '_' + $(el).val()); 6168 }); 6169 6170 // get qty for selected variants 6171 $.each(ids, function (i, variant_id) { 6172 6173 var variant_index = variant_id.split('_', 2); 6174 qty = $form.find('input[name="edd_download_quantity_' + variant_index[1] + '"]').val(); 6175 6176 if (typeof qty !== 'undefined') { 6177 quantities.push(qty); 6178 } else { 6179 quantities.push(1); 6180 } 6181 6182 }); 6183 6184 } else if (variable_price === 'yes' && price_mode === 'single') { 6185 6186 id = $form.find('input[name="download_id"]').val(); 6187 ids.push(id + '_' + $form.find('input[name="edd_options[price_id][]"]:checked').val()); 6188 6189 qty = $form.find('input[name="edd_download_quantity"]').val(); 6190 6191 if (typeof qty !== 'undefined') { 6192 quantities.push(qty); 6193 } else { 6194 quantities.push(1); 6195 } 6196 6197 } else { 6198 6199 ids.push($button.data('downloadId')); 6200 6201 qty = $form.find('input[name="edd_download_quantity"]').val(); 6202 6203 if (typeof qty !== 'undefined') { 6204 quantities.push(qty); 6205 } else { 6206 quantities.push(1); 6207 } 6208 } 6209 6210 // fire event for each download/variant 6211 $.each(ids, function (i, download_id) { 6212 6213 var q = parseInt(quantities[i]); 6214 var variant_index = download_id.toString().split('_', 2); 6215 var price_index; 6216 6217 if (variant_index.length === 2) { 6218 download_id = variant_index[0]; 6219 price_index = variant_index[1]; 6220 } 6221 6222 Facebook.onEddAddToCartOnButtonEvent(download_id, price_index, q); 6223 Analytics.onEddAddToCartOnButtonEvent(download_id, price_index, q); 6224 GTM.onEddAddToCartOnButtonEvent(download_id, price_index, q); 6225 GAds.onEddAddToCartOnButtonEvent(download_id, price_index, q); 6226 Pinterest.onEddAddToCartOnButtonEvent(download_id, price_index, q); 6227 Bing.onEddAddToCartOnButtonEvent(download_id, price_index, q); 6228 TikTok.onEddAddToCartOnButtonEvent(download_id, price_index, q); 6229 6230 }); 6231 6232 }); 6233 6234 } 6235 6236 // EDD RemoveFromCart 6237 if (options.dynamicEvents.hasOwnProperty("edd_remove_from_cart") ) { 6238 6239 $('form#edd_checkout_cart_form .edd_cart_remove_item_btn').on("click",function (e) { 6240 6241 var href = $(this).attr('href'); 6242 var key = href.substring(href.indexOf('=') + 1).charAt(0);
6243 6244 if (options.dynamicEvents.edd_remove_from_cart.hasOwnProperty(key)) { 6245 var events = options.dynamicEvents.edd_remove_from_cart[key]; 6246 Utils.fireEventForAllPixel("onEddRemoveFromCartEvent",events) 6247 } 6248 6249 }); 6250 6251 } 6252 6253 } 6254 6255 Utils.setupURLClickEvents(); 6256 6257 // setup Comment Event 6258 if (options.dynamicEvents.hasOwnProperty("automatic_event_comment") 6259 ) { 6260 6261 $('form.comment-form').on("submit",function () { 6262 if (options.dynamicEvents.hasOwnProperty("automatic_event_comment")) { 6263 var pixels = Object.keys(options.dynamicEvents.automatic_event_comment); 6264 for (var i = 0; i < pixels.length; i++) { 6265 var event = Utils.clone(options.dynamicEvents.automatic_event_comment[pixels[i]]); 6266 if ( pixels[i] !== 'tiktok') { 6267 Utils.copyProperties(Utils.getRequestParam
6267s(), event.params); 6268 } 6269 getPixelBySlag(pixels[i]).onCommentEvent(event); 6270 } 6271 } 6272 }); 6273 6274 } 6275 6276 // setup Form Event 6277 if ( options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 6278 6279 $(document).onFirst('submit', 'form', function (e) { 6280 6281 var $form = $(this); 6282 6283 // exclude WP forms 6284 if ($form.hasClass('comment-form') || $form.hasClass('search-form') || $form.attr('id') === 'adminbarsearch') { 6285 return; 6286 } 6287 6288 // exclude Woo forms 6289 if ($form.hasClass('woocommerce-product-search') || $form.hasClass('cart') || $form.hasClass('woocommerce-cart-form') || 6290 $form.hasClass('woocommerce-shipping-calculator') || $form.hasClass('checkout') || $form.hasClass('checkout_coupon')) { 6291 return; 6292 } 6293 6294 // exclude EDD forms 6295 if ($form.hasClass('edd_form') || $form.hasClass('edd_download_purchase_form')) { 6296 return; 6297 } 6298 // exclude CF7 forms 6299 if ($form.hasClass('wpcf7-form')) { 6300 return; 6301 } 6302 // exclude Gravity forms 6303 if ($form.attr('id') && $form.attr('id').includes('gform')) { 6304 var target = $form.attr('target'); 6305 if (target && target.indexOf('gform_ajax_frame') !== -1) { 6306 return; 6307 } 6308 } 6309 // exclude Forminator forms 6310 if ($form.hasClass('forminator-custom-form') || $form.hasClass('forminator_ajax')) { 6311 return; 6312 } 6313 // exclude WPforms forms 6314 if ($form.hasClass('wpforms-form') || $form.hasClass('wpforms-ajax-form')) { 6315 return; 6316 } 6317 // exclude Formidable forms 6318 /*if ($form.hasClass('frm-show-form')) { 6319 return; 6320 }*/ 6321 // exclude Ninja Forms forms 6322 if ($form.parent().hasClass('nf-form-layout')) { 6323 return; 6324 } 6325 // exclude Fluent forms 6326 if ($form.hasClass('frm-fluent-form')) { 6327 return; 6328 } 6329 6330 // exclude WS form forms 6331 if ($form.hasClass('wsf-form') ) { 6332 return; 6333 } 6334 6335 // exclude WS form forms 6336 if ( $form.hasClass( 'elementor-form' ) ) { 6337 return; 6338 } 6339 6340 if(!options.enable_success_send_form) { 6341 var params = { 6342 form_id: $form.attr('id'), 6343 form_class: $form.attr('class') ? $form.attr('class') : $form.attr('id'), 6344 text: $form.find('[type="submit"]').is('input') ? 6345 $form.find('[type="submit"]').val() : $form.find('[type="submit"]').text() 6346 }; 6347 6348 if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 6349 var pixels = Object.keys(options.dynamicEvents.automatic_event_form); 6350 for (var i = 0; i < pixels.length; i++) { 6351 var event = Utils.clone(options.dynamicEvents.automatic_event_form[pixels[i]]); 6352 6353 if (pixels[i] === "tiktok") { 6354 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 6355 } else { 6356 Utils.copyProperties(params, event.params,) 6357 Utils.copyProperties(Utils.getRequestParam
6357s(), event.params); 6358 getPixelBySlag(pixels[i]).onFormEvent(event); 6359 } 6360 } 6361 } 6362 } 6363 }); 6364 6365 6366 } 6367 6368 jQuery(document).on('elementor/popup/show', function(event) { 6369 for (var i = 0; i < jQuery(".wpcf7-form").length; i++) { 6370 wpcf7.init(jQuery(".wpcf7-form")[i]); 6371 } 6372 }); 6373 6374 document.addEventListener( 'wpcf7mailsent', function ( event ) { 6375 let form_id = event.detail.contactFormId, 6376 sendEventId = null, 6377 disabled_form_action = false; 6378 if ( options.triggerEventTypes.hasOwnProperty( 'CF7' ) ) { 6379 $.each( options.triggerEventTypes.CF7, function ( eventId, triggers ) { 6380 $.each( triggers, function ( index, trigger ) { 6381 $.each( trigger.forms, function ( i, value ) { 6382 if ( value == form_id ) { 6383 sendEventId = eventId; 6384 disabled_form_action = trigger.disabled_form_action; 6385 } 6386 } ) 6387 } ); 6388 } ); 6389 } 6390 if ( sendEventId != null ) { 6391 Utils.fireTriggerEvent( sendEventId ); 6392 } 6393 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6394 6395 }, false ); 6396 6397 //GravityForm 6398 jQuery( document ).on( 'gform_confirmation_loaded', function ( event, formId ) { 6399 let form_id = formId, 6400 sendEventId = null, 6401 disabled_form_action = false; 6402 if ( options.triggerEventTypes.hasOwnProperty( 'gravity' ) ) { 6403 $.each( options.triggerEventTypes.gravity, function ( eventId, triggers ) { 6404 $.each( triggers, function ( index, trigger ) { 6405 $.each( trigger.forms, function ( i, value ) { 6406 if ( value == form_id ) { 6407 disabled_form_action = trigger.disabled_form_action; 6408 sendEventId = eventId; 6409 } 6410 } ) 6411 } ); 6412 } ); 6413 } 6414 6415 if ( sendEventId != null ) { 6416 Utils.fireTriggerEvent( sendEventId ); 6417 } 6418 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6419 jQuery( document ).off( 'gform_confirmation_loaded' ); 6420 } ); 6421 //Forminator 6422 $( document ).on( 'forminator:form:submit:success', function ( event ) { 6423 6424 let form_id = $( event.target ).find( 'input[name="form_id"]' ).val(), 6425 sendEventId = null, 6426 disabled_form_action = false; 6427 if ( options.triggerEventTypes.hasOwnProperty( 'forminator' ) ) { 6428 $.each( options.triggerEventTypes.forminator, function ( eventId, triggers ) { 6429 $.each( triggers, function ( index, trigger ) { 6430 $.each( trigger.forms, function ( i, value ) { 6431 if ( value == form_id ) { 6432 disabled_form_action = trigger.disabled_form_action; 6433 sendEventId = eventId; 6434 } 6435 } ) 6436 } ); 6437 } ); 6438 } 6439 if ( sendEventId != null ) { 6440 Utils.fireTriggerEvent( sendEventId ); 6441 } 6442 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6443 } ); 6444 6445 //WPForm 6446 $( 'form.wpforms-form' ).on( 'wpformsAjaxSubmitSuccess', ( event ) => { 6447 6448 let form_id = $( event.target ).attr( 'data-formid' ), 6449 sendEventId = null, 6450 disabled_form_action = false; 6451 6452 if ( options.triggerEventTypes.hasOwnProperty( 'wpforms' ) ) { 6453 $.each( options.triggerEventTypes.wpforms, function ( eventId, triggers ) { 6454 $.each( triggers, function ( index, trigger ) { 6455 $.each( trigger.forms, function ( i, value ) { 6456 if ( value == form_id ) { 6457 sendEventId = eventId; 6458 disabled_form_action = trigger.disabled_form_action; 6459 } 6460 } ) 6461 } ); 6462 } ); 6463 } 6464 if ( sendEventId != null ) { 6465 Utils.fireTriggerEvent( sendEventId ); 6466 } 6467 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6468 } ) 6469 6470 $( document ).on( 'frmFormComplete', function ( event, form, response ) { 6471 const form_id = $( form ).find( 'input[name="form_id"]' ).val(); 6472 let sendEventId = null, 6473 disabled_form_action = false; 6474 if ( options.triggerEventTypes.hasOwnProperty( 'formidable' ) ) { 6475 $.each( options.triggerEventTypes.formidable, function ( eventId, triggers ) { 6476 $.each( triggers, function ( index, trigger ) { 6477 $.each( trigger.forms, function ( i, value ) { 6478 if ( value == form_id ) { 6479 disabled_form_action = trigger.disabled_form_action; 6480 sendEventId = eventId; 6481 } 6482 } ) 6483 } ); 6484 } ); 6485 } 6486 if ( sendEventId != null ) { 6487 Utils.fireTriggerEvent( sendEventId ); 6488 } 6489 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6490 6491 } ); 6492 6493 // Ninja Forms 6494 $( document ).onFirst( 'nfFormSubmitResponse', function ( event, data ) { 6495 const form_id = data.response.data.form_id; 6496 let sendEventId = null, 6497 disabled_form_action = false; 6498 if ( options.triggerEventTypes.hasOwnProperty( 'ninjaform' ) ) { 6499 $.each( options.triggerEventTypes.ninjaform, function ( eventId, triggers ) { 6500 $.each( triggers, function ( index, trigger ) { 6501 $.each( trigger.forms, function ( i, value ) { 6502 if ( value == form_id ) { 6503 disabled_form_action = trigger.disabled_form_action; 6504 sendEventId = eventId; 6505 } 6506 } ) 6507 } ); 6508 } ); 6509 } 6510 if ( sendEventId != null ) { 6511 Utils.fireTriggerEvent( sendEventId ); 6512 } 6513 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6514 } ); 6515 6516 var fluentForms = $( 'form.frm-fluent-form' ); 6517 fluentForms.each( function () { 6518 var $form = $( this ); 6519 $form.on( 'fluentform_submission_success', function ( event ) { 6520 let $formItem = $( this ), 6521 form_id = $formItem.attr( 'data-form_id' ), 6522 sendEventId = null, 6523 disabled_form_action = false; 6524 if ( options.triggerEventTypes.hasOwnProperty( 'fluentform' ) ) { 6525 $.each( options.triggerEventTypes.fluentform, function ( eventId, triggers ) { 6526 $.each( triggers, function ( index, trigger ) { 6527 $.each( trigger.forms, function ( i, value ) { 6528 if ( value == form_id ) { 6529 disabled_form_action = trigger.disabled_form_action; 6530 sendEventId = eventId; 6531 } 6532 } ) 6533 } ); 6534 } ); 6535 } 6536 6537 if ( sendEventId != null ) { 6538 Utils.fireTriggerEvent( sendEventId ); 6539 } 6540 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6541 } ); 6542 } ); 6543 6544 //WSForm 6545 $( document ).on( 'wsf-submit-complete', ( event, form_object, form_id ) => { 6546 let sendEventId = null, 6547 disabled_form_action = false; 6548 if ( options.triggerEventTypes.hasOwnProperty( 'wsform' ) ) { 6549 $.each( options.triggerEventTypes.wsform, function ( eventId, triggers ) { 6550 $.each( triggers, function ( index, trigger ) { 6551 $.each( trigger.forms, function ( i, value ) { 6552 if ( value == form_id ) { 6553 disabled_form_action = trigger.disabled_form_action; 6554 sendEventId = eventId; 6555 } 6556 } ) 6557 } ); 6558 } ); 6559 } 6560 6561 if ( sendEventId != null ) { 6562 Utils.fireTriggerEvent( sendEventId ); 6563 } 6564 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6565 } ) 6566 6567 // Elementor Forms 6568 let forms = document.querySelectorAll( '.elementor-form' ); 6569 // Apply the observer to each form
6570 forms.forEach( function ( form ) { 6571 observeElementorForm( form ); 6572 } ); 6573 6574 // watching Elementor Popup forms 6575 let observer = new MutationObserver( function ( mutationsList, observer ) { 6576 for ( let i = 0; i < mutationsList.length; i++ ) { 6577 let popupForm = document.querySelector( '[class*="elementor-popup"] form' ); 6578 if ( popupForm ) { 6579 observeElementorForm( popupForm ); 6580 observer.disconnect(); 6581 break; 6582 } 6583 } 6584 } ); 6585 observer.observe( document.body, { childList: true, subtree: true } ); 6586 6587 // load pixel APIs 6588 Utils.loadPixels(); 6589 6590 // setup Enrich content 6591 if(Utils.isCheckoutPage()) { 6592 Utils.addCheckoutFields(); 6593 } 6594 }); 6595 6596 6597 6598 6599 var sendFormAction = function (form_target, formId, customEventId = null, disabled = false){ 6600 var params = { 6601 form_id: formId, 6602 text: form_target.find('[type="submit"]').is('input') ? form_target.find('[type="submit"]').val() : 6603 form_target.find('.forminator-button-submit').text() != '' ? form_target.find('.forminator-button-submit').text() : 6604 form_target.find('[type="submit"]').text() 6605 }; 6606 6607 if (options.dynamicEvents.hasOwnProperty("automatic_event_form")) { 6608 var pixels = Object.keys(options.dynamicEvents.automatic_event_form); 6609 for (var i = 0; i < pixels.length; i++) { 6610 6611 if ( disabled && customEventId && typeof options.triggerEvents[customEventId][pixels[i]] !== 'undefined') { 6612 continue; 6613 } 6614 var event = options.dynamicEvents.automatic_event_form[pixels[i]]; 6615 if (pixels[i] === "tiktok") { 6616 getPixelBySlag(pixels[i]).fireEvent(event.name, event); 6617 } else { 6618 Utils.copyProperties(params, event.params)
6619 Utils.copyProperties(Utils.getRequestParams(), event.params); 6620 getPixelBySlag(pixels[i]).onFormEvent(event); 6621 } 6622 } 6623 } 6624 } 6625 6626 var setupEmailLinks = function ( disabled_for_pixels = [] ) { 6627 if ( options.dynamicEvents.hasOwnProperty( "automatic_event_email_link" ) ) { 6628 var pixels = Object.keys( options.dynamicEvents.automatic_event_email_link ); 6629 for ( var i = 0; i < pixels.length; i++ ) { 6630 if ( disabled_for_pixels.indexOf(pixels[ i ]) === -1 ) { 6631 var event = Utils.clone( options.dynamicEvents.automatic_event_email_link[ pixels[ i ] ] ); 6632 if ( pixels[ i ] !== 'tiktok' ) { 6633 Utils.copyProperties( Utils.getRequestParams(), event.params ); 6634 } 6635 getPixelBySlag( pixels[ i ] ).fireEvent( event.name, event ); 6636 } 6637 } 6638 } 6639 } 6640 6641 //Elementor Forms Observer 6642 var observeElementorForm = function ( form ) { 6643 let observer = new MutationObserver( function ( mutations ) { 6644 6645 for ( let i = 0; i < mutations.length; i++ ) { 6646 let mutation = mutations[ i ]; 6647 6648 if ( mutation.type === 'childList' || mutation.type === 'attributes' ) { 6649 if ( $( form ).find( '.elementor-message-success' ).length > 0 ) { 6650 6651 let form_id = $( form ).attr( 'id' ); 6652 if ( !form_id ) { 6653 form_id = $( form ).find( 'input[name="form_id"]' ).val(); 6654 } 6655 6656 let sendEventId = null, 6657 disabled_form_action = false; 6658 if ( options.triggerEventTypes.hasOwnProperty( 'elementor_form' ) ) { 6659 $.each( options.triggerEventTypes.elementor_form, function ( eventId, triggers ) { 6660 $.each( triggers, function ( index, trigger ) { 6661 $.each( trigger.forms, function ( i, value ) { 6662 if ( value == form_id ) { 6663 disabled_form_action = trigger.disabled_form_action; 6664 sendEventId = eventId; 6665 } 6666 }) 6667 } ); 6668 } ); 6669 } 6670 if ( sendEventId != null ) { 6671 Utils.fireTriggerEvent( sendEventId ); 6672 } 6673 sendFormAction( $( event.target ), form_id, sendEventId, disabled_form_action ); 6674 6675 observer.disconnect(); 6676 break; 6677 } 6678 } 6679 } 6680 } ); 6681 6682 // Start observing the form for changes 6683 observer.observe( form, { 6684 attributes: true, 6685 childList: true, 6686 subtree: true 6687 } ); 6688 } 6689 6690}(jQuery, pysOptions); 6691 6692function pys_generate_token() { 6693 return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => 6694 (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) 6695 ); 6696} 6697function getBundlePriceOnSingleProduct(data) { 6698 var items_sum = 0; 6699 jQuery(".bundle_form .bundled_product").each(function(index){ 6700 var id = jQuery(this).find(".cart").data("bundled_item_id"); 6701 var item_price = data.prices[id]; 6702 var item_quantity = jQuery(this).find(".bundled_qty").val(); 6703 if(!jQuery(this).hasClass("bundled_item_optional") || 6704 jQuery(this).find(".bundled_product_optional_checkbox input").prop('checked')) { 6705 items_sum += item_price*item_quantity; 6706 } 6707 }); 6708 return items_sum; 6709} 6710 6711function getPixelBySlag(slug) { 6712 switch (slug) { 6713 case "facebook": return window.pys.Facebook; 6714 case "ga": return window.pys.Analytics; 6715 case "gtm": return window.pys.GTM; 6716 case "google_ads": return window.pys.GAds; 6717 case "bing": return window.pys.Bing; 6718 case "pinterest": return window.pys.Pinterest; 6719 case "tiktok": return window.pys.TikTok; 6720 } 6721} 6722function getUrlParameter(sParam) { 6723 var sPageURL = window.location.search.substring(1), 6724 sURLVariables = sPageURL.split('&'), 6725 sParameterName, 6726 i; 6727 6728 for (i = 0; i < sURLVariables.length; i++) { 6729 sParameterName = sURLVariables[i].split('='); 6730 6731 if (sParameterName[0] === sParam) { 6732 return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); 6733 } 6734 } 6735 return false; 6736}; 6737function inArray(needle, haystack) { 6738 var length = haystack.length; 6739 for(var i = 0; i < length; i++) { 6740 if(haystack[i] == needle) return true; 6741 } 6742 return false; 6743} 6744 6745function getCookieYes(key) { 6746 const cookies = document.cookie 6747 .split(";") 6748 .reduce( 6749 (ac, cv, i) => 6750 Object.assign(ac, { [cv.split("=")[0].trim()]: cv.split("=")[1] }), 6751 {} 6752 )["cookieyes-consent"]; 6753 const { [key]: value } = cookies 6754 .split(",") 6755 .reduce( 6756 (obj, pair) => ( 6757 (pair = pair.split(":")), (obj[pair[0]] = pair[1]), obj 6758 ), 6759 {} 6760 ); 6761 return value; 6762} 6763 6764function getRootDomain(useSubdomain = false) { 6765 const hostname = window.location.hostname; // Get the current hostname 6766 const rootDomain = tldjs.getDomain(hostname); // Use tldjs to extract the root domain 6767 return rootDomain && (useSubdomain == true) ? '.' + rootDomain : hostname; // Add leading dot for cookies 6768}
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.