
    //console.log(getCookie('pageview_event_id'));
    //var external_id = getCookie('external_id');
    var pageview_event_id = getCookie('pageview_event_id');
    var pp_price_precision = 2;
    var deferred_loading = 0;
    var deferred_seconds = 0;
    var event_time = 1730223650;
    var local_time = new Date().getTime();
    var consentStatus = false;
    var pp_aurl = 'https://sebio.be/fr/module/facebookconversiontrackingplus/AjaxConversion'.replace(/&amp;/g, "&");

    function generateEventId(eventName, round) {
        //return window.event_id_gen;
        round = (typeof round !== 'undefined') ? round : 10;
        return '0' + '.' + eventName + '.' + generateEventTime(round);
    }

    // Get cookie by name
    function getCookie(cName) {
        const name = cName + "=";
        const cDecoded = decodeURIComponent(document.cookie); //to be careful
        const cArr = cDecoded.split('; ');
        let res;
        cArr.forEach(val => {
            if (val.indexOf(name) === 0) res = val.substring(name.length);
        })
      return res
    }
    function deleteCookie(name) {
        //console.log('delete cookie: '+name);
        var paths = window.location.pathname.split('/');
        var pl = paths.length;
        var acupath = '';
        for (let i = 0; i < pl; i++) {
            acupath += '/' + paths[i];
            acupath = acupath.replace('//', '/');
            document.cookie = name + '=; Path=' + acupath + '; Domain=' + window.location.host + '; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
        }
    }
    function getRandomString(length) {
        var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        var result = '';
        for (var i = 0; i < length; i++) {
            result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
        }
        return result;
    }

    function generateEventTime(round) {
        return Math.floor(((new Date().getTime() - local_time) / 1000 + event_time) / round) * round;
    }

    function facebookpixelinit(tries) {
        if (typeof fbq == 'undefined') {
            
            !function(f,b,e,v,n,t,s){if (f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};if (!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,document,'script','https://connect.facebook.net/en_US/fbevents.js');
            
            initFbqPixels();
        } else if (typeof fbq == 'function' && typeof window.fbq_pageview == 'undefined') {
            initFbqPixels();
        } else {
            console.log('Facebook Pixel Already loaded');
        }
    }

    function initFbqPixels() {
                        fbq('init', '1981660968754727', {"client_ip_address":"3.145.83.221","client_user_agent":"Mozilla\/5.0 AppleWebKit\/537.36 (KHTML, like Gecko; compatible; ClaudeBot\/1.0; +claudebot@anthropic.com)","fbp":"fb.1.1730223650.jEShwALitxYb","country":"79adb2a2fce5c6ba215fe5f27f532d4e7edbac4b6a5e09e1ef3a08084a904621"});
                /* Code to avoid multiple pixels call */
        /* Used to make it compatible with onepagecheckout */
        if (typeof window.fbq_pageview == 'undefined') {
            //console.log('Header initialized');
            ppTrackEvent('PageView', {}, pageview_event_id);
                        window.fbq_pageview = 1;
            //console.log('Delete PageView Cookie');
            deleteCookie('pageview_event_id');
        }
    }

    // TODO finish the checkLocalStorage function check
        
        fctp_pageviewcount(20);

    function fctp_pageviewcount(tries) {
        if (typeof jQuery === 'undefined' || typeof fbq != 'function') {
            if (tries > 0) {
                setTimeout(function () { fctp_pageviewcount(tries - 1) }, 350);
            }
        } else {
            jQuery.ajax({
                url: pp_aurl,
                type: 'POST',
                cache: false,
                data: {
                    event: 'Pageviewcount',
                    source_url: location.href,
                    token: 'ca7570e6d4b3997d6cbe14412a789bba',
                }
            })
            .done(function (data) {
                if (data !== null && data.return == 'ok' && typeof data.current_page !== 'undefined') {
                    var page = data.current_page == 20 ? 'PagesViewedMore' + data.current_page : 'PagesViewed' + data.current_page;
                    ppTrackEvent(page, {
                        'currency': 'EUR',
                        'value': '1'
                    }, pageview_event_id);
                }
            })
            .fail(function (jqXHR, textStatus, errorThrown) {
                //console.log('Pixel Plus: Cookie consent could not be validated');
            });
        }
    }
    