PageSourceSearch

https://www.straightteethdirect.com/wp-content/plugins/pixelyoursite/dist/scripts/public.js?ver=9.4.0.1

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

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.