PageSourceSearch

https://www.digitrend.it/wp-content/plugins/pixelyoursite/dist/scripts/public.js?ver=10.2.0.2

js digitrend.it collected 2026-10-07 08:37:35 UTC 147,539 bytes, 3,551 lines download raw bytes

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

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.