(function() { function bxBootstrap() { var re = /bot|crawl|slurp|spider|mediapartners|headlesschrome|snap-prefetch|remotasks|woorank|uptime\.com|facebookexternalhit|facebookcatalog/i; if (re.test(navigator.userAgent) || navigator.userAgent == '') { return; } if (!(window.bouncex&&bouncex.website)) { var pushedData = []; if(window.bouncex && bouncex.push && bouncex.length){ pushedData = bouncex; } window.bouncex = {}; bouncex.pushedData = pushedData; bouncex.website = {"id":7243,"name":"City Mattress","cookie_name":"bounceClientVisit7243","domain":"citymattress.com","ct":"fp_local_storage","ally":0,"ei":0,"tcjs":"","cjs":"","force_https":false,"waypoints":false,"content_width":900,"gai":"","swids":"","sd":0,"ljq":"auto","campaign_id":0,"is_preview":false,"aco":{"first_party_limit":"3500","local_storage":"1"},"cmp":{"gdpr":0,"gmp":0,"whitelist_check":0},"burls":[],"ple":false,"fbe":true,"ffs":"","mas":2,"map":1,"gar":true,"ete":1,"ettm":false,"etjs":"/* ---------------------------- STANDARD VARIABLES ---------------------------- */\n\nvar CART_COOKIE_KEY = 'cart',\n\tCLEAN_URL = bouncex.utils.url.allowParams(),\n\tROOT_DOMAIN = window.location.hostname.replace('www.', '');\n\n/* --------------------------------- CUSTOMIZATION VARIABLES -------------------------------- */\n\nvar soldOutItemsOnSite = true,\n\tpdpAtcSelector = '#btnAddToBag, form[action=\"/cart/add\"] button[type=\"submit\"], button[name=\"add\"]',\n\toutOfStockSelector = '';\n\n/* --------------------------------- CLIENT SPECIFIC FUNCTIONALITY -------------------------------- */\n\nvar CATALOG = true;\n\n/* --------------------------------- HELPERS -------------------------------- */\nfunction getItemId(){\n\treturn bouncex.utils.getNestedProp('ShopifyAnalytics.meta.product.id', '') ||\n\t\tbouncex.utils.getNestedProp('__st.rid', '');\n}\n\nfunction getItemCopy(){\n\treturn jQuery('.shopify-section h1').first().text().trim() ||\n\t\tjQuery('meta[property=\"og:title\"]').attr('content') ||\n\t\t'';\n}\n\nfunction getItemCategory(){\n\treturn bouncex.utils.getNestedProp('ShopifyAnalytics.meta.product.type') || 'Global';\n}\n\nfunction getItemImage(){\n\tvar imgUrl = jQuery('meta[property=\"og:image\"]').first().attr('content');\n\n\tif (!imgUrl){\n\t\treturn false;\n\t}\n\n\timgUrl = bouncex.utils.url.allowParams([], imgUrl.replace(/\\s+/g, ''));\n\n\tif (imgUrl.indexOf('http') === -1){\n\t\treturn 'https:' + imgUrl;\n\t}\n\n\treturn imgUrl;\n}\n\nfunction getItemInStock(){\n\tif (!soldOutItemsOnSite){\n\t\treturn true;\n\t}\n\n\tif (outOfStockSelector && jQuery(outOfStockSelector).length > 0){\n\t\treturn false;\n\t}\n\n\treturn jQuery(pdpAtcSelector).length > 0 ? !jQuery(pdpAtcSelector).is(':disabled') && jQuery(pdpAtcSelector).is(':visible') : true;\n}\n\n/* ------------------------------ ITEM TRACKING ----------------------------- */\n\n\nfunction getItem() {\n\treturn {\n\t\tid: getItemId(),\n\t\tcopy: getItemCopy(),\n\t\tcategory: getItemCategory(),\n\t\turl: CLEAN_URL,\n\t\timageurl: getItemImage(),\n\t\tinstock: getItemInStock()\n\t};\n}\n\nfunction fireViewItem(id, groupId) {\n\tvar pushItem = { 'item:id': id };\n\n\tif (groupId) {\n\t\tpushItem['item:itemgroupid'] = groupId;\n\t}\n\tbouncex.push(['view item', pushItem]);\n}\n\nfunction initializeItemEvents() {\n\tvar item;\n\n\tbouncex.et.onTrue(\n\t\tfunction () {\n\t\t\titem = getItem();\n\t\t\treturn !!item.id &&\n\t\t\t\t!!item.copy &&\n\t\t\t\t!!item.category &&\n\t\t\t\t!!item.url &&\n\t\t\t\t!!item.imageurl;\n\t\t},\n\t\tfunction () {\n\t\t\tif (item.url.indexOf('gift-card') > -1) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbouncex.push(['item', item]);\n\n\t\t\tif (CATALOG){\n\t\t\t\titem.groupId = item.url.split('/').pop();\n\t\t\t\tinitializeSkuEvents(item.id, item.groupId);\n\t\t\t}\n\n\t\t\tfireViewItem(item.id, item.groupId);\n\t\t\tinitializeATCClickTracking(item.id);\n\t\t},\n\t\t10\n\t);\n}\n\n/* ------------------------------ SKU TRACKING ------------------------------ */\n\nfunction getSku() {\n\treturn bouncex.utils.url.getParam('variant', window.location.href) ||\n\t\tbouncex.utils.getNestedProp('ShopifyAnalytics.meta.selectedVariantId') ||\n\t\tjQuery('input[name=\"id\"]').val();\n}\n\nfunction getDlSku() {\n var arr = window.dataLayer,\n len = arr.length;\n\n for (var i = len - 1; i >= 0; i--) {\n if (arr[i].event !== \"view_item\") {\n continue;\n }\n \n if (!!arr[i].ecommerce) {\n return (arr[i].ecommerce.items[0].item_shopify_id || '').split('_').pop();\n }\n\n }\n}\n\nfunction initializeSkuEvents(itemId, groupId) {\n\tvar allVariantsSelector = '.custom-select div.option, .product-option__label, .option-value, button[data-product-option], .Swatch, input[data-variant-id]',\n\t\tminVariants = 2,\n\t\tlastSkuFired,\n\t\tskuId;\n\n\tif (jQuery(allVariantsSelector).length <= minVariants){\n\t\tskuId = bouncex.vars.sku_id;\n\t\tif (skuId){\n\t\t\tfireSelectSku(itemId, groupId, skuId);\n\t\t}\n\t}\n\t\n\tbouncex.et.onVarChange('sku_id', function (oldVal, newVal) {\n\t\tif (newVal != oldVal) {\n\t\t fireSelectSku(itemId, groupId, bouncex.vars.sku_id);\n\t\t}\n\t});\n\n// \tbouncex.et.on(\n// \t\tbouncex.document,\n// \t\t'click.bxsku',\n// \t\tfunction () {\n// \t\t bounce.log('c')\n// \t\t\tbouncex.et.onTrue(function () {\n// \t\t\t\tskuId = getSku();\n// \t\t\t\treturn skuId && skuId !== lastSkuFired;\n// \t\t\t}, function () {\n// \t\t\t\tfireSelectSku(itemId, groupId, skuId);\n// \t\t\t\tlastSkuFired = skuId;\n// \t\t\t}, 5);\n// \t\t},\n// \t\tallVariantsSelector\n// \t);\n}\n\nfunction fireSelectSku(itemId, groupId, skuId){\n\tbouncex.push([\n\t\t'select_sku',\n\t\t{\n\t\t\t'item:id': itemId,\n\t\t\t'item:itemgroupid': groupId,\n\t\t\t'item:feedid': skuId\n\t\t}\n\t]);\n}\n\n/* ---------------------------- CATEGORY TRACKING --------------------------- */\n\nfunction getItemIdsFromShopifyAnalytics(sp) {\n\tvar ids = [];\n\n\tfor (var i = 0; i < sp.length; i++ ) {\n\t\tvar id = sp[i].id;\n\n\t\tif (!!id && ids.indexOf(id) === -1){\n\t\t\tids.push(id);\n\t\t}\n\t}\n\n\treturn ids.join(',');\n}\n\nfunction getItemIdsBySelector(){\n\tvar ids = [],\n\t\ttileSelector = 'div[data-product-id]';\n\n\tjQuery(tileSelector).each(function () {\n\t\tvar id = jQuery(this).attr('data-product-id');\n\n\t\tif (id && ids.indexOf(id) < 0) {\n\t\t\tids.push(id);\n\t\t}\n\t});\n\n\treturn ids.join(',');\n\n}\n\nfunction getSearchResultsFromScript(){\n\tvar pixelText = jQuery('#web-pixels-manager-setup').html() || '',\n\t\tproductVariants = pixelText.split('productVariants').pop(),\n\t\tstartIdx = productVariants.indexOf('['),\n\t\tendIdx = productVariants.indexOf(']');\n\n\treturn bouncex.parseJSON(productVariants.substring(startIdx, endIdx + 1));\n}\n\nfunction getItemIdsFromScript(searchResults){\n\tvar ids = [];\n\n\tsearchResults.forEach(function(i){\n\t\tvar product = i.product || {},\n\t\t\tid = product.id;\n\n\t\tif (id && ids.indexOf(id) < 0){\n\t\t\tids.push(id);\n\t\t}\n\t});\n\n\treturn ids.join(',');\n}\n\nfunction getItemIdsCat(){\n\tvar shopifyProducts = bouncex.utils.getNestedProp('ShopifyAnalytics.meta.products', []),\n\t\tshopifyWebPixelSR = getSearchResultsFromScript();\n\n\tswitch(true) {\n\t\tcase !!shopifyProducts.length:\n\t\t\treturn getItemIdsFromShopifyAnalytics(shopifyProducts);\n\t\tcase !!jQuery('#web-pixels-manager-setup').length && !!shopifyWebPixelSR.length:\n\t\t\treturn getItemIdsFromScript(shopifyWebPixelSR);\n\t\tdefault:\n\t\t\tbouncex.log(' GET ITEM IDS BY CUSTOM SELECTOR - UPDATE TILE SELECTOR ACCORDINGLY');\n\t\t\treturn getItemIdsBySelector();\n\t}\n\n}\n\nfunction getCategoryObject() {\n\tvar itemIds = getItemIdsCat();\n\n\treturn {\n\t\t'page:url': bouncex.utils.url.allowParams('q'),\n\t\t'items:ids': itemIds\n\t};\n}\n\nfunction initializeCategoryEvents() {\n\tvar categoryObj;\n\n\tbouncex.et.onTrue(\n\t\tfunction () {\n\t\t\tcategoryObj = getCategoryObject();\n\t\t\treturn !!categoryObj['items:ids'].length &&\n\t\t\t\t!!categoryObj['page:url'];\n\t\t},\n\t\tfunction () {\n\t\t\tbouncex.push(['view category', categoryObj]);\n\t\t},\n\t\t10\n\t);\n}\n\n/* ------------------------------- CART EVENTS ------------------------------ */\n\nfunction fireAddToCart(itemId) {\n\tvar token;\n\n\tbouncex.et.onTrue(\n\t\tfunction () {\n\t\t\ttoken = bouncex.getBounceCookie(CART_COOKIE_KEY);\n\t\t\treturn token;\n\t\t},\n\t\tfunction () {\n\t\t\tbouncex.push([\n\t\t\t\t'add to cart',\n\t\t\t\t{\n\t\t\t\t\t'item:id': itemId,\n\t\t\t\t\t'cart:token': token\n\t\t\t\t}\n\t\t\t]);\n\n\t\t\tif (bouncex.vars.cart) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tbouncex.setVar('cart', true);\n\t\t},\n\t\t10\n\t);\n}\n\nfunction initializeATCClickTracking(itemId) {\n\tbouncex.et.onVisible(pdpAtcSelector, function(){\n\t\tbouncex.et.on(jQuery(pdpAtcSelector), 'click.bxatc', function () {\n\t\t\tfireAddToCart(itemId);\n\t\t});\n\t});\n}\n\nfunction emptyCart() {\n\tbouncex.et.onVarChange('cart_qty', function (oldVal, newVal) {\n\t\tif (bouncex.vars.cart && newVal === 0 && oldVal > 0) {\n\t\t\tbouncex.push(['empty_cart']);\n\t\t\tbouncex.setVar('cart', false);\n\t\t}\n\t});\n}\n\nfunction initializeCartEvents() {\n\tbouncex.et.cart.init({\n\t\treplenishmentType: 'cookie',\n\t\treplenish: function (cart) {\n\t\t\tbouncex.utils.cookies.create({\n\t\t\t\tname: CART_COOKIE_KEY,\n\t\t\t\tvalue: cart.token\n\t\t\t});\n\t\t\treplenComplete();\n\t\t}\n\t});\n\n\n\tfunction replenComplete() {\n\t\twindow.location.href = CLEAN_URL + '?bx_replen=true';\n\t}\n\n\temptyCart();\n}\n\n/* --------------------------- INITIALIZE TRACKING -------------------------- */\n\nfunction isValidDomain() {\n\tif (!bouncex.vars.location_path){\n\t\treturn ROOT_DOMAIN === bouncex.website.domain;\n\t}\n\n\treturn ROOT_DOMAIN === bouncex.website.domain && window.location.pathname.indexOf(bouncex.vars.location_path) > -1;\n}\n\nfunction isEn() {\n\tvar lang = bouncex.html.attr('lang') || '';\n\n\treturn /^en/.test(lang);\n}\n\nfunction isValidForTracking() {\n\treturn isValidDomain() && isEn();\n}\n\nfunction init() {\n\tif (!isValidForTracking()) {\n\t\treturn;\n\t}\n\n\tinitializeCartEvents();\n\n\tswitch (bouncex.website.pts) {\n\t\tcase 'category':\n\t\tcase 'search':\n\t\t\tinitializeCategoryEvents();\n\t\t\tbreak;\n\t\tcase 'product':\n\t\t\tinitializeItemEvents();\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n\ninit();","dge":true,"bxidLoadFirst":false,"pie":true,"cme":true,"gbi_enabled":0,"bpush":false,"pt":{"cart":{"testmode":false,"val":[[{"activation":"current_page_url","prop":"contains","prop2":"","prop3":"","val":"/cart"}]]},"category":{"testmode":false,"val":[[{"activation":"js","prop":"","prop2":"","prop3":"","val":"bouncex.utils.getNestedProp('ShopifyAnalytics.meta.page.pageType', '') === 'collection';"}]]},"checkout":{"testmode":false,"val":[[{"activation":"current_page_url","prop":"contains","prop2":"","prop3":"","val":"/checkouts"}]]},"home":{"testmode":false,"val":[[{"activation":"js","prop":"","prop2":"","prop3":"","val":"bouncex.utils.getNestedProp('ShopifyAnalytics.meta.page.pageType', '') === 'home';"}]]},"product":{"testmode":false,"val":[[{"activation":"js","prop":"","prop2":"","prop3":"","val":"bouncex.utils.getNestedProp('ShopifyAnalytics.meta.page.pageType', '') === 'product';"}]]},"search":{"testmode":false,"val":[[{"activation":"js","prop":"","prop2":"","prop3":"","val":"bouncex.utils.getNestedProp('ShopifyAnalytics.meta.page.pageType', '') === 'searchresults';"}]]}},"els":null,"vars":[{"name":"logged_in","polling":"all","persist":"no","page_types":[],"testmode":false,"default":"false","code":"wunderkind.user !== undefined\n","trigger":""},{"name":"ever_logged_in","polling":"all","persist":"permanent","page_types":[],"testmode":false,"default":"false","code":"bouncex.vars.logged_in || null;","trigger":""},{"name":"cart_qty","polling":"all","persist":"no","page_types":[],"testmode":false,"default":"0","code":"wunderkind.cart.quantity;","trigger":""},{"name":"in_stock","polling":"none","persist":"no","page_types":[],"testmode":true,"default":"false","code":"","trigger":""},{"name":"submitted_onsite","polling":"all","persist":"permanent","page_types":[],"testmode":false,"default":"false","code":"jQuery('.cty-newsletter__success').text().indexOf('You have been added to our newsletter!') > -1 || null;","trigger":""},{"name":"page_url","polling":"none","persist":"no","page_types":["category","search"],"testmode":true,"default":"false","code":"","trigger":""},{"name":"logged_in_identified","polling":"none","persist":"visit","page_types":[],"testmode":false,"default":"false","code":"null;","trigger":"pageload"},{"name":"cart","polling":"none","persist":"permanent","page_types":[],"testmode":false,"default":"false","code":"null;","trigger":"pageload"},{"name":"cookie_modal_present","polling":"all","persist":"no","page_types":[],"testmode":true,"default":"false","code":"null;","trigger":"pageload"},{"name":"page_type","polling":"all","persist":"no","page_types":[],"testmode":true,"default":"false","code":"bouncex.website.pts;","trigger":"pageload"},{"name":"attentive_visible","polling":"vars","persist":"no","page_types":[],"testmode":true,"default":"false","code":"jQuery('#attentive_overlay').length > 0;","trigger":"pageload"},{"name":"sku_id","polling":"all","persist":"no","page_types":["product"],"testmode":false,"default":"false","code":"jQuery('#btnAddToBag').attr('data-combination-id') || jQuery('#btnAddToBag').attr('data-id') || false;","trigger":"pageload"},{"name":"cart_value","polling":"all","persist":"no","page_types":[],"testmode":false,"default":"false","code":"wunderkind.cart.value;","trigger":"pageload"},{"name":"modal_visible","polling":"all","persist":"no","page_types":[],"testmode":false,"default":"false","code":"jQuery('#olark-container[aria-hidden=\"false\"], .affirm-sandbox-container[style*=\"display: block;\"], #extend-learn-more-modal-iframe[style*=\"display: block;\"], #tt-submission-modal').length > 0;","trigger":"pageload"}],"dgu":"pixel.cdnwidget.com","dgp":false,"ba":{"enabled":0,"fbte":0},"biu":"assets.bounceexchange.com","bau":"api.bounceexchange.com","beu":"events.bouncex.net","ibx":{"tjs":"","cjs":"","miw":0,"mibcx":1,"te":1,"cart_rep":{"get":"","set":""},"ulpj":{"bxid":"espemailid"},"cus":"","miw_exclude":"","enabled":1},"etjson":null,"osre":true,"osru":"osr.bounceexchange.com/v1/osr/items","checkDfp":false,"gamNetwork":"","spa":0,"spatm":1,"preinit_cjs":"","crs":{"integrations":null,"pageCount":null},"mat":0,"math":0,"cpnu":"coupons.bounceexchange.com","dfpcms":0,"sms":{"optm":"","eventSharing":false,"shqId":"","enabled":0},"pde":true,"fmc":["AW","AI","AG","AR","BS","BB","BZ","BM","BO","BQ","BR","CA","KY","CL","CO","CR","CU","CW","DM","DO","EC","SV","GF","GL","GD","GT","GP","HT","HN","JM","MQ","MX","MS","NI","PA","PY","PE","PR","PM","MF","BL","KN","LC","VC","SX","SR","TT","US","UM","UY","VE","VG","VI"],"fme":true,"fmx":"","uid2":false,"sdk":{"android":{"enabled":false,"enabledVersions":[],"eventModifications":null},"ios":{"enabled":false,"enabledVersions":[],"eventModifications":null}},"onsite":{"enabled":1},"ads":{"enabled":0},"pubs":{"enabled":0},"websdk":{"enabled":0,"devMode":0},"ga4_property_id":"321424439","ga4_measurement_id":"G-B5FBN4WK5W","tag_state_domain":"api.bounceexchange.com","tag_state_domain_enabled":false} ; bouncex.tag = 'tag3'; bouncex.$ = window.jQuery; bouncex.env = 'production'; bouncex.restrictedTlds = {"casl":{"ca":1},"gdpr":{"ad":1,"al":1,"at":1,"ax":1,"ba":1,"be":1,"bg":1,"by":1,"xn--90ais":1,"ch":1,"cy":1,"cz":1,"de":1,"dk":1,"ee":1,"es":1,"eu":1,"fi":1,"fo":1,"fr":1,"uk":1,"gb":1,"gg":1,"gi":1,"gr":1,"hr":1,"hu":1,"ie":1,"im":1,"is":1,"it":1,"je":1,"li":1,"lt":1,"lu":1,"lv":1,"mc":1,"md":1,"me":1,"mk":1,"xn--d1al":1,"mt":1,"nl":1,"no":1,"pl":1,"pt":1,"ro":1,"rs":1,"xn--90a3ac":1,"ru":1,"su":1,"xn--p1ai":1,"se":1,"si":1,"sj":1,"sk":1,"sm":1,"ua":1,"xn--j1amh":1,"va":1,"tr":1}}; bouncex.client = { supportsBrotli: 1 }; bouncex.assets = {"ads":"ba8ae19a5bf9548f3d50df1e54121805","creativesBaseStyles":"a53944a2","gpsAuction":"bbb80866120d17013073bb6d284cbd6b","inbox":"c5ffeacd3b77d074a53f2878c1332dc9","onsite":"c05f8c5551fa6b964660ad61916291c1","sms":"e39203556bab2366e56296ce42e974a7","websdk":"9c2817e65e803cb8c86d0410c88f20c1","website_campaigns_7243":"cd0cb24a003fa17df13c85eecc2b4665"}; bouncex.push = function(pushData) { bouncex.pushedData.push(pushData); } var runtime = document.createElement('script'); runtime.setAttribute('src', '//assets.bounceexchange.com/assets/smart-tag/versioned/runtime_c81e76ee00d795b1eebf8d27949f8dc5.br.js'); runtime.setAttribute('async', 'async'); bouncex.initializeTag = function() { var script = document.createElement('script'); script.setAttribute('src', '//assets.bounceexchange.com/assets/smart-tag/versioned/main-v2_593c276f770cc7539a00ca1a99a96e5c.br.js'); script.setAttribute('async', 'async'); document.body.appendChild(script); var deviceGraphScript = document.createElement('script'); deviceGraphScript.setAttribute('src', '//assets.bounceexchange.com/assets/smart-tag/versioned/cjs_min_c84323e2726f3e99b307ab7740c6434b.js'); deviceGraphScript.setAttribute('async', 'async'); var dgAttrs = [{"Key":"id","Value":"c.js"},{"Key":"async","Value":"true"},{"Key":"data-apikey","Value":"2^HIykD"},{"Key":"data-cb","Value":"bouncex.dg.initPostDeviceGraph"},{"Key":"data-bx","Value":"1"},{"Key":"data-gm","Value":"1"},{"Key":"data-fire","Value":"1"}]; if (dgAttrs) { for (var i = 0; i < dgAttrs.length; i++) { deviceGraphScript.setAttribute(dgAttrs[i].Key, dgAttrs[i].Value); } } document.body.appendChild(deviceGraphScript); bouncex.initializeTag = function() {}; }; runtime.onload = bouncex.initializeTag; document.body.appendChild(runtime); } } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", bxBootstrap); } else { bxBootstrap(); }})();