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