1 line
9.5 KiB
JavaScript
1 line
9.5 KiB
JavaScript
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5244],{1696:(e,t,r)=>{r.d(t,{b:()=>o});var i=r(40444);class o{static productView(e){return new i.X({name:"product_view",timestamp:new Date,properties:{product_id:e.id,product_name:e.name,product_price:e.price,product_currency:e.currency||"USD",product_category:e.category,product_variant:e.variant}})}static addToCart(e){return new i.X({name:"add_to_cart",timestamp:new Date,properties:{product_id:e.id,product_name:e.name,product_price:e.price,product_currency:e.currency||"USD",product_category:e.category,product_variant:e.variant,product_quantity:e.quantity||1}})}static removeFromCart(e){return new i.X({name:"remove_from_cart",timestamp:new Date,properties:{product_id:e.id,product_name:e.name,product_price:e.price,product_currency:e.currency||"USD",product_category:e.category,product_variant:e.variant,product_quantity:e.quantity||1}})}static beginCheckout(e){return new i.X({name:"begin_checkout",timestamp:new Date,properties:{cart_id:e.id,cart_total:e.total,cart_currency:e.currency||"USD",cart_items_count:e.items.length,cart_items:e.items.map(e=>e.id).join(",")}})}static purchase(e){return new i.X({name:"purchase",timestamp:new Date,properties:{transaction_id:e.transaction_id,cart_id:e.id,value:e.total,currency:e.currency||"USD",shipping:e.shipping,tax:e.tax,discount:e.discount,items_count:e.items.length,items:e.items.map(e=>e.id).join(",")}})}}},13770:(e,t,r)=>{r.d(t,{c:()=>o});var i=r(1696);class o{initialize(e){this.provider.initialize(e)}async trackEvent(e){this.provider.trackEvent(e);try{await this.repository.saveEvent(e)}catch(e){console.error("Error saving event to repository:",e)}}async trackPageView(e,t,r){this.provider.trackPageView(e,t,r);try{await this.repository.savePageView(e,t,r)}catch(e){console.error("Error saving page view to repository:",e)}}async trackProductView(e){let t=i.b.productView(e);await this.trackEvent(t)}async trackAddToCart(e){let t=i.b.addToCart(e);await this.trackEvent(t)}async trackRemoveFromCart(e){let t=i.b.removeFromCart(e);await this.trackEvent(t)}async trackBeginCheckout(e){let t=i.b.beginCheckout(e);await this.trackEvent(t)}async trackPurchase(e){let t=i.b.purchase(e);await this.trackEvent(t)}async getPageViews(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:50;if(!this.repository.getPageViews)throw Error("Repository does not support getPageViews");try{return await this.repository.getPageViews(e)}catch(e){throw console.error("Error getting page views:",e),e}}async getEvents(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:50;if(!this.repository.getEvents)throw Error("Repository does not support getEvents");try{return await this.repository.getEvents(e)}catch(e){throw console.error("Error getting events:",e),e}}async getPageViewsByUrl(){if(!this.repository.getPageViewsByUrl)throw Error("Repository does not support getPageViewsByUrl");try{return await this.repository.getPageViewsByUrl()}catch(e){throw console.error("Error getting page views by URL:",e),e}}constructor(e,t){this.provider=e,this.repository=t}}},24898:(e,t,r)=>{r.d(t,{l:()=>i.l});var i=r(44036);r(54538)},35244:(e,t,r)=>{r.r(t),r.d(t,{useAnalytics:()=>n});var i=r(12115),o=r(62832);function n(){let e=(0,i.useContext)(o.AnalyticsContext);if(!e)throw Error("useAnalytics must be used within an AnalyticsProvider");return e}},40444:(e,t,r)=>{r.d(t,{X:()=>i});class i{constructor(e){this.name=e.name,this.timestamp=e.timestamp,this.properties=e.properties||{}}}},44036:(e,t,r)=>{r.d(t,{l:()=>o});var i=r(46414);class o{async saveEvent(e){let t=window.location.href,r="undefined"!=typeof document?document.title:"",i=window.location.pathname.split("/")[1]||"en",o="undefined"!=typeof document?document.referrer:"",n="undefined"!=typeof navigator?navigator.userAgent:"";this.options.debug&&console.log("Saving event:",e.name,e.properties);try{let{error:a}=await this.supabase.from("page_analytics").insert({page_url:t,page_title:r,locale:i,user_agent:n,referrer:o,session_id:this.sessionId,event_type:"event",event_name:e.name,event_data:e.properties||{},created_at:e.timestamp.toISOString()});if(a&&this.options.debug)throw console.error("Error saving event:",a),a}catch(e){throw this.options.debug&&console.error("Error saving event:",e),e}}async savePageView(e,t,r){let i=t||("undefined"!=typeof document?document.title:""),o=window.location.pathname.split("/")[1]||"en",n=r||("undefined"!=typeof document?document.referrer:""),a="undefined"!=typeof navigator?navigator.userAgent:"";this.options.debug&&console.log("Saving page view:",e,i);try{let{error:t}=await this.supabase.from("page_analytics").insert({page_url:e,page_title:i,locale:o,user_agent:a,referrer:n,session_id:this.sessionId,event_type:"pageview",created_at:new Date().toISOString()});if(t&&this.options.debug)throw console.error("Error saving page view:",t),t}catch(e){throw this.options.debug&&console.error("Error saving page view:",e),e}}constructor(e={}){this.options=e,this.supabase=(0,i.u)(),this.sessionId=crypto.randomUUID(),e.debug&&console.log("SupabaseAnalyticsRepository initialized with session ID:",this.sessionId)}}},46414:(e,t,r)=>{r.d(t,{l:()=>o,u:()=>n});var i=r(81935);let o=()=>{let e=(0,i.createBrowserClient)("https://wnyinxhxkptmflckeyfj.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndueWlueGh4a3B0bWZsY2tleWZqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDMzMDk2OTYsImV4cCI6MjA1ODg4NTY5Nn0.UPKZgxgy_VE8J508zNcPoBt8e-ByicQ5ile8WNFV3K8");return e&&"function"==typeof e.from||console.error("Warning: Supabase client may be invalid"),e},n=()=>o()},54538:(e,t,r)=>{r.d(t,{d:()=>o});var i=r(81935);let o=e=>(0,i.createServerClient)("https://wnyinxhxkptmflckeyfj.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndueWlueGh4a3B0bWZsY2tleWZqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDMzMDk2OTYsImV4cCI6MjA1ODg4NTY5Nn0.UPKZgxgy_VE8J508zNcPoBt8e-ByicQ5ile8WNFV3K8",{cookies:{async get(t){try{let r=(await e()).get(t);return null==r?void 0:r.value}catch(e){console.error("Error getting cookie ".concat(t,":"),e);return}},async set(t,r,i){try{let o=await e();try{o.set({name:t,value:r,...i})}catch(e){if(e&&e.message&&e.message.includes("Server Action or Route Handler")){console.log("Cookie '".concat(t,"' not set: Running in a Server Component context where cookies cannot be modified. ")+"This is expected and safe if you have middleware refreshing sessions.");return}throw e}}catch(e){console.error("Error setting cookie ".concat(t,":"),e)}},async remove(t,r){try{let i=await e();try{i.set({name:t,value:"",...r})}catch(e){if(e&&e.message&&e.message.includes("Server Action or Route Handler")){console.log("Cookie '".concat(t,"' not removed: Running in a Server Component context where cookies cannot be modified. ")+"This is expected and safe if you have middleware refreshing sessions.");return}throw e}}catch(e){console.error("Error removing cookie ".concat(t,":"),e)}}}})},62832:(e,t,r)=>{r.r(t),r.d(t,{AnalyticsContext:()=>u,AnalyticsProvider:()=>d});var i=r(95155),o=r(12115),n=r(13770),a=r(90658),s=r(24898),c=r(81023);let u=(0,o.createContext)(null);function d(e){let{children:t,options:r,disablePageViewTracking:d=!1}=e,p=o.useMemo(()=>{let e=new a.e,t=new s.l,i=new n.c(e,t);return i.initialize(r),i},[r]);return d||(0,c.usePageViewTracking)(p),(0,i.jsx)(u.Provider,{value:p,children:t})}},64697:(e,t,r)=>{r.d(t,{e:()=>o});var i=r(46414);class o{initialize(e){e&&(this.options={...this.options,...e}),this.options.debug&&console.log("SupabaseAnalyticsProvider initialized with options:",this.options)}shouldTrack(e){return!this.excludedPaths.some(t=>t.test(e))}trackEvent(e){let t=window.location.href;if(!this.shouldTrack(t))return;let r="undefined"!=typeof document?document.title:"",i=window.location.pathname.split("/")[1]||"en",o="undefined"!=typeof document?document.referrer:"",n="undefined"!=typeof navigator?navigator.userAgent:"";this.options.debug&&console.log("Tracking event:",e.name,e.properties),this.supabase.from("page_analytics").insert({page_url:t,page_title:r,locale:i,user_agent:n,referrer:o,session_id:this.sessionId,event_type:"event",event_name:e.name,event_data:e.properties||{},created_at:e.timestamp.toISOString()}).then(e=>{let{error:t}=e;t&&this.options.debug&&console.error("Error tracking event:",t)})}trackPageView(e,t,r){if(!this.shouldTrack(e))return;let i=t||("undefined"!=typeof document?document.title:""),o=window.location.pathname.split("/")[1]||"en",n=r||("undefined"!=typeof document?document.referrer:""),a="undefined"!=typeof navigator?navigator.userAgent:"";this.options.debug&&console.log("Tracking page view:",e,i),this.supabase.from("page_analytics").insert({page_url:e,page_title:i,locale:o,user_agent:a,referrer:n,session_id:this.sessionId,event_type:"pageview",created_at:new Date().toISOString()}).then(e=>{let{error:t}=e;t&&this.options.debug&&console.error("Error tracking page view:",t)})}constructor(e={}){this.options=e,this.supabase=(0,i.u)(),this.sessionId=crypto.randomUUID(),this.excludedPaths=[/\/products\/?$/,/\/products\/[^/]+\/?$/,/\/cart\/?$/,/\/checkout\/?$/,/\/account\/orders\/?$/,/\/success\/?$/],e.excludePaths&&(this.excludedPaths=[...this.excludedPaths,...e.excludePaths.map(e=>new RegExp(e))]),e.debug&&console.log("SupabaseAnalyticsProvider initialized with session ID:",this.sessionId)}}},81023:(e,t,r)=>{r.r(t),r.d(t,{usePageViewTracking:()=>n});var i=r(12115),o=r(35695);function n(e){let t=(0,o.usePathname)(),r=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!e||!t||t===r.current)return;if(t.startsWith("/admin")){r.current=t;return}r.current=t;let i=t+window.location.search;e.trackPageView(i)},[e,t])}},90658:(e,t,r)=>{r.d(t,{e:()=>i.e});var i=r(64697)}}]); |