PageSourceSearch

https://dragonfly.com.pt/wp-content/cache/wpfc-minified/7kdh9x8f/dfr8e.js

js dragonfly.com.pt collected 2026-10-06 19:19:58 UTC 122,027 bytes, 3,012 lines download raw bytes

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

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.