PageSourceSearch

https://cjdropship.com/wp-content/plugins/pixelyoursite/dist/scripts/public.js?ver=9.4.7.1

js cjdropship.com collected 2026-10-03 21:17:58 UTC 113,558 bytes, 2,877 lines download raw bytes

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

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.