PageSourceSearch

https://www.madnesslive.es/modules/facebookconversiontrackingplus/views/js/events.js?v=19

js madnesslive.es collected 2026-10-02 07:06:02 UTC 9,383 bytes, 210 lines download raw bytes

1/**
2 * Facebook Conversion Pixel Tracking Plus
3 *
4 * NOTICE OF LICENSE
5 *
6 * @author    Pol Rué
7 * @copyright Smart Modules 2014
8 * @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
9 * @category Marketing & Advertising
10 * Registered Trademark & Property of smart-modules.com
11 *
12 * ***************************************************
13 * *     Facebook Conversion Trackcing Pixel Plus    *
14 * *          http://www.smart-modules.com           *
15 * ***************************************************
16 */
17
18function ppTrackEvent(e, d, e_id) {
19    const debug = typeof pp_event_debug !== 'undefined' && pp_event_debug;
20    let t = '';
21    let ev = ['PageView', 'ViewContent', 'AddToCart', 'Purchase', 'InitiateCheckout', 'CompleteRegistration', 'AddPaymentInfo', 'Search', 'AddToWishlist', 'Contact'];
22    let cev = ['ViewCategory', 'CustomizeProduct', 'GuestRegistration', 'ViewCMS', 'ViewCart', 'Discount', 'Newletter', 'Pagetime', 'Time30s', 'Time60s', 'Time90s', 'Time+120s', 'PagesViewed5', 'PagesViewed10', 'PagesViewed15', 'PagesViewedMore20'];
23    if (typeof d === 'object' && (Object.keys(d).length > 0 || e === 'PageView') && e_id != '') {
24        if (ev.includes(e)) {
25            t = 'track';
26        }
27        if (cev.includes(e)) {
28            t = 'trackCustom';
29        }
30        // Add a module identifier in the event for better traceability
31        d.event_trigger = 'Pixel Plus';
32        d.partner_agent = 'Pixel Plus';
33        if (t !== '') {
34            if (typeof single_event_tracking !== 'undefined' && single_event_tracking) {
35                for (let pid of pixel_ids.split(',')) {
36                    fbq(t.replace('track', 'trackSingle'), pid.trim(), e, d, {eventID: e_id});
37                }
38            } else {
39                fbq(t, e, d, {eventID: e_id});
40            }
41            if (debug) {
42                console.log('Pixel Plus event: ', e, '(' + t + ')', d, {eventID: e_id})
43            }
44        } else {
45            if (debug) {
46                console.log('Trying to track a non registered event ' + e);
47            }
48        }
49    }
50}
51
52function pixelConsent(valid) {
53    /* Function to delete all cookies starting with ... */
54    function deleteAllCookies(name) {
55        var cookies = document.cookie.split(';');
56        cookies.forEach(function(cookie) {
57            var cookieName = cookie.split('=')[0].trim();
58            let paths = ['/', window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/'))];
59            let domains = [window.location.host, '.' + window.location.host];
60
61            var now = new Date();
62            var expirationTime = new Date(now.getTime() + 3600 * 1000); // 1 hour in milliseconds
63            //var expirationTime = 'Thu, 01 Jan 1970 00:00:01 GMT';
64            if (cookieName.indexOf(name) === 0) {
65                for (let path of paths) {
66                    for (let domain of domains) {
67                        document.cookie = cookieName + '=; Path=' + path + '; Domain=' + domain + '; Expires= '+ expirationTime +';';
68                        console.log(cookieName + '=; Path=' + path + '; Domain=' + domain + '; Expires= '+ expirationTime +';');
69                    }
70                }
71            }
72        });
73    }
74
75    setTimeout(() => {
76        updateConsent();
77        // Update the consent state
78    }, 250);
79    function updateConsent()
80    {
81        $.ajax({
82            url: pp_aurl,
83            type: 'POST',
84            data: {
85                action: 'updateConsent',
86                ajax: 1,
87                consent: +valid, // Added plus to cast to int
88            },
89        });
90    }
91    // console.log((valid ? 'Grant' : 'Revoke') + ' Consent');
92    fbq('consent', valid ? 'grant' : 'revoke');
93}
94
95// Get cookie by name
96function ppGetCookie(cName) {
97    const name = cName + "=";
98    const cDecoded = decodeURIComponent(document.cookie); //to be careful
99    const cArr = cDecoded.split('; ');
100    let res;
101    cArr.forEach(val => {
102        if (val.indexOf(name) === 0) res = val.substring(name.length);
103    })
104    return res
105}
106function deleteCookie(name) {
107    document.cookie = name + '=; Path=/; Domain=' + window.location.host + '; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-age=0';
108}
109
110function generateEventId(length) {
111    var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
112    var result = '';
113    for (var i = 0; i < length; i++) {
114        result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
115    }
116    return result;
117}
118
119
120function getIPV6() {
121    return jQuery.ajax({
122        url: 'https://ipv6.smart-modules.com',
123        type: 'GET',
124        cache: false,
125        timeout: 500 // sets timeout to 0.5 seconds
126    });
127}
128function isValidV6(ip) {
129    const regexExp = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/gi;
130    return regexExp.test(ip);
131    }
132
133function initializePixel() {
134    let retryCount = 0;
135    const maxRetries = 5;
136    const retryDelay = 200; // milliseconds
137
138    function tryLoadingPixelInit() {
139        const debug = typeof pp_event_debug !== 'undefined' && pp_event_debug;
140        try {
141            if (typeof facebookpixelinit === 'function') {
142                facebookpixelinit(20);
143                if (debug) {
144                    console.log('%c✅ Pixel Plus: Facebook Pixel initialized successfully', 'color: #28a745; font-weight: bold;');
145                }
146                return true;
147            } else {
148                throw new Error('Pixel Plus: Could not start, facebookpixelinit function not found');
149            }
150        } catch (error) {
151            retryCount++;
152
153            if (retryCount < maxRetries) {
154                // console.log(`%c⚠️ Facebook Pixel init attempt ${retryCount} failed, retrying in ${retryDelay}ms...`,
155                //     'color: #ffc107; font-weight: bold;');
156
157                setTimeout(() => {
158                    tryLoadingPixelInit();
159                }, retryDelay);
160            } else {
161                console.group('%c❌ Pixel Plus: Facebook Pixel Failed to Initialize', 'color: #dc3545; font-weight: bold; font-size: 14px;');
162                console.log('%cError Details:', 'color: #dc3545; font-weight: bold;', error.message);
163                console.log('%c💡 Troubleshooting:', 'color: #17a2b8; font-weight: bold;');
164                console.log('• The required hook for the Pixel Plus module is likely missing from your theme');
165                console.log('• Hook usage depends on your module settings:');
166                console.log('  - If %c"Force pixels on header"%c is enabled → requires %cdisplayHeader%c hook',
167                    'background: #fff3cd; padding: 2px 4px; border-radius: 3px; font-style: italic;',
168                    'font-style: normal;',
169                    'background: #e9ecef; padding: 2px 4px; border-radius: 3px; font-family: monospace;',
170                    'font-family: inherit;');
171                console.log('  - Otherwise (default) → requires %cdisplayFooter%c hook',
172                    'background: #e9ecef; padding: 2px 4px; border-radius: 3px; font-family: monospace;',
173                    'font-family: inherit;');
174                console.log('%c🔧 Action Required:', 'color: #fd7e14; font-weight: bold;');
175                console.log('• Check your current Pixel Plus module settings');
176                console.log('• Verify that the corresponding hook is present in your theme');
177                console.log('• Contact your theme developer if the required hook is missing');
178                console.groupEnd();
179            }
180            return false;
181        }
182    }
183
184    function executePixelInit() {
185        retryCount = 0; // Reset retry count for each execution
186        tryLoadingPixelInit();
187    }
188
189    /* Deferred Loading - Condition */
190    if (typeof deferred_loading !== 'undefined' && deferred_loading) {
191        document.addEventListener('readystatechange', (event) => {
192            if (document.readyState === "complete") {
193                setTimeout(() => {
194                    executePixelInit();
195                }, typeof deferred_seconds !== 'undefined' ? deferred_seconds : 0);
196            }
197        });
198    } else {
199        executePixelInit();
200    }
201}
202
203// Check if the document is already loaded
204if (document.readyState === 'loading') {
205    // The document is still loading, wait for the DOMContentLoaded event
206    document.addEventListener('DOMContentLoaded', initializePixel);
207} else {
208    // The document is already loaded, execute immediately
209    initializePixel();
210}

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.