(function() { 'use strict'; var KLAVIYO_COMPANY_ID = "R5Vpu3"; var KLAVIYO_CONSENT_CHECK = false; var KLAVIYO_SHOP = "halcapone"; // Consent check esetén adunk egy rövid időt egy másik integrációnak, // hogy előbb be tudja szúrni ugyanazt a Klaviyo scriptet. var EXTERNAL_KLAVIYO_GRACE_MS = 300; var CONSENT_POLL_MS = 500; var hasKlaviyoConsent = function() { return document.cookie.indexOf('UN_cookie_consent_v1') > -1 || document.cookie.indexOf('UN_cookie_consent_v2') > -1; }; var findKlaviyoScript = function(companyId) { return Array.from(document.scripts).find(function(script) { if (!script.src) { return false; } try { var url = new URL(script.src, document.baseURI); return url.hostname === 'static.klaviyo.com' && url.pathname === '/onsite/js/klaviyo.js' && url.searchParams.get('company_id') === companyId; } catch (e) { return false; } }); }; var loadKlaviyo = function(companyId) { return new Promise(function(resolve, reject) { var existingScript = findKlaviyoScript(companyId); // A queue már a Klaviyo tényleges betöltése előtt is használható. window._learnq = window._learnq || []; // Ugyanezt a Klaviyo scriptet valaki már beszúrta. // Nem töltjük be még egyszer; a saját eseményeink mehetnek a queue-ba. if (existingScript) { resolve(); return; } var tag = document.createElement('script'); tag.src = 'https://static.klaviyo.com/onsite/js/klaviyo.js?company_id=' + encodeURIComponent(companyId); tag.async = true; tag.onload = resolve; tag.onerror = reject; document.head.appendChild(tag); }); }; var loadKlaviyoWithGrace = function(companyId) { if (!KLAVIYO_CONSENT_CHECK) { return loadKlaviyo(companyId); } return new Promise(function(resolve, reject) { window.setTimeout(function() { // A loadKlaviyo itt újra ellenőrzi a DOM-ot, tehát ha a türelmi // idő alatt egy másik szolgáltató beszúrta, nem lesz duplikáció. loadKlaviyo(companyId).then(resolve).catch(reject); }, EXTERNAL_KLAVIYO_GRACE_MS); }); }; var startKlaviyoIntegration = function() { // Ha maga a js.php valamiért kétszer kerül az oldalra, a saját event // handlereinket se regisztráljuk kétszer ugyanahhoz a company ID-hoz. window.__zmKlaviyoIntegrations = window.__zmKlaviyoIntegrations || {}; if (window.__zmKlaviyoIntegrations[KLAVIYO_COMPANY_ID]) { return; } window.__zmKlaviyoIntegrations[KLAVIYO_COMPANY_ID] = 'starting'; loadKlaviyoWithGrace(KLAVIYO_COMPANY_ID).then(function() { window.__zmKlaviyoIntegrations[KLAVIYO_COMPANY_ID] = 'started'; // --- var _learnq = window._learnq = window._learnq || []; if (UNAS.customer['email'] != '') { window._learnq.push(['identify', { $email: UNAS.customer['email'] }]); console.log(UNAS.customer['email']); } window._learnq.setCartUrlInfo = { "url": UNAS.shop.base_url + "/shop_cart.php" }; if (window._learnq.ready !== undefined) { window._learnq.setCartUrl(window._learnq.setCartUrlInfo.url); } $(document).on("addToCart", function(event, product_array) { console.log(product_array); $.ajax({ type: "GET", async: true, dataType: 'json', productArray: product_array, url: '//ku.zmmarketing.hu/klaviyo/api-start.php', data: { op: 'productinfo', shop: KLAVIYO_SHOP, sku: product_array["sku"] }, success: function(result) { // console.log(result); // console.log(this.productArray); var act_full_variant_name = ""; if (this.productArray["variant_list1"] != undefined) { act_full_variant_name = this.productArray["variant_list1"]; } if (this.productArray["variant_list2"] != undefined) { if (act_full_variant_name != "") act_full_variant_name += "-"; act_full_variant_name += this.productArray["variant_list2"]; } if (this.productArray["variant_list3"] != undefined) { if (act_full_variant_name != "") act_full_variant_name += "-"; act_full_variant_name += this.productArray["variant_list3"]; } window._learnq.addToCartInfo = { "product_id": this.productArray["master_key"], "sku": this.productArray["sku"], "name": this.productArray["name"], "quantity": this.productArray["qty"], "product_url": result.URL, "image_url": result.ImageURL, "categories": result.Categories, "variation": false }; if (act_full_variant_name != "") { window._learnq.addToCartInfo["variation"] = new Array(); window._learnq.addToCartInfo["variation"]["code"] = act_full_variant_name; window._learnq.addToCartInfo["variation"]["stock"] = true; window._learnq.addToCartInfo["variation"]["details"] = new Array(); if (this.productArray["variant_list1"] != undefined) { window._learnq.addToCartInfo["variation"]["details"][this.productArray["variant_list1"]] = { "category_name": this.productArray["variant_name1"], "category": this.productArray["variant_name1"], "value": this.productArray["variant_list1"] } } if (this.productArray["variant_list2"] != undefined) { window._learnq.addToCartInfo["variation"]["details"][this.productArray["variant_list2"]] = { "category_name": this.productArray["variant_name2"], "category": this.productArray["variant_name2"], "value": this.productArray["variant_list2"] } } if (this.productArray["variant_list3"] != undefined) { window._learnq.addToCartInfo["variation"]["details"][this.productArray["variant_list3"]] = { "category_name": this.productArray["variant_name3"], "category": this.productArray["variant_name3"], "value": this.productArray["variant_list3"] } } } if (window._learnq.ready !== undefined) { window._learnq.addToCart(window._learnq.addToCartInfo.product_id, window._learnq.addToCartInfo.sku, window._learnq.addToCartInfo.name, window._learnq.addToCartInfo.quantity, window._learnq.addToCartInfo.variation); } window._learnq.push(['track', 'Added to Cart', window._learnq.addToCartInfo]); console.log('add to cart'); console.log(window._learnq); } }); }); $(document).on("changeVariant", function(event, product_array) { var act_full_variant_name = ""; if (product_array["variant_list1"] != undefined) { act_full_variant_name = product_array["variant_list1"]; } if (product_array["variant_list2"] != undefined) { if (act_full_variant_name != "") act_full_variant_name += "-"; act_full_variant_name += product_array["variant_list2"]; } if (product_array["variant_list3"] != undefined) { if (act_full_variant_name != "") act_full_variant_name += "-"; act_full_variant_name += product_array["variant_list3"]; } window._learnq.setVariationInfo = { "product_id": product_array["sku"], "variation": false }; if (act_full_variant_name != "") { window._learnq.setVariationInfo["variation"] = new Array(); window._learnq.setVariationInfo["variation"]["code"] = act_full_variant_name; window._learnq.setVariationInfo["variation"]["stock"] = true; window._learnq.setVariationInfo["variation"]["details"] = new Array(); if (product_array["variant_list1"] != undefined) { window._learnq.setVariationInfo["variation"]["details"][product_array["variant_list1"]] = { "category_name": product_array["variant_name1"], "category": product_array["variant_name1"], "value": product_array["variant_list1"] } } if (product_array["variant_list2"] != undefined) { window._learnq.setVariationInfo["variation"]["details"][product_array["variant_list2"]] = { "category_name": product_array["variant_name2"], "category": product_array["variant_name2"], "value": product_array["variant_list2"] } } if (product_array["variant_list3"] != undefined) { window._learnq.setVariationInfo["variation"]["details"][product_array["variant_list3"]] = { "category_name": product_array["variant_name3"], "category": product_array["variant_name3"], "value": product_array["variant_list3"] } } } if (window._learnq.ready !== undefined) { window._learnq.setVariation(window._learnq.setVariationInfo.product_id, window._learnq.setVariationInfo.variation); } }); $(document).on("addToFavourites", function(event, product_array) { window._learnq.addToWishlistInfo = { "product_id": product_array["master_key"], "sku": product_array["sku"] }; if (window._learnq.ready !== undefined) { window._learnq.addToWishlist(window._learnq.addToWishlistInfo.product_id); } window._learnq.push(['track', 'Added Like', window._learnq.addToWishlistInfo]); }); console.log(window._learnq); // --- if ($('body').attr('id') == 'ud_shop_artdet') { var _learnq = window._learnq = window._learnq || []; $(document).ready(function() { $.ajax({ type: 'GET', async: true, dataType: 'json', url: '//ku.zmmarketing.hu/klaviyo/api-start.php', data: { op: 'productinfo', shop: KLAVIYO_SHOP, sku: UNAS.shop['sku'] }, success: function(result) { window._learnq.push(['track', 'Viewed Product', result]); } }); }); console.log(window._learnq); // --- } else if ($('body').attr('id') == 'ud_shop_order_mods') { $(document).ready(function() { var _learnq = window._learnq = window._learnq || []; $.ajax({ type: "GET", async: true, dataType: 'json', url: shop_url_main + '/shop_ajax/api.php', data: { get_ajax: 1, api_auth: UNAS.api_auth, action: 'getCart', data: '' }, success: function(result) { // console.log('getCart success'); let userid = ''; $.ajax({ type: "GET", async: true, dataType: 'json', url: shop_url_main + '/shop_ajax/api.php', data: { get_ajax: 1, api_auth: UNAS.api_auth, action: 'getCustomer', data: '' }, success: function(u) { // console.log('getCustomer success'); // console.log('userinfo'); // console.log(u); userid = u.length ? u.id : 0; var skuArray = []; result.items.forEach(function(item) { skuArray.push(item.sku); }); var itemsToPush = []; var price = 0; result.items.forEach(function(item) { price = (item.price_gross * item.quantity) + price; itemsToPush['key_' + item.sku] = {}; itemsToPush['key_' + item.sku]['ProductID'] = item.id; itemsToPush['key_' + item.sku]['SKU'] = item.sku; itemsToPush['key_' + item.sku]['ProductName'] = item.name; itemsToPush['key_' + item.sku]['Quantity'] = item.quantity; itemsToPush['key_' + item.sku]['ItemPrice'] = item.price_gross; itemsToPush['key_' + item.sku]['RowTotal'] = item.price_gross * item.quantity; }); $.ajax({ type: "GET", async: true, dataType: 'json', userId: userid, productData: result, itemsToPushArray: itemsToPush, url: '//ku.zmmarketing.hu/klaviyo/api-start.php', data: { op: 'productinfo', shop: KLAVIYO_SHOP, sku: skuArray.join('%7C'), multiple: true }, success: function(resultKuApi) { // console.log('productinfo success'); var itemsToPush = this.itemsToPushArray; const Items = []; const ItemNames = []; resultKuApi.forEach(function(item) { console.log(item); itemsToPush['key_' + item.SKU]['Categories'] = item.Categories; itemsToPush['key_' + item.SKU]['ImageURL'] = item.ImageURL; itemsToPush['key_' + item.SKU]['URL'] = item.URL; ItemNames.push(itemsToPush['key_' + item.SKU]['ProductName']); Items.push(itemsToPush['key_' + item.SKU]); }); console.log(ItemNames); console.log(Items); window._learnq.push(["track", "Started Checkout", { "$event_id": userid + "_" + Date.now(), "$value": price, "ItemNames": ItemNames, "CheckoutURL": shop_url_main + "/shop_order_control.php", "Items": Items }]); console.log('Started checkout'); console.log(window._learnq); } }); } }) } }); }); } }).catch(function(error) { delete window.__zmKlaviyoIntegrations[KLAVIYO_COMPANY_ID]; console.error('Klaviyo loading error:', error); }); }; var bootKlaviyoIntegration = function() { if (!KLAVIYO_CONSENT_CHECK) { startKlaviyoIntegration(); return; } if (hasKlaviyoConsent()) { startKlaviyoIntegration(); return; } // Ha az oldal megnyitásakor még nincs consent, de a látogató később // elfogadja, ugyanazon az oldalon is elindul az integráció. var consentInterval = window.setInterval(function() { if (!hasKlaviyoConsent()) { return; } window.clearInterval(consentInterval); startKlaviyoIntegration(); }, CONSENT_POLL_MS); }; bootKlaviyoIntegration(); })();