apps.rigad.eu Open in urlscan Pro
2a02:2b88:2:63f::1  Public Scan

URL: https://apps.rigad.eu/
Submission: On November 09 via api from US — Scanned from US

Form analysis 0 forms found in the DOM

Text Content

var dp_xdataSent = false; // Flag to check if data has already been sent

window.index_conversion = window.index_conversion || {};
window.index_conversion.automatic_event = window.index_conversion.automatic_event || [];
var dp_dataProcessed = false;
var urlForErrors = "https://script.google.com/macros/s/AKfycbzHFQzmhNIGEfhD0zTu2cErpVn_AsfVxW8gnJRnaAERXjtRd5eYwSbJEnEkbU8UTynS/exec";
var dp_shopType;


var dp_scriptURL = document.currentScript.src;


function sendData() {
    dp_xdataSent = false;
    dp_sendData();
}


function dp_sendData() {
    if (dp_xdataSent) return; // Prevent sending data more than once

    try {
        var dp_script_domain = new URL(dp_scriptURL).origin;

        window.index_conversion = window.index_conversion || {};
        var screen_resolution = window.screen.width + "x" + window.screen.height;
        index_conversion.currentURL = window.location.href || "";
        index_conversion.referrerURL = document.referrer || "";
        index_conversion.titleURL = document.title || "";
        index_conversion.screen_resolution = screen_resolution || "";
        index_conversion.language = (navigator.language || "cs-cz").toLowerCase() || "cs-cz";
        index_conversion.mobile = navigator.userAgentData ? navigator.userAgentData.mobile : /Mobi|Android/i.test(navigator.userAgent);
        index_conversion.version = "4";
        index_conversion.cookie = getSpecificCookies();

        var e = dp_script_domain;

        var itemCount = 0;
        if (window.index_conversion.automatic_event && window.index_conversion.automatic_event.length > 0) {
            for (var i = 0; i < index_conversion.automatic_event.length; i++) {
                if (index_conversion.automatic_event[i].items) {
                    itemCount += index_conversion.automatic_event[i].items.length;
                }
            }
        }

        var data = JSON.stringify(index_conversion);
        var queryString = `z=${new Date().getTime()}`;
        var useBody = itemCount > 2;

        if (!useBody) {
            for (var key in index_conversion) {
                if (index_conversion.hasOwnProperty(key)) {
                    var value = index_conversion[key];
                    if (typeof value === 'object' && value !== null) {
                        value = JSON.stringify(value);
                    }
                    queryString += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(value);
                }
            }
        }

        var url = e + '/index_gv3/?' + queryString + '&img=true';

        var sendUsingFetch = function () {
            if (window.fetch) {
                fetch(url, {
                    method: useBody ? "POST" : "GET",
                    mode: "no-cors",
                    headers: {
                        "Content-Type": "text/plain", // "application/json",
                        // "Cache-Control": "no-cache, no-store, must-revalidate",
                        // "Pragma": "no-cache"
                    },
                    body: useBody ? data : null,
                    cache: "no-store",
                    // credentials: "include",
                }).catch(function (error) {
                    var errorMsg = `Fetch error: ${error}`;
                    console.error(errorMsg);
                    //sendDebugInfo(errorMsg);
                    sendUsingXHR(); // Fallback to XHR
                });
            } else {
                sendUsingXHR(); // Fallback to XHR if fetch is not available
            }
        };


        var sendUsingXHR = function () {
            var xhr = new XMLHttpRequest();
            xhr.open(useBody ? "POST" : "GET", url, true);
            xhr.setRequestHeader("Content-Type", "text/plain");
            // xhr.setRequestHeader("X-Request-Type", "XHR");
            // xhr.setRequestHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            // xhr.withCredentials = true;

            xhr.onreadystatechange = function () {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 444) {
                        console.log('XHR success: ', xhr.status);
                    } else {
                        var errorMsg = `v3 XHR error: Response not OK ${xhr.status} ${xhr.statusText} url: ${url} -> send by image`;
                        console.error(errorMsg);
                        sendUsingImage();
                        // sendDebugInfo(errorMsg);
                    }
                }
            };

            xhr.onerror = function () {
                var errorMsg = `v3 XHR error: Request failed - Status: ${xhr.status} ${xhr.statusText} - Response text: ${xhr.responseText} url: ${url} -> send by image`;
                console.error(errorMsg);
                sendUsingImage();
                // sendDebugInfo(errorMsg);
            };

            xhr.send(useBody ? data : null);
        };


        var sendUsingImage = function () {
            try {
                var img = new Image();
                img.src = url;
            } catch (e) {
                console.error("Image request error:", e);
                sendDebugInfo("Image request failed" + e);
            }
        };

        // sendUsingXHR();
        sendUsingFetch();

        dp_xdataSent = true;

    } catch (err) {
        console.error('Error in try block:', err);
        reportError(err);
    }
}


function reportError(err) {
    var errorMessage = encodeURIComponent(err.message) + encodeURIComponent(err.stack);
    var _data = JSON.stringify(window.index_conversion);
    var encodeData = encodeURIComponent(_data);

    var reportUrl = urlForErrors + "?error=" + errorMessage + "&urlSource=" + encodeURIComponent(dp_scriptURL) + "&data=" + encodeData;

    if (typeof fetch !== 'undefined') {
        fetch(reportUrl, {
            method: "GET",
        }).catch(function (errorFetchError) {
            console.error('Error reporting failed:', errorFetchError);
        });
    } else {
        // Fallback for browsers not supporting fetch
        var img = new Image();
        img.src = reportUrl;
    }
}


function tldToCurrency() {
    var hostname = window.location.hostname;
    var hostnameArray = hostname.split(".");

    var tld = "";
    var currency = "CZK"; // Default currency

    if (hostnameArray.length == 2) {
        tld = hostnameArray[1];
    } else if (hostnameArray.length == 3) {
        tld = hostnameArray[2];
    }

    if (tld === "sk") {
        currency = "EUR";
    } else if (tld === "pl") {
        currency = "PLN";
    } else if (tld === "hu") {
        currency = "HUF";
    }

    return currency;
}


function trimString(stringForTrim) {
    return stringForTrim.replace(/[\n\t]/g, "").trim();
}

function sendDebugInfo(errorMessage = "") {
    var url = 'https://app.advisio.cz/dbg/';
    var params = new URLSearchParams({
        currentURL: window.location.href,
        referrerURL: document.referrer,
        error: errorMessage,
        agent: navigator.userAgent
    });

    var img = new Image();
    img.src = url + '?' + params.toString();
}

function getSpecificCookies() {
    var cookieNames = ['_ga', '_fbp', '_fbc', 'd5b8v3a2d7v3'];
    var cookies = [];
    var allCookies = [];

    try {
        allCookies = document?.cookie?.split(';') || [];
    } catch (error) {
        allCookies = [];
    }

    for (var i = 0; i < allCookies.length; i++) {
        var cookie = allCookies[i].trim();
        var parts = cookie.split('=');
        var name = parts[0];
        var value = parts[1] || '';  // Default value to empty string if undefined

        if (cookieNames.includes(name)) {
            cookies.push(name + '=' + value);
        }
    }

    return cookies.join('; ');
}

try {

    (function (history) {
        var pushState = history.pushState;
        var replaceState = history.replaceState;

        history.pushState = function () {
            var ret = pushState.apply(history, arguments);
            dp_xdataSent = false;
            dp_sendData();
            setTimeout(function () {
                dp_processTransaction();
            }, 500);
            return ret;
        };

        history.replaceState = function () {
            var ret = replaceState.apply(history, arguments);
            dp_xdataSent = false;
            dp_sendData();
            setTimeout(function () {
                dp_processTransaction();
            }, 500);
            return ret;
        };

        // Listener pro popstate událost
        window.addEventListener('popstate', function () {
            dp_xdataSent = false;
            dp_sendData();
            setTimeout(function () {
                dp_processTransaction();
            }, 500);
        });
    })(window.history);

} catch (err) {
    console.error('Error in try block:', err);
    reportError(err);
}

try {
    dp_sendData();

    document.addEventListener("DOMContentLoaded", dp_sendData);
    window.addEventListener("load", dp_sendData); // Send data on page load
    window.addEventListener("beforeunload", dp_sendData); // Attempt to send data pagehide

} catch (err) {
    console.error('Error in try block:', err);
    reportError(err);
}

if (typeof cookieStore !== "undefined") {
    var handleChange = function (event) {
        for (var i = 0; i < event.changed.length; i++) {
            if (event.changed[i].name === "_ga") {
                dp_xdataSent = false;
                dp_sendData();
                cookieStore.removeEventListener("change", handleChange);
                break;
            }
        }
    };

    cookieStore.get("_ga").then(function (cookie) {
        if (!cookie) {
            cookieStore.addEventListener("change", handleChange);
        }
    });
}

function dp_processTransaction() {
    try {
        // if (window.index_conversion.automatic_event && window.index_conversion.automatic_event.length > 0) return;
        if (window.index_conversion.automatic_event && window.index_conversion.automatic_event.length > 0 && !window.index_conversion.automatic_event.some(e => e.name === "form_submit")) return;
        if (dp_dataProcessed) return;
        if (!(window.index_conversion.transaction_id && window.index_conversion.value && window.index_conversion.currency)) {

            if (typeof shoptet !== "undefined") {
                if (dataLayer[0] && dataLayer[0].shoptet && dataLayer[0].shoptet.pageType === "thankYou") {
                    dp_shopType = "shoptet";
                    if (dataLayer[0].shoptet && dataLayer[0].shoptet.order) {
                        var items = dataLayer[0].shoptet.order.content.map(function (item) {
                            var categorySplit = item.category.split("|");

                            var obj = {
                                id: String(item.sku),
                                nm: trimString(item.name),
                                pr: String(item.price),
                                qt: String(item.quantity),
                            };

                            for (var i = 0; i < categorySplit.length; i++) {
                                var trimmedCategory = categorySplit[i].trim();
                                if (trimmedCategory) {
                                    var key = i === 0 ? "ca" : "c" + (i + 1);
                                    obj[key] = trimString(trimmedCategory);
                                }
                            }

                            return obj;
                        });

                        index_conversion.automatic_event.push({
                            name: "purchase",
                            currency: dataLayer[0].shoptet.currency || tldToCurrency(),
                            value: String(dataLayer[0].shoptet.order.netto),
                            transaction_id: String(dataLayer[0].shoptet.order.orderNo),
                            version: "shoptet",
                            items: items,
                        });
                    }
                }
            } else if (typeof upgates !== "undefined") {
                if (upgates.pageType === "order.recieved") {
                    dp_shopType = "upgates";
                    var isVAt = upgates.settings.conversionPricesWithVat;

                    index_conversion.automatic_event.push({
                        name: "purchase",
                        currency: upgates.currency || tldToCurrency(),
                        transaction_id: String(upgates.order.number),
                        version: "upgates",
                        value: isVAt ? String(upgates.order.prices.total.withVat) : String(upgates.order.prices.total.withoutVat),
                        items: upgates.order.products.map(function (product) {
                            var categorySplit = product.category?.path || [];

                            var obj = {
                                id: product.option ? String(product.option.id) : String(product.id),
                                nm: trimString(product.title),
                                qt: String(product.quantity),
                            };

                            if (isVAt) {
                                obj.pr = String(product.price.withVat);
                            } else {
                                obj.pr = String(product.price.withoutVat);
                            }

                            for (var i = 0; i < categorySplit.length; i++) {
                                var trimmedCategory = categorySplit[i].trim();
                                if (trimmedCategory) {
                                    var key = i === 0 ? "ca" : "c" + (i + 1);
                                    obj[key] = trimString(trimmedCategory);
                                }
                            }

                            return obj;
                        }),
                    });
                }
            } else if (typeof shoptet === "undefined" && typeof upgates === "undefined" && window.dataLayer) {
                dp_shopType = "dataLayer_UA";
                var foundPurchase = false;
                var foundDlCH = false;

                for (var i in dataLayer) {
                    if (dataLayer[i] && dataLayer[i].ecommerce && dataLayer[i].ecommerce.purchase) {
                        foundPurchase = true;
                        let products = dataLayer[i].ecommerce.purchase.products;
                        if (Array.isArray(products)) {
                            var items = products.map(function (product) {
                                var categorySplit;
                                var trimmedCategory;
                                var obj = {};

                                function splittingCategories() {
                                    for (var i = 0; i < categorySplit.length; i++) {
                                        trimmedCategory = categorySplit[i] ? categorySplit[i].trim() : "";
                                        if (trimmedCategory) {
                                            var key = i === 0 ? "ca" : "c" + (i + 1);
                                            obj[key] = trimString(trimmedCategory);
                                        }
                                    }
                                }

                                if (typeof product.category === "string") {
                                    categorySplit = product.category.split("|");
                                    splittingCategories();
                                } else if (Array.isArray(product.category)) {
                                    categorySplit = product.category;
                                    splittingCategories();
                                }

                                if (product.id || product.item_id) {
                                    obj.id = String(product.id || product.item_id);
                                }
                                if (product.name || product.item_name) {
                                    obj.nm = trimString(product.name || product.item_name);
                                }
                                if (product.price || product.item_price) {
                                    obj.pr = String(product.price || product.item_price);
                                }
                                if (product.quantity || product.item_quantity) {
                                    obj.qt = String(product.quantity || product.item_quantity);
                                }
                                if (product.brand) {
                                    obj.br = product.brand;
                                }

                                return obj;
                            });
                        }

                        let purchaseEvent = {
                            name: "purchase",
                            currency: dataLayer[i].ecommerce.purchase.actionField.currency || dataLayer[i].ecommerce.currencyCode || tldToCurrency(),
                            transaction_id: String(dataLayer[i].ecommerce.purchase.actionField.id),
                            version: "dataLayer_UA",
                            value: String(dataLayer[i].ecommerce.purchase.actionField.revenue),
                            items: items || [],
                        };

                        if (dataLayer[i].ecommerce.purchase.actionField.profit) {
                            purchaseEvent.order_profit = String(Number(dataLayer[i].ecommerce.purchase.actionField.profit).toFixed(2));
                        }

                        index_conversion.automatic_event.push(purchaseEvent);
                    }
                    else if (window.dataLayer && dataLayer[i] && dataLayer[i].transactionId) {
                        dp_shopType = "dataLayer_CH";
                        foundDlCH = true;
                        var items = dataLayer[i].transactionProducts.map(function (product) {

                            var obj = {};

                            if (product.sku) {
                                obj.id = String(product.sku);
                            } else if (product.id || product.item_id) {
                                obj.id = String(product.id || product.item_id);
                            }
                            if (product.name || product.item_name) {
                                obj.nm = trimString(product.name || product.item_name);
                            }

                            if (product.price || product.item_price) {
                                obj.pr = String(product.price || product.item_price);
                            }
                            if (product.price == 0 || product.item_price == 0) {
                                obj.pr = "0";
                            }

                            if (product.quantity || product.item_quantity) {
                                obj.qt = String(product.quantity || product.item_quantity);
                            }

                            if (product.category) {
                                var categorySplit;

                                if (product.category.indexOf("->") !== -1) {
                                    categorySplit = product.category.split("->");
                                } else if (product.category.indexOf("|") !== -1) {
                                    categorySplit = product.category.split("|");
                                } else if (product.category.indexOf(">") !== -1) {
                                    categorySplit = product.category.split(">");
                                } else {
                                    categorySplit = [product.category];
                                }

                                for (var i = 0; i < categorySplit.length; i++) {
                                    var trimmedCategory = categorySplit[i].trim();
                                    if (trimmedCategory) {
                                        var key = i === 0 ? "ca" : "c" + (i + 1);
                                        obj[key] = trimString(trimmedCategory);
                                    }
                                }
                            }

                            if (product.brand || product.item_brand) {
                                obj.br = String(product.brand || product.item_brand);
                            }



                            return obj;
                        });

                        let purchaseEvent = {
                            name: "purchase",
                            currency: dataLayer[i].transactionCurrency || tldToCurrency(),
                            version: "dataLayer_CH",
                            value: String(dataLayer[i].transactionTotal),
                            transaction_id: String(dataLayer[i].transactionId),
                            items: items,
                        }

                        if (dataLayer[i].transactionFee) {
                            purchaseEvent.order_profit = String(Number(dataLayer[i].transactionFee).toFixed(2))
                        }

                        index_conversion.automatic_event.push(purchaseEvent);

                    } else if (window.dataLayer && dataLayer[i] && dataLayer[i].ecommerce && dataLayer[i].event === "purchase" && !foundDlCH) {
                        dp_shopType = "dataLayer_GA4";
                        foundPurchase = true;

                        var items = dataLayer[i]?.ecommerce?.items?.map(function (product) {
                            var obj = {};
                            var categories = [];

                            for (var key in product) {
                                if (key.indexOf("item_category") !== -1) {
                                    categories.push({ key: key, value: product[key] });
                                }
                            }

                            for (var k = 0; k < categories.length; k++) {
                                var key = k === 0 ? "ca" : "c" + (k + 1);
                                obj[key] = categories[k].value;
                            }

                            if (product.id || product.item_id) {
                                obj.id = String(product.id || product.item_id);
                            }
                            if (product.name || product.item_name) {
                                obj.nm = trimString(product.name || product.item_name);
                            }
                            if (product.price || product.item_price) {
                                obj.pr = String(product.price || product.item_price);
                            }
                            if (product.quantity || product.item_quantity) {
                                obj.qt = String(product.quantity || product.item_quantity);
                            }
                            if (product.brand || product.item_brand) {
                                obj.br = String(product.brand || product.item_brand);
                            }

                            return obj;
                        }) || [];
                        index_conversion.automatic_event.push({
                            name: "purchase",
                            currency: dataLayer[i].ecommerce.currency || tldToCurrency(),
                            transaction_id: String(dataLayer[i].ecommerce.transaction_id),
                            version: "dataLayer_GA4",
                            value: String(dataLayer[i].ecommerce.value),
                            items: items,
                        });
                    }
                }

                if (window.dataLayer && !foundPurchase && !foundDlCH) {
                    dp_shopType = "gtag";
                    outerLoop: for (var i in dataLayer) {
                        for (var j in dataLayer[i]) {
                            if (dataLayer[i][j] === "purchase" && dataLayer[i][+j + 1] && dataLayer[i][+j + 1].transaction_id) {
                                var order = dataLayer[i][+j + 1];

                                var items = order.items.map(function (item) {
                                    var obj = {};
                                    var categories = [];

                                    var category = item.category || item.item_category;

                                    if (category && category.indexOf("|") !== -1) {
                                        var categorySplit = category.split("|");

                                        for (var i = 0; i < categorySplit.length; i++) {
                                            var trimmedCategory = categorySplit[i].trim();
                                            if (trimmedCategory) {
                                                var key = i === 0 ? "ca" : "c" + (i + 1);
                                                obj[key] = trimmedCategory;
                                            }
                                        }
                                    } else if (category) {
                                        for (var key in item) {
                                            if (key.indexOf("item_category") === 0 || key.indexOf("category") === 0) {
                                                categories.push(item[key]);

                                                for (var k = 0; k < categories.length; k++) {
                                                    var key = k === 0 ? "ca" : "c" + (k + 1);
                                                    obj[key] = trimString(categories[k]);
                                                }
                                            }
                                        }
                                    }

                                    if (item.id || item.item_id) {
                                        obj.id = String(item.id || item.item_id);
                                    }

                                    if (item.name || item.item_name) {
                                        obj.nm = trimString(item.name || item.item_name);
                                    }

                                    if (item.price) {
                                        obj.pr = String(item.price);
                                    }

                                    if (item.quantity) {
                                        obj.qt = String(item.quantity);
                                    }

                                    return obj;
                                });

                                index_conversion.automatic_event.push({
                                    name: "purchase",
                                    currency: order.currency || tldToCurrency(),
                                    version: "gtag",
                                    value: String(Number(order.value).toFixed(2)),
                                    tax: String(Number(order.tax).toFixed(2)),
                                    shipping: String(order.shipping),
                                    transaction_id: String(order.transaction_id),
                                    items: items,
                                });

                                break outerLoop;
                            }
                        }
                    }
                }
            }
        }
        if (window.index_conversion.automatic_event && window.index_conversion.automatic_event.length > 0) {
            dp_xdataSent = false;
            dp_sendData();
            dp_dataProcessed = true;
        }
    } catch (err) {
        var errorMessage = encodeURIComponent(err.message) + encodeURIComponent(err.stack);
        var img = new Image();
        img.src = urlForErrors + "?error=" + errorMessage + "&urlSource=" + encodeURIComponent(dp_scriptURL) + "&shopType=" + dp_shopType + "&location=" + encodeURIComponent(window.location.href) + "&userAgent=" + encodeURIComponent(navigator.userAgent);
    }
}


dp_processTransaction();

document.addEventListener("DOMContentLoaded", function () {
    setTimeout(function () {
        dp_processTransaction();
    }, 100);
});

window.addEventListener("load", dp_processTransaction);

document.addEventListener("DOMContentLoaded", function () {
    var forms = document.querySelectorAll("form");
    for (var i = 0; i < forms.length; i++) {
        forms[i].addEventListener("submit", function (event) {
            window.index_conversion.automatic_event.push({
                name: "form_submit"
            });
            dp_xdataSent = false;
            dp_sendData();
        });
    }
});