PageSourceSearch

https://www.gorv.com.au/wp-content/plugins/pixelyoursite/dist/scripts/public.js?ver=7.1.2

js gorv.com.au collected 2026-09-28 23:36:31 UTC 46,175 bytes, 1,440 lines download raw bytes

1/* global pysOptions */
2
3// https://bitbucket.org/pixelyoursite/pys_pro_7/issues/7/possible-ie-11-error
4// https://tc39.github.io/ecma262/#sec-array.prototype.includes
5if (!Array.prototype.includes) {
6    Object.defineProperty(Array.prototype, 'includes', {
7        value: function (searchElement, fromIndex) {
8
9            if (this == null) {
10                throw new TypeError('"this" is null or not defined');
11            }
12
13            // 1. Let O be ? ToObject(this value).
14            var o = Object(this);
15
16            // 2. Let len be ? ToLength(? Get(O, "length")).
17            var len = o.length >>> 0;
18
19            // 3. If len is 0, return false.
20            if (len === 0) {
21                return false;
22            }
23
24            // 4. Let n be ? ToInteger(fromIndex).
25            //    (If fromIndex is undefined, this step produces the value 0.)
26            var n = fromIndex | 0;
27
28            // 5. If n ≥ 0, then
29            //  a. Let k be n.
30            // 6. Else n < 0,
31            //  a. Let k be len + n.
32            //  b. If k < 0, let k be 0.
33            var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
34
35            function sameValueZero(x, y) {
36                return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
37            }
38
39            // 7. Repeat, while k < len
40            while (k < len) {
41                // a. Let elementK be the result of ? Get(O, ! ToString(k)).
42                // b. If SameValueZero(searchElement, elementK) is true, return true.
43                if (sameValueZero(o[k], searchElement)) {
44                    return true;
45                }
46                // c. Increase k by 1.
47                k++;
48            }
49
50            // 8. Return false
51            return false;
52        }
53    });
54}
55
56!function ($, options) {
57
58    if (options.debug) {
59        console.log('PYS:', options);
60    }
61
62    var dummyPinterest = function () {
63
64        /**
65         * Public API
66         */
67        return {
68
69            isEnabled: function () {
70            },
71
72            disable: function () {
73            },
74
75            loadPixel: function () {
76            },
77
78            fireEvent: function (name, data) {
79                return false;
80            },
81
82            onCommentEvent: function () {
83            },
84
85            onDownloadEvent: function (params) {
86            },
87
88            onFormEvent: function (params) {
89            },
90
91            onWooAddToCartOnButtonEvent: function (product_id) {
92            },
93
94            onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, is_external, $form) {
95            },
96
97            onWooRemoveFromCartEvent: function (cart_item_hash) {
98            },
99
100            onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) {
101            },
102
103            onEddRemoveFromCartEvent: function (item) {
104            }
105
106        }
107
108    }();
109
110    var dummyBing = function () {
111
112        /**
113         * Public API
114         */
115        return {
116
117            isEnabled: function () {
118            },
119
120            disable: function () {
121            },
122
123            loadPixel: function () {
124            },
125
126            fireEvent: function (name, data) {
127                return false;
128            },
129
130            onAdSenseEvent: function () {
131            },
132
133            onClickEvent: function (params) {
134            },
135
136            onWatchVideo: function (params) {
137            },
138
139            onCommentEvent: function () {
140            },
141
142            onFormEvent: function (params) {
143            },
144
145            onDownloadEvent: function (params) {
146            },
147
148            onWooAddToCartOnButtonEvent: function (product_id) {
149            },
150
151            onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, is_external, $form) {
152            },
153
154            onWooRemoveFromCartEvent: function (cart_item_hash) {
155            },
156
157            onWooAffiliateEvent: function (product_id) {
158            },
159
160            onWooPayPalEvent: function () {
161            },
162
163            onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) {
164            },
165
166            onEddRemoveFromCartEvent: function (item) {
167            }
168
169        }
170
171    }();
172
173    var Utils = function (options) {
174
175        var Pinterest = dummyPinterest;
176
177        var Bing = dummyBing;
178
179        var gtag_loaded = false;
180
181        function loadPixels() {
182
183            if (!options.gdpr.all_disabled_by_api) {
184
185                if (!options.gdpr.facebook_disabled_by_api) {
186                    Facebook.loadPixel();
187                }
188
189                if (!options.gdpr.analytics_disabled_by_api) {
190                    Analytics.loadPixel();
191                }
192
193                if (!options.gdpr.pinterest_disabled_by_api) {
194                    Pinterest.loadPixel();
195                }
196
197                if (!options.gdpr.bing_disabled_by_api) {
198                    Bing.loadPixel();
199                }
200            }
201
202        }
203
204        /**
205         * PUBLIC API
206         */
207        return {
208
209            setupPinterestObject: function () {
210                Pinterest = window.pys.Pinterest || Pinterest;
211                return Pinterest;
212            },
213
214            setupBingObject: function () {
215                Bing = window.pys.Bing || Bing;
216                return Bing;
217            },
218
219            // Clone all object members to another and return it
220            copyProperties: function (from, to) {
221                for (var key in from) {
222                    to[key] = from[key];
223                }
224                return to;
225            },
226
227            // Returns array of elements with given tag name
228            getTagsAsArray: function (tag) {
229                return [].slice.call(document.getElementsByTagName(tag));
230            },
231
232            getRequestParams: function () {
233                return [];
234            },
235
236            /**
237             * Events
238             */
239
240            fireStaticEvents: function (pixel) {
241
242                if (options.staticEvents.hasOwnProperty(pixel)) {
243
244                    $.each(options.staticEvents[pixel], function (eventName, events) {
245                        $.each(events, function (index, eventData) {
246
247                            eventData.fired = eventData.fired || false;
248
249                            if (!eventData.fired) {
250
251                                var fired = false;
252
253                                // fire event
254                                if ('facebook' === pixel) {
255                                    fired = Facebook.fireEvent(eventName, eventData);
256                                } else if ('ga' === pixel) {
257                                    fired = Analytics.fireEvent(eventName, eventData);
258                                } else if ('pinterest' === pixel) {
259                                    fired = Pinterest.fireEvent(eventName, eventData);
260                                } else if ('bing' === pixel) {
261                                    fired = Bing.fireEvent(eventName, eventData);
262                                }
263
264                                // prevent event double event firing
265                                eventData.fired = fired;
266
267                            }
268
269                        });
270                    });
271
272                }
273
274            },
275
276            /**
277             * Load tag's JS
278             *
279             * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/
280             * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
281             */
282            loadGoogleTag: function (id) {
283
284                if (!gtag_loaded) {
285
286                    (function (window, document, src) {
287                        var a = document.createElement('script'),
288                            m = document.getElementsByTagName('script')[0];
289                        a.async = 1;
290                        a.src = src;
291                        m.parentNode.insertBefore(a, m);
292                    })(window, document, '//www.googletagmanager.com/gtag/js?id=' + id);
293
294                    window.dataLayer = window.dataLayer || [];
295                    window.gtag = window.gtag || function gtag() {
296                        dataLayer.push(arguments);
297                    };
298
299                    gtag('js', new Date());
300
301                    gtag_loaded = true;
302
303                }
304
305            },
306
307            /**
308             * GDPR
309             */
310
311            loadPixels: function () {
312
313                if (options.gdpr.ajax_enabled) {
314
315                    // retrieves actual PYS GDPR filters values which allow to avoid cache issues
316                    $.get({
317                        url: options.ajaxUrl,
318                        dataType: 'json',
319                        data: {
320                            action: 'pys_get_gdpr_filters_values'
321                        },
322                        success: function (res) {
323
324                            if (res.success) {
325
326                                options.gdpr.all_disabled_by_api = res.data.all_disabled_by_api;
327                                options.gdpr.facebook_disabled_by_api = res.data.facebook_disabled_by_api;
328                                options.gdpr.analytics_disabled_by_api = res.data.analytics_disabled_by_api;
329                                options.gdpr.google_ads_disabled_by_api = res.data.google_ads_disabled_by_api;
330                                options.gdpr.pinterest_disabled_by_api = res.data.pinterest_disabled_by_api;
331                                options.gdpr.bing_disabled_by_api = res.data.bing_disabled_by_api;
332
333                            }
334
335                            loadPixels();
336
337                        }
338                    });
339
340                } else {
341                    loadPixels();
342                }
343
344            },
345
346            consentGiven: function (pixel) {
347
348                /**
349                 * Cookiebot
350                 */
351                if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') {
352
353                    var cookiebot_consent_category = options.gdpr['cookiebot_' + pixel + '_consent_category'];
354
355                    if (options.gdpr[pixel + '_prior_consent_enabled']) {
356                        if (Cookiebot.consented === false || Cookiebot.consent[cookiebot_consent_category]) {
357                            return true;
358                        }
359                    } else {
360                        if (Cookiebot.consent[cookiebot_consent_category]) {
361                            return true;
362                        }
363                    }
364
365                    return false;
366
367                }
368
369                /**
370                 * Ginger – EU Cookie Law
371                 */
372                if (options.gdpr.ginger_integration_enabled) {
373
374                    var ginger_cookie = Cookies.get('ginger-cookie');
375
376                    if (options.gdpr[pixel + '_prior_consent_enabled']) {
377                        if (typeof ginger_cookie === 'undefined' || ginger_cookie === 'Y') {
378                            return true;
379                        }
380                    } else {
381                        if (ginger_cookie === 'Y') {
382                            return true;
383                        }
384                    }
385
386                    return false;
387
388                }
389
390                /**
391                 * Cookie Notice
392                 */
393                if (options.gdpr.cookie_notice_integration_enabled && typeof cnArgs !== 'undefined') {
394
395                    var cn_cookie = Cookies.get(cnArgs.cookieName);
396
397                    if (options.gdpr[pixel + '_prior_consent_enabled']) {
398                        if (typeof cn_cookie === 'undefined' || cn_cookie === 'true') {
399                            return true;
400                        }
401                    } else {
402                        if (cn_cookie === 'true') {
403                            return true;
404                        }
405                    }
406
407                    return false;
408
409                }
410
411                /**
412                 * Cookie Law Info
413                 */
414                if (options.gdpr.cookie_law_info_integration_enabled) {
415
416                    var cli_cookie = Cookies.get('viewed_cookie_policy');
417
418                    if (options.gdpr[pixel + '_prior_consent_enabled']) {
419                        if (typeof cli_cookie === 'undefined' || cli_cookie === 'yes') {
420                            return true;
421                        }
422                    } else {
423                        if (cli_cookie === 'yes') {
424                            return true;
425                        }
426                    }
427
428                    return false;
429
430                }
431
432                return true;
433
434            },
435
436            setupGdprCallbacks: function () {
437
438                /**
439                 * Cookiebot
440                 */
441                if (options.gdpr.cookiebot_integration_enabled && typeof Cookiebot !== 'undefined') {
442
443                    Cookiebot.onaccept = function () {
444
445                        if (Cookiebot.consent[options.gdpr.cookiebot_facebook_consent_category]) {
446                            Facebook.loadPixel();
447                        }
448
449                        if (Cookiebot.consent[options.gdpr.cookiebot_analytics_consent_category]) {
450                            Analytics.loadPixel();
451                        }
452
453                        if (Cookiebot.consent[options.gdpr.cookiebot_pinterest_consent_category]) {
454                            Pinterest.loadPixel();
455                        }
456
457                        if (Cookiebot.consent[options.gdpr.cookiebot_bing_consent_category]) {
458                            bing.loadPixel();
459                        }
460
461                    };
462
463                    Cookiebot.ondecline = function () {
464                        Facebook.disable();
465                        Analytics.disable();
466                        Pinterest.disable();
467                        Bing.disable();
468                    };
469
470                }
471
472                /**
473                 * Cookie Notice
474                 */
475                if (options.gdpr.cookie_notice_integration_enabled) {
476
477                    $(document).onFirst('click', '.cn-set-cookie', function () {
478
479                        if ($(this).data('cookie-set') === 'accept') {
480                            Facebook.loadPixel();
481                            Analytics.loadPixel();
482                            Pinterest.loadPixel();
483                            Bing.loadPixel();
484                        } else {
485                            Facebook.disable();
486                            Analytics.disable();
487                            Pinterest.disable();
488                            Bing.disable();
489                        }
490
491                    });
492
493                    $(document).onFirst('click', '.cn-revoke-cookie', function () {
494                        Facebook.disable();
495                        Analytics.disable();
496                        Pinterest.disable();
497                        Bing.disable();
498                    });
499
500                }
501
502                /**
503                 * Cookie Law Info
504                 */
505                if (options.gdpr.cookie_law_info_integration_enabled) {
506
507                    $(document).onFirst('click', '#cookie_action_close_header', function () {
508                        Facebook.loadPixel();
509                        Analytics.loadPixel();
510                        Pinterest.loadPixel();
511                        Bing.loadPixel();
512                    });
513
514                    $(document).onFirst('click', '#cookie_action_close_header_reject', function () {
515                        Facebook.disable();
516                        Analytics.disable();
517                        Pinterest.disable();
518                        Bing.disable();
519                    });
520
521                }
522
523            },
524
525            /**
526             * DOWNLOAD DOCS
527             */
528
529            getLinkExtension: function (link) {
530
531                // Remove anchor, query string and everything before last slash
532                link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#"));
533                link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?"));
534                link = link.substring(link.lastIndexOf("/") + 1, link.length);
535
536                // If there's a period left in the URL, then there's a extension
537                if (link.length > 0 && link.indexOf('.') !== -1) {
538                    link = link.substring(link.indexOf(".") + 1); // Remove everything but what's after the first period
539                    return link;
540                } else {
541                    return "";
542                }
543            },
544
545            getLinkFilename: function (link) {
546
547                // Remove anchor, query string and everything before last slash
548                link = link.substring(0, (link.indexOf("#") === -1) ? link.length : link.indexOf("#"));
549                link = link.substring(0, (link.indexOf("?") === -1) ? link.length : link.indexOf("?"));
550                link = link.substring(link.lastIndexOf("/") + 1, link.length);
551
552                // If there's a period left in the URL, then there's a extension
553                if (link.length > 0 && link.indexOf('.') !== -1) {
554                    return link;
555                } else {
556                    return "";
557                }
558            }
559
560        };
561
562    }(options);
563
564    var Facebook = function (options) {
565
566        var defaultEventTypes = [
567            'PageView',
568            'ViewContent',
569            'Search',
570            'AddToCart',
571            'AddToWishlist',
572            'InitiateCheckout',
573            'AddPaymentInfo',
574            'Purchase',
575            'Lead',
576
577            'Subscribe',
578            'CustomizeProduct',
579            'FindLocation',
580            'StartTrial',
581            'SubmitApplication',
582            'Schedule',
583            'Contact',
584            'Donate'
585        ];
586
587        var initialized = false;
588
589        function fireEvent(name, data) {
590
591            var actionType = defaultEventTypes.includes(name) ? 'track' : 'trackCustom';
592
593            var params = {};
594            Utils.copyProperties(data, params);
595            Utils.copyProperties(options.commonEventParams, params);
596
597            if (options.debug) {
598                console.log('[Facebook] ' + name, params);
599            }
600
601            fbq(actionType, name, params);
602
603        }
604
605        /**
606         * Public API
607         */
608        return {
609
610            isEnabled: function () {
611                return options.hasOwnProperty('facebook');
612            },
613
614            disable: function () {
615                initialized = false;
616            },
617
618            /**
619             * Load pixel's JS
620             */
621            loadPixel: function () {
622
623                if (initialized || !this.isEnabled() || !Utils.consentGiven('facebook')) {
624                    return;
625                }
626
627                !function (f, b, e, v, n, t, s) {
628                    if (f.fbq) return;
629                    n = f.fbq = function () {
630                        n.callMethod ?
631                            n.callMethod.apply(n, arguments) : n.queue.push(arguments)
632                    };
633                    if (!f._fbq) f._fbq = n;
634                    n.push = n;
635                    n.loaded = !0;
636                    n.version = '2.0';
637                    n.agent = 'dvpixelyoursite';
638                    n.queue = [];
639                    t = b.createElement(e);
640                    t.async = !0;
641                    t.src = v;
642                    s = b.getElementsByTagName(e)[0];
643                    s.parentNode.insertBefore(t, s)
644                }(window,
645                    document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
646
647                // initialize pixel
648                options.facebook.pixelIds.forEach(function (pixelId) {
649
650                    if (options.facebook.removeMetadata) {
651                        fbq('set', 'autoConfig', false, pixelId);
652                    }
653
654                    fbq('init', pixelId, options.facebook.advancedMatching);
655
656                });
657
658                initialized = true;
659
660                Utils.fireStaticEvents('facebook');
661
662            },
663
664            fireEvent: function (name, data) {
665
666                if (!initialized || !this.isEnabled()) {
667                    return false;
668                }
669
670                data.delay = data.delay || 0;
671                data.params = data.params || {};
672
673                if (data.delay === 0) {
674
675                    fireEvent(name, data.params);
676
677                } else {
678
679                    setTimeout(function (name, params) {
680                        fireEvent(name, params);
681                    }, data.delay * 1000, name, data.params);
682
683                }
684
685                return true;
686
687            },
688
689            onCommentEvent: function () {
690
691                if (initialized && this.isEnabled() && options.facebook.commentEventEnabled) {
692
693                    this.fireEvent('Comment', {
694                        params: Utils.copyProperties(options.facebook.contentParams, {})
695                    });
696
697                }
698
699            },
700
701            onDownloadEvent: function (params) {
702
703                if (initialized && this.isEnabled() && options.facebook.downloadEnabled) {
704
705                    this.fireEvent('Download', {
706                        params: Utils.copyProperties(options.facebook.contentParams, params)
707                    });
708
709                }
710
711            },
712
713            onFormEvent: function (params) {
714
715                if (initialized && this.isEnabled() && options.facebook.formEventEnabled) {
716
717                    this.fireEvent('Form', {
718                        params: Utils.copyProperties(options.facebook.contentParams, params)
719                    });
720
721                }
722
723            },
724
725            onWooAddToCartOnButtonEvent: function (product_id) {
726
727                if (window.pysWooProductData.hasOwnProperty(product_id)) {
728                    if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) {
729
730                        this.fireEvent('AddToCart', {
731                            params: Utils.copyProperties(window.pysWooProductData[product_id]['facebook'], {})
732                        });
733
734                    }
735                }
736
737            },
738
739            onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, $form) {
740
741                window.pysWooProductData = window.pysWooProductData || [];
742
743                if (window.pysWooProductData.hasOwnProperty(product_id)) {
744                    if (window.pysWooProductData[product_id].hasOwnProperty('facebook')) {
745
746                        if (is_variable && !options.facebook.wooVariableAsSimple) {
747                            product_id = parseInt($form.find('input[name="variation_id"]').val());
748                        }
749
750                        var params = Utils.copyProperties(window.pysWooProductData[product_id]['facebook'], {});
751
752                        // maybe customize value option
753                        if (options.woo.addToCartOnButtonValueEnabled && options.woo.addToCartOnButtonValueOption !== 'global') {
754                            params.value = params.value * qty;
755                        }
756
757                        // only when non Facebook for WooCommerce logic used
758                        if (params.hasOwnProperty('contents')) {
759                            params.contents[0].quantity = qty;
760                        }
761
762                        this.fireEvent('AddToCart', {
763                            params: params
764                        });
765
766                    }
767                }
768
769            },
770
771            onWooRemoveFromCartEvent: function (cart_item_hash) {
772
773                window.pysWooRemoveFromCartData = window.pysWooRemoveFromCartData || [];
774
775                if (window.pysWooRemoveFromCartData[cart_item_hash].hasOwnProperty('facebook')) {
776
777                    this.fireEvent('RemoveFromCart', {
778                        params: Utils.copyProperties(window.pysWooRemoveFromCartData[cart_item_hash]['facebook'], {})
779                    });
780
781                }
782
783            },
784
785            onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) {
786
787                if (window.pysEddProductData.hasOwnProperty(download_id)) {
788
789                    var index;
790
791                    if (price_index) {
792                        index = download_id + '_' + price_index;
793                    } else {
794                        index = download_id;
795                    }
796
797                    if (window.pysEddProductData[download_id].hasOwnProperty(index)) {
798                        if (window.pysEddProductData[download_id][index].hasOwnProperty('facebook')) {
799
800                            var params = Utils.copyProperties(window.pysEddProductData[download_id][index]['facebook'], {});
801
802                            // maybe customize value option
803                            if (options.edd.addToCartOnButtonValueEnabled && options.edd.addToCartOnButtonValueOption !== 'global') {
804                                params.value = params.value * qty;
805                            }
806
807                            // update contents qty param
808                            var contents = JSON.parse(params.contents);
809                            contents[0].quantity = qty;
810                            params.contents = JSON.stringify(contents);
811
812                            this.fireEvent('AddToCart', {
813                                params: params
814                            });
815
816                        }
817                    }
818
819                }
820
821            },
822
823            onEddRemoveFromCartEvent: function (item) {
824
825                if (item.hasOwnProperty('facebook')) {
826
827                    this.fireEvent('RemoveFromCart', {
828                        params: Utils.copyProperties(item['facebook'], {})
829                    });
830
831                }
832
833            }
834
835        };
836
837    }(options);
838
839    var Analytics = function (options) {
840
841        var initialized = false;
842
843        /**
844         * Fires event
845         *
846         * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data
847         * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/events
848         * @link: https://developers.google.com/gtagjs/reference/event
849         * @link: https://developers.google.com/gtagjs/reference/parameter
850         *
851         * @link: https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
852         *
853         * @param name
854         * @param data
855         */
856        function fireEvent(name, data) {
857
858            var eventParams = Utils.copyProperties(data, {});
859
860            var _fireEvent = function (tracking_id) {
861
862                var params = Utils.copyProperties(eventParams, {send_to: tracking_id});
863
864                if (options.debug) {
865                    console.log('[Google Analytics #' + tracking_id + '] ' + name, params);
866                }
867
868                gtag('event', name, params);
869
870            };
871
872            options.ga.trackingIds.forEach(function (tracking_id) {
873                _fireEvent(tracking_id);
874            });
875
876        }
877
878        /**
879         * Public API
880         */
881        return {
882
883            isEnabled: function () {
884                return options.hasOwnProperty('ga');
885            },
886
887            disable: function () {
888                initialized = false;
889            },
890
891            loadPixel: function () {
892
893                if (initialized || !this.isEnabled() || !Utils.consentGiven('analytics')) {
894                    return;
895                }
896
897                Utils.loadGoogleTag(options.ga.trackingIds[0]);
898
899                var config = {
900                    'link_attribution': options.ga.enhanceLinkAttr,
901                    'anonymize_ip': options.ga.anonimizeIP
902                };
903
904                // Cross-Domain tracking
905                if (options.ga.crossDomainEnabled) {
906                    config.linker = {
907                        accept_incoming: options.ga.crossDomainAcceptIncoming,
908                        domains: options.ga.crossDomainDomains
909                    };
910                }
911
912                // configure tracking ids
913                options.ga.trackingIds.forEach(function (trackingId) {
914                    gtag('config', trackingId, config);
915                });
916
917                initialized = true;
918
919                Utils.fireStaticEvents('ga');
920
921            },
922
923            fireEvent: function (name, data) {
924
925                if (!initialized || !this.isEnabled()) {
926                    return false;
927                }
928
929                data.delay = data.delay || 0;
930                data.params = data.params || {};
931
932                if (data.delay === 0) {
933
934                    fireEvent(name, data.params);
935
936                } else {
937
938                    setTimeout(function (name, params) {
939                        fireEvent(name, params);
940                    }, data.delay * 1000, name, data.params);
941
942                }
943
944                return true;
945
946            },
947
948            onCommentEvent: function () {
949
950                if (initialized && this.isEnabled() && options.ga.commentEventEnabled) {
951
952                    this.fireEvent(window.location.href, {
953                        params: {
954                            event_category: 'Comment',
955                            event_label: $(document).find('title').text(),
956                            non_interaction: options.ga.commentEventNonInteractive
957                        }
958                    });
959
960                }
961
962            },
963
964            onDownloadEvent: function (params) {
965
966                if (initialized && this.isEnabled() && options.ga.downloadEnabled) {
967
968                    this.fireEvent(params.download_url, {
969                        params: {
970                            event_category: 'Download',
971                            event_label: params.download_name,
972                            non_interaction: options.ga.downloadEventNonInteractive
973                        }
974                    });
975
976                }
977
978            },
979
980            onFormEvent: function (params) {
981
982                if (initialized && this.isEnabled() && options.ga.formEventEnabled) {
983
984                    this.fireEvent(window.location.href, {
985                        params: {
986                            event_category: 'Form',
987                            event_label: params.form_class,
988                            non_interaction: options.ga.formEventNonInteractive
989                        }
990                    });
991
992                }
993
994            },
995
996            onWooAddToCartOnButtonEvent: function (product_id) {
997
998                if (window.pysWooProductData.hasOwnProperty(product_id)) {
999                    if (window.pysWooProductData[product_id].hasOwnProperty('ga')) {
1000
1001                        this.fireEvent('add_to_cart', {
1002                            params: window.pysWooProductData[product_id]['ga']
1003                        });
1004
1005                    }
1006                }
1007
1008            },
1009
1010            onWooAddToCartOnSingleEvent: function (product_id, qty, is_variable, $form) {
1011
1012                window.pysWooProductData = window.pysWooProductData || [];
1013
1014                if (is_variable) {
1015                    product_id = parseInt($form.find('input[name="variation_id"]').val());
1016                }
1017
1018                if (window.pysWooProductData.hasOwnProperty(product_id)) {
1019                    if (window.pysWooProductData[product_id].hasOwnProperty('ga')) {
1020
1021                        var params = Utils.copyProperties(window.pysWooProductData[product_id]['ga'], {});
1022
1023                        // maybe customize value option
1024                        if (options.woo.addToCartOnButtonValueEnabled && options.woo.addToCartOnButtonValueOption !== 'global') {
1025                            params.items[0].price = params.items[0].price * qty;
1026                        }
1027
1028                        // update items qty param
1029                        params.items[0].quantity = qty;
1030
1031                        this.fireEvent('add_to_cart', {
1032                            params: params
1033                        });
1034
1035                    }
1036                }
1037
1038            },
1039
1040            onWooRemoveFromCartEvent: function (cart_item_hash) {
1041
1042                window.pysWooRemoveFromCartData = window.pysWooRemoveFromCartData || [];
1043
1044                if (window.pysWooRemoveFromCartData[cart_item_hash].hasOwnProperty('ga')) {
1045
1046                    this.fireEvent('remove_from_cart', {
1047                        params: Utils.copyProperties(window.pysWooRemoveFromCartData[cart_item_hash]['ga'], {})
1048                    });
1049
1050                }
1051
1052            },
1053
1054            onEddAddToCartOnButtonEvent: function (download_id, price_index, qty) {
1055
1056                if (window.pysEddProductData.hasOwnProperty(download_id)) {
1057
1058                    var index;
1059
1060                    if (price_index) {
1061                        index = download_id + '_' + price_index;
1062                    } else {
1063                        index = download_id;
1064                    }
1065
1066                    if (window.pysEddProductData[download_id].hasOwnProperty(index)) {
1067                        if (window.pysEddProductData[download_id][index].hasOwnProperty('ga')) {
1068
1069                            var params = Utils.copyProperties(window.pysEddProductData[download_id][index]['ga'], {});
1070
1071                            // update items qty param
1072                            params.items[0].quantity = qty;
1073
1074                            this.fireEvent('add_to_cart', {
1075                                params: params
1076                            });
1077
1078                        }
1079                    }
1080
1081                }
1082
1083            },
1084
1085            onEddRemoveFromCartEvent: function (item) {
1086
1087                if (item.hasOwnProperty('ga')) {
1088
1089                    this.fireEvent('remove_from_cart', {
1090                        params: Utils.copyProperties(item['ga'], {})
1091                    });
1092
1093                }
1094
1095            }
1096
1097        };
1098
1099    }(options);
1100
1101    window.pys = window.pys || {};
1102    window.pys.Facebook = Facebook;
1103    window.pys.Analytics = Analytics;
1104    window.pys.Utils = Utils;
1105
1106    $(document).ready(function () {
1107
1108        var Pinterest = Utils.setupPinterestObject();
1109        var Bing = Utils.setupBingObject();
1110
1111        Utils.setupGdprCallbacks();
1112
1113        // setup WooCommerce events
1114        if (options.woo.enabled) {
1115
1116            // WooCommerce AddToCart
1117            if (options.woo.addToCartOnButtonEnabled) {
1118
1119                // Loop, any kind of "simple" product, except external
1120                $('.add_to_cart_button:not(.product_type_variable)').click(function (e) {
1121
1122                    var product_id = $(this).data('product_id');
1123
1124                    if (typeof product_id !== 'undefined') {
1125                        Facebook.onWooAddToCartOnButtonEvent(product_id);
1126                        Analytics.onWooAddToCartOnButtonEvent(product_id);
1127                        Pinterest.onWooAddToCartOnButtonEvent(product_id);
1128                        Bing.onWooAddToCartOnButtonEvent(product_id);
1129                    }
1130
1131                });
1132
1133                // Single Product
1134                $('.single_add_to_cart_button').click(function (e) {
1135
1136                    var $button = $(this);
1137
1138                    if ($button.hasClass('disabled')) {
1139                        return;
1140                    }
1141
1142                    var $form = $button.closest('form');
1143
1144                    if ($form.length === 0) {
1145                        return;
1146                    }
1147
1148                    var is_variable = $form.hasClass('variations_form');
1149
1150                    var product_id;
1151                    var qty;
1152
1153                    if (is_variable) {
1154                        product_id = parseInt($form.find('*[name="add-to-cart"]').val());
1155                        qty = parseInt($form.find('input[name="quantity"]').val());
1156                    } else {
1157                        product_id = parseInt($form.find('*[name="add-to-cart"]').val());
1158                        qty = parseInt($form.find('input[name="quantity"]').val());
1159                    }
1160
1161                    Facebook.onWooAddToCartOnSingleEvent(product_id, qty, is_variable, $form);
1162                    Analytics.onWooAddToCartOnSingleEvent(product_id, qty, is_variable, $form);
1163                    Pinterest.onWooAddToCartOnSingleEvent(product_id, qty, is_variable, false, $form);
1164                    Bing.onWooAddToCartOnSingleEvent(product_id, qty, is_variable, false, $form);
1165
1166                });
1167
1168            }
1169
1170            // WooCommerce RemoveFromCart
1171            if (options.woo.removeFromCartEnabled) {
1172
1173                $('body').on('click', options.woo.removeFromCartSelector, function (e) {
1174
1175                    var $a = $(e.currentTarget),
1176                        href = $a.attr('href');
1177
1178                    // extract cart item hash from remove button URL
1179                    var regex = new RegExp("[\\?&]remove_item=([^&#]*)"),
1180                        results = regex.exec(href);
1181
1182                    if (results !== null) {
1183
1184                        var item_hash = results[1];
1185                        window.pysWooRemoveFromCartData = window.pysWooRemoveFromCartData || [];
1186
1187                        if (window.pysWooRemoveFromCartData.hasOwnProperty(item_hash)) {
1188                            Facebook.onWooRemoveFromCartEvent(item_hash);
1189                            Analytics.onWooRemoveFromCartEvent(item_hash);
1190                            Pinterest.onWooRemoveFromCartEvent(item_hash);
1191                            Bing.onWooRemoveFromCartEvent(item_hash);
1192                        }
1193
1194                    }
1195
1196                });
1197
1198            }
1199
1200        }
1201
1202        // setup EDD events
1203        if (options.edd.enabled) {
1204
1205            // EDD AddToCart
1206            if (options.edd.addToCartOnButtonEnabled) {
1207
1208                $('form.edd_download_purchase_form .edd-add-to-cart').click(function (e) {
1209
1210                    var $button = $(this);
1211                    var $form = $button.closest('form');
1212                    var variable_price = $button.data('variablePrice'); // yes/no
1213                    var price_mode = $button.data('priceMode'); // single/multi
1214                    var ids = [];
1215                    var quantities = [];
1216                    var qty;
1217                    var id;
1218
1219                    if (variable_price === 'yes' && price_mode === 'multi') {
1220
1221                        id = $form.find('input[name="download_id"]').val();
1222
1223                        // get selected variants
1224                        $.each($form.find('input[name="edd_options[price_id][]"]:checked'), function (i, el) {
1225                            ids.push(id + '_' + $(el).val());
1226                        });
1227
1228                        // get qty for selected variants
1229                        $.each(ids, function (i, variant_id) {
1230
1231                            var variant_index = variant_id.split('_', 2);
1232                            qty = $form.find('input[name="edd_download_quantity_' + variant_index[1] + '"]').val();
1233
1234                            if (typeof qty !== 'undefined') {
1235                                quantities.push(qty);
1236                            } else {
1237                                quantities.push(1);
1238                            }
1239
1240                        });
1241
1242                    } else if (variable_price === 'yes' && price_mode === 'single') {
1243
1244                        id = $form.find('input[name="download_id"]').val();
1245                        ids.push(id + '_' + $form.find('input[name="edd_options[price_id][]"]:checked').val());
1246
1247                        qty = $form.find('input[name="edd_download_quantity"]').val();
1248
1249                        if (typeof qty !== 'undefined') {
1250                            quantities.push(qty);
1251                        } else {
1252                            quantities.push(1);
1253                        }
1254
1255                    } else {
1256
1257                        ids.push($button.data('downloadId'));
1258
1259                        qty = $form.find('input[name="edd_download_quantity"]').val();
1260
1261                        if (typeof qty !== 'undefined') {
1262                            quantities.push(qty);
1263                        } else {
1264                            quantities.push(1);
1265                        }
1266
1267
1268                    }
1269
1270                    // fire event for each download/variant
1271                    $.each(ids, function (i, download_id) {
1272
1273                        var q = parseInt(quantities[i]);
1274                        var variant_index = download_id.toString().split('_', 2);
1275                        var price_index;
1276
1277                        if (variant_index.length === 2) {
1278                            download_id = variant_index[0];
1279                            price_index = variant_index[1];
1280                        }
1281
1282                        Facebook.onEddAddToCartOnButtonEvent(download_id, price_index, q);
1283                        Analytics.onEddAddToCartOnButtonEvent(download_id, price_index, q);
1284                        Pinterest.onEddAddToCartOnButtonEvent(download_id, price_index, q);
1285                        Bing.onEddAddToCartOnButtonEvent(download_id, price_index, q);
1286
1287                    });
1288
1289                });
1290
1291            }
1292
1293            // EDD RemoveFromCart
1294            if (options.edd.removeFromCartEnabled) {
1295
1296                $('form#edd_checkout_cart_form .edd_cart_remove_item_btn').click(function (e) {
1297
1298                    var href = $(this).attr('href');
1299                    var key = href.substring(href.indexOf('=') + 1).charAt(0);
1300
1301                    window.pysEddRemoveFromCartData = window.pysEddRemoveFromCartData || [];
1302
1303                    if (window.pysEddRemoveFromCartData[key]) {
1304
1305                        var item = window.pysEddRemoveFromCartData[key];
1306
1307                        Facebook.onEddRemoveFromCartEvent(item);
1308                        Analytics.onEddRemoveFromCartEvent(item);
1309                        Pinterest.onEddRemoveFromCartEvent(item);
1310                        Bing.onEddRemoveFromCartEvent(item);
1311
1312                    }
1313
1314                });
1315
1316            }
1317
1318        }
1319
1320        // setup Comment Event
1321        if (options.commentEventEnabled) {
1322
1323            $('form.comment-form').submit(function () {
1324
1325                Facebook.onCommentEvent();
1326                Analytics.onCommentEvent();
1327                Pinterest.onCommentEvent();
1328                Bing.onCommentEvent();
1329
1330            });
1331
1332        }
1333
1334        // setup DownloadDocs event
1335        if (options.downloadEventEnabled && options.downloadExtensions.length > 0) {
1336
1337            $('body').click(function (event) {
1338
1339                var el = event.srcElement || event.target;
1340
1341                /* Loop up the DOM tree through parent elements if clicked element is not a link (eg: an image inside a link) */
1342                while (el && (typeof el.tagName === 'undefined' || el.tagName.toLowerCase() !== 'a' || !el.href)) {
1343                    el = el.parentNode;
1344                }
1345
1346                if (el && el.href) {
1347
1348                    var extension = Utils.getLinkExtension(el.href);
1349                    var track_download = false;
1350
1351                    if (extension.length > 0) {
1352
1353                        for (i = 0, len = options.downloadExtensions.length; i < len; ++i) {
1354                            if (options.downloadExtensions[i] === extension) {
1355                                track_download = true;
1356                                break;
1357                            }
1358                        }
1359
1360                    }
1361
1362                    if (track_download) {
1363
1364                        var params = {
1365                            download_url: el.href,
1366                            download_type: extension,
1367                            download_name: Utils.getLinkFilename(el.href)
1368                        };
1369
1370                        Facebook.onDownloadEvent(params);
1371                        Analytics.onDownloadEvent(params);
1372                        Pinterest.onDownloadEvent(params);
1373                        Bing.onDownloadEvent(params);
1374
1375                    }
1376
1377                }
1378
1379            });
1380
1381        }
1382
1383        // setup Form Event
1384        if (options.formEventEnabled) {
1385
1386            $(document).onFirst('submit', 'form', function () {
1387
1388                var $form = $(this);
1389
1390                // exclude WP forms
1391                if ($form.hasClass('comment-form') || $form.hasClass('search-form') || $form.attr('id') === 'adminbarsearch') {
1392                    return;
1393                }
1394
1395                // exclude Woo forms
1396                if ($form.hasClass('woocommerce-product-search') || $form.hasClass('cart') || $form.hasClass('woocommerce-cart-form')
1397                    || $form.hasClass('woocommerce-shipping-calculator') || $form.hasClass('checkout') || $form.hasClass('checkout_coupon')) {
1398                    return;
1399                }
1400
1401                // exclude EDD forms
1402                if ($form.hasClass('edd_form') || $form.hasClass('edd_download_purchase_form')) {
1403                    return;
1404                }
1405
1406                var params = {
1407                    form_id: $form.attr('id'),
1408                    form_class: $form.attr('class')
1409                };
1410
1411                Facebook.onFormEvent(params);
1412                Analytics.onFormEvent(params);
1413                Pinterest.onFormEvent(params);
1414                Bing.onFormEvent(params);
1415
1416            });
1417
1418            // Ninja Forms
1419            $(document).onFirst('nfFormSubmitResponse', function (e, data) {
1420
1421                var params = {
1422                    form_id: data.response.data.form_id,
1423                    form_title: data.response.data.settings.title
1424                };
1425
1426                Facebook.onFormEvent(params);
1427                Analytics.onFormEvent(params);
1428                Pinterest.onFormEvent(params);
1429                Bing.onFormEvent(params);
1430
1431            });
1432
1433        }
1434
1435        // load pixel APIs
1436        Utils.loadPixels();
1437
1438    });
1439
1440}(jQuery, pysOptions);

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.