PageSourceSearch

https://neemans.com/cdn/shop/t/891/assets/nms-webengage-events.js?v=71720281591235007051785228050

js neemans.com collected 2026-09-25 04:25:45 UTC 15,101 bytes, 2 lines download raw bytes

1class NMSWebEngageEvents{constructor(){this.webengage=window.webengage,this.config=window.neemans?.webengage?.config||{},this.debugMode=!1,this.eventQueue=[],this.isInitialized=!1,this.retryCount=0,this.maxRetries=this.#isPrivateBrowsing()?1:3,this.retryTimeouts=[],this.fallbackMode=!1,this.init()}init(){if(window.neemans=window.neemans||{},window.neemans.webengage=window.neemans.webengage||{},window.neemans.webengage.events=this,this.webengage&&typeof this.webengage.onReady=="function")this.webengage.onReady(()=>{this.setupWebEngageConfig(),this.setupNMSEventListeners(),this.setupMenuLinkListeners(),this.isInitialized=!0,this.processEventQueue(),this.clearRetryTimeouts(),this.log("WebEngage Event Manager initialized successfully")});else{if(this.retryCount>=this.maxRetries){this.log("WebEngage SDK failed to load after maximum retries. Enabling fallback mode."),this.enableFallbackMode();return}const delay=Math.min(1e3*Math.pow(2,this.retryCount),4e3);this.retryCount++,this.log(`WebEngage SDK not ready. Retry ${this.retryCount}/${this.maxRetries} in ${delay}ms`);const timeoutId=setTimeout(()=>{this.init()},delay);this.retryTimeouts.push(timeoutId)}}setupWebEngageConfig(){this.webengage&&typeof this.webengage.options=="function"&&this.webengage.options({debug:!1,autoTrack:!1})}clearRetryTimeouts(){this.retryTimeouts.forEach(timeoutId=>clearTimeout(timeoutId)),this.retryTimeouts=[]}enableFallbackMode(){this.fallbackMode=!0,this.isInitialized=!0,this.setupNMSEventListeners(),this.setupMenuLinkListeners(),this.processEventQueue(),this.log("Fallback mode enabled - events will be logged but not sent to WebEngage")}#isPrivateBrowsing(){try{const key="__nms_test__";return localStorage.setItem(key,"1"),localStorage.removeItem(key),!1}catch{return!0}}destroy(){this.clearRetryTimeouts(),this.retryCount=0,this.fallbackMode=!1,this.isInitialized=!1}trackEvent(eventName,eventData={},options={}){if(!this.isInitialized){this.eventQueue.push({eventName,eventData,options});return}if(this.fallbackMode){this.log("Fallback mode - Event would be tracked:",eventName,eventData),options.callback&&typeof options.callback=="function"&&options.callback(eventData);return}if(!this.webengage||typeof this.webengage.track!="function"){this.log("WebEngage SDK not available - switching to fallback mode"),this.enableFallbackMode();return}if(!eventName)return;const enrichedData=eventName==="Page Viewed"?eventData:{timestamp:new Date().toISOString(),"Page Title":document.title,"Page URL":window.location.href,"Page Type":this.getNeemansData("webengage.page.type"),...eventData},cleanedData={};Object.entries(enrichedData).forEach(([key,value])=>{value!=null&&value!==""&&(cleanedData[key]=value)}),this.webengage.track(eventName,cleanedData),this.log("WebEngage Event tracked:",eventName,cleanedData),options.callback&&typeof options.callback=="function"&&options.callback(enrichedData)}identifyUser(userId,userAttributes={}){if(!this.webengage||typeof this.webengage.user.login!="function"){this.log("WebEngage SDK not available for user identification");return}this.webengage.user.login(userId.toString()),this.log("User identified:",userId),Object.keys(userAttributes).length>0&&this.setUserAttributes(userAttributes)}setUserAttributes(attributes){!this.webengage||typeof this.webengage.user.setAttribute!="function"||(Object.entries(attributes).forEach(([key,value])=>{this.webengage.user.setAttribute(key,value)}),this.log("User attributes set:",attributes))}logoutUser(){this.webengage&&typeof this.webengage.user.logout=="function"&&(this.webengage.user.logout(),this.log("User logged out"))}trackProductView(product){const selectedVariant=product.selectedVariant||{};this.trackEvent("Product Viewed",{Color:product.color,"Product ID":product.product_id||product.id,"Product Name":product.product_name||product.title,"Product Price":(selectedVariant.price||product.price||0)/100,Image:this.#ensureHttps(product.featured_image_url),"Image URL":this.#ensureHttps(product.featured_image_url),Images:(product.images||[]).map(url=>this.#ensureHttps(url)),"Product Variant ID":selectedVariant.id,Size:selectedVariant.size||selectedVariant.title,Currency:product.currency||"USD",discount:selectedVariant.discount||0,"Product Category":product.product_category||product.type,"Product Vendor":product.product_vendor||product.vendor,URL:window.location.href,Available:selectedVariant.available!==void 0?selectedVariant.available:product.available,"Compare At Price":(selectedVariant.compareAtPrice||product.compareAtPrice||0)/100,"Number of reviews":0,"Product For":"","Product Rating":0,Quantity:1})}trackAddToCart(variant,quantity=1){const productData=this.formatVariantData(variant);this.trackEvent("Product Added To Cart",{Color:productData.color,"Product ID":productData.product_id,"Product Name":productData.product_title,"Product Price":productData.price/100,image_url:this.#ensureHttps(productData.featured_image_url),"Image URL":this.#ensureHttps(productData.featured_image_url),Images:(productData.all_images||[]).map(url=>this.#ensureHttps(url)),"Product Variant ID":productData.id,Quantity:quantity,Size:productData.size,Currency:productData.currency,discount:productData.discount,"Number of reviews":0,"Product For":"","Product Rating":0,"Product URL":window.location.href})}
1trackBuyNow(product,quantity=1){const selectedVariant=product.selectedVariant||{};this.trackEvent("Buy Now",{Color:product.color,"Product ID":product.product_id||product.id,"Product Name":product.product_name||product.title,"Product Price":(selectedVariant.price||product.price||0)/100,"Image URL":this.#ensureHttps(product.featured_image_url),Images:(product.images||[]).map(url=>this.#ensureHttps(url)),"Product Variant ID":selectedVariant.id,Quantity:quantity,Size:selectedVariant.size||selectedVariant.title,Currency:product.currency||"USD",discount:selectedVariant.discount||0,"Number of reviews":0,"Product For":"","Product Rating":0,"Product URL":window.location.href})}trackRemoveFromCart(variant){const productData=this.formatVariantData(variant);this.trackEvent("Product Removed from Cart",{Image:this.#ensureHttps(productData.featured_image_url)||"","Product ID":productData.product_id,"Product Name":productData.product_title,"Total Price":productData.price/100,"Product Variant ID":productData.id})}async trackCartView(){try{const cart=await(await fetch("/cart.js")).json();if(!cart||cart.item_count===0){this.log("Cart is empty - no tracking");return}this.trackEvent("Cart Viewed",{"Total Price":cart.total_price/100,"Number of Products":cart.item_count,Currency:cart.currency||"INR","Cart Details":cart.items.map(item=>({"Product ID":item.product_id,"Variant ID":item.variant_id||item.id,"Product Name":item.product_title,Price:item.price/100,Quantity:item.quantity}))})}catch(error){this.handleError(error,"Failed to fetch cart data for tracking");const cartData=this.getNeemansData("webengage.cart");cartData&&this.trackEvent("Cart Viewed",{"Cart Value":cartData.totalPrice/100,"Item Count":cartData.itemCount,Currency:cartData.currency||"INR"})}}trackCollectionView(collection){const collectionData=collection||this.getNeemansData("webengage.collection");if(!collectionData){this.log("No collection data available for tracking");return}this.trackEvent("Category/Collection Viewed",{"Collection Id":collectionData.id,"Collection Name":collectionData.title,"Collection Handle":collectionData.handle,"Collection URL":collectionData.url||window.location.href,"Collection Product Count":collectionData.productsCount||0,"Sort By":collectionData.sortBy||"manual","Page Type":"collection"})}trackPageView(pageData){const userData=this.getNeemansData("webengage.user");this.trackEvent("Page Viewed",{"Page URL":pageData.url||window.location.href,"Page Title":pageData.title||document.title,"Shop Domain":pageData.shopDomain,"Page Type":pageData.type,"Shop Name":pageData.shopName,"Customer Email":userData?.email||null,"Page Template":pageData.template,Currency:pageData.currency,"Customer ID":userData?.id||null})}trackGenderToggle(data){console.log("Gender Toggle Fired",data),this.trackEvent("Gender Toggle Clicked",{"Selected Gender":data.gender,"Previous Gender":data.previousGender,"Product ID":data.productId,"Product Name":data.productName,"Product Variant ID":data.variantId,Color:data.color,Size:data.size,"Page URL":window.location.href})}trackMenuLinkClick(linkData){this.trackEvent("Clicked on Menu Link",{"Link Name":linkData.name,"Page URL":linkData.url})}async trackCheckoutStarted(){try{const cart=await(await fetch("/cart.js")).json(),trackingData={"Checkout Method":"Standard",Step:1,"Total Price":cart.total_price?cart.total_price/100:0,"Number of Products":cart.item_count||0,Currency:cart.currency||"INR"};cart.items&&cart.items.length>0&&(trackingData["Cart Details"]=cart.items.map(item=>({"Product ID":item.product_id,"Product Name":item.product_title,"Variant ID":item.variant_id,Price:item.price/100,Quantity:item.quantity,"Line Price":item.line_price/100,"Variant Title":item.variant_title,SKU:item.sku}))),this.trackEvent("Checkout Started Step 1",trackingData)}catch(error){this.handleError(error,"Failed to fetch cart data for checkout tracking"),this.trackEvent("Checkout Started Step 1",{"Checkout Method":"Standard",Step:1})}}setupNMSEventListeners(){document.addEventListener("nms:gender-toggle-clicked",event=>{this.trackGenderToggle(event.detail)});const trackableEvents=["buy-now-clicked","variant-picker:value-changed"];document.addEventListener("nms:buy-now-clicked",event=>{const productData=this.getNeemansData("webengage.product"),quantity=event.detail.quantity||1;productData&&this.trackBuyNow(productData,quantity)}),document.addEventListener("line-item:change",event=>{const{cart}=event.detail;cart.item_count===0?this.trackEvent("Product Removed from Cart",{Image:"","Product ID":0,"Product Name":"","Product Price":0,"Product Variant ID":0}):this.trackEvent("Cart Updated",{Currency:cart.currency||"INR",Products:cart.items.map(item=>({id:item.product_id,variant_id:item.variant_id||item.id,title:item.product_title,price:item.price/100,quantity:item.quantity,image:this.#ensureHttps(item.image),line_price:item.line_price/100})),Total:cart.total_price/100,"Total Quantity":cart.item_count})}),document.addEventListener("variant:add",async event=>{if(event.detail?.items?.length>0){const item=event.detail.items[0];try{const[allImages,variantData]=await Promise.all([this.fetchProductImages(item.handle),this.fetchVariantData(item.id)]),enhancedVariantData={id:item.id,product_id:item.product_id,title:item.title,variant_title:item.variant_title,price:item.price,product_title:item.product_title,image:this.#ensureHttps(item.image),handle:item.handle,all_images:allImages,compare_at_price:variantData?.compare_at_price||0};this.trackAddToCart(enhancedVariantData,item.quantity||1)}catch{this.trackAddToCart({id:item.id,product_id:item.product_id,title:item.title,variant_title:item.variant_title,price:item.price,product_title:item.product_title,image:this.#ensureHttps(item.image),all_images:[item.image],compare_at_price:0},item.quantity||1)}}}
1),trackableEvents.forEach(eventName=>{document.addEventListener(`nms:${eventName}`,event=>{this.trackEvent("User Interaction",{action:eventName,category:"nms_component",detail:event.detail})})}),this.log("NMS event listeners set up")}setupMenuLinkListeners(){document.addEventListener("click",event=>{const link=event.target.closest("[data-webengage-track-link]");if(link){const linkData={name:link.textContent.trim(),url:link.href};this.trackMenuLinkClick(linkData);return}if(event.target.closest("[data-nms-cart-drawer-checkout-button]")){this.trackCheckoutStarted();return}if(event.target.closest("[data-nms-gtm-view-cart]")){this.trackCartView();return}}),this.log("Menu link listeners set up")}formatProductData(product){return{id:product.id,title:product.title,type:product.type||"Unknown",vendor:product.vendor||"Unknown",price:product.price||product.selected_or_first_available_variant?.price||0,available:product.available!==void 0?product.available:!0,currency:this.getNeemansData("analytics.shop.currency")||"USD"}}formatVariantData(variant){const productTitle=variant.product_title||variant.untranslated_product_title||"",color=productTitle.includes(" : ")?productTitle.split(" : ")[1]:"",size=variant.variant_title||variant.untranslated_variant_title||"",price=variant.price||variant.final_price||0,compareAtPrice=variant.compare_at_price||variant.original_price||0,discountAmount=compareAtPrice>price?compareAtPrice-price:0,discountPercentage=compareAtPrice>0?Math.round(discountAmount/compareAtPrice*100):0;return{id:variant.id||variant.variant_id,product_id:variant.product_id,product_title:productTitle,variant_title:size,price,compare_at_price:compareAtPrice,discount:discountPercentage,color,size,product_type:variant.product_type||"Unknown",vendor:variant.vendor||"",sku:variant.sku||"",featured_image_url:this.#ensureHttps(variant.image||variant.featured_image?.url||""),all_images:(variant.all_images||[]).map(url=>this.#ensureHttps(url)),product_description:variant.product_description||"",product_handle:variant.handle||"",url:variant.url||"",quantity:variant.quantity||1,currency:this.getNeemansData("analytics.shop.currency")||"USD"}}#ensureHttps(url){return url&&(url.startsWith("//")?`https:${url}`:url)}async fetchProductImages(handle){if(!handle)return[];try{return((await this.fetchData(`/products/${handle}.js`)).images||[]).slice(0,6).map(url=>this.#ensureHttps(url))}catch(error){return this.handleError(error,`Failed to fetch images for ${handle}`),[]}}async fetchVariantData(variantId){if(!variantId)return null;try{return await this.fetchData(`/variants/${variantId}.js`)}catch(error){return this.handleError(error,`Failed to fetch variant data for ${variantId}`),null}}formatLineItemData(lineItem){return{product_id:lineItem.product_id,variant_id:lineItem.variant_id,product_name:lineItem.title,variant_name:lineItem.variant_title,price:lineItem.price/100,quantity:lineItem.quantity,currency:this.getNeemansData("analytics.shop.currency")||"USD"}}async fetchData(url){const response=await fetch(url);if(!response.ok)throw new Error(`HTTP ${response.status}: ${response.statusText}`);return await response.json()}handleError(error,context=""){const message=context?`${context}: ${error.message}`:error.message;console.error("[NMS WebEngage Error]",message),this.debugMode&&console.error("[NMS WebEngage Error Details]",error)}getNeemansData(key){const keys=key.split(".");let data=window.neemans;for(const k of keys)if(data=data?.[k],data===void 0)return null;return data}processEventQueue(){this.eventQueue.splice(0).forEach(({eventName,eventData,options})=>{this.trackEvent(eventName,eventData,options)})}log(...args){this.debugMode&&console.log("[NMS WebEngage]",...args)}}function initNMSWebEngageEvents(){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{new NMSWebEngageEvents}):new NMSWebEngageEvents}initNMSWebEngageEvents();
2//# sourceMappingURL=/cdn/shop/t/891/assets/nms-webengage-events.js.map?v=71720281591235007051785228050

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.