1import{r as d,j as e,a as S,u as V,F as J,t as Q}from"./index-XOty-1m8.js";import{F as Z}from"./FilterBar-CNffUlc5.js";import{C as ee}from"./ConnectGoogleButton-DaTHqbA4.js";import{K as C,D as F,R as G,L as R,X as D,Y as L,T as E,a as A}from"./DynamicTooltip-DqJxzWaH.js";import{S as _}from"./Google_Ads_logo-DDib3zEn.js";import{u as I}from"./useCurrency-DgkhYIAs.js";import{s as te}from"./dateUtils--IggGAkn.js";import"./DateRangePicker-Dp_orY21.js";const re=({shop:i,className:l="",startDate:o,endDate:r})=>{var f,t,n;const[s,y]=d.useState(null),[j,u]=d.useState(!0),[a,g]=d.useState(null),p=async()=>{try{u(!0),g(null);const v={shop:i};o&&(v.start_date=o),r&&(v.end_date=r);const z=await S.get("/kpi/google/cac",{params:v});console.log("Google CAC data response:",z.data),y(z.data)}catch(v){g(v instanceof Error?v.message:"Failed to fetch data"),console.error("Error fetching Google CAC data:",v)}finally{u(!1)}};if(d.useEffect(()=>{i&&p()},[i,o,r]),j)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(a||!s)return e.jsx(C,{title:"CAC (Google Ads)",className:l,message:a||"Something went wrong while loading Google CAC.",onRetry:p});const b=((f=s.weekly_data)==null?void 0:f.map(v=>({week:v.week_label,cac:v.cac})))||[];return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-visible ${l} w-full`,children:[e.jsx("style",{children:` 2 .gross-sales-widget .chart-x-axis { 3 font-size: 11px; 4 fill: rgba(148, 163, 184, 1); 5 } 6 `}),e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"CAC (Google Ads)"}),e.jsx(F,{title:"Customer Acquisition Cost (CAC)",content:"CAC measures how much it costs to acquire a new customer through Google Ads. It's calculated by dividing total ad spend by the number of new customers acquired. Lower CAC indicates more efficient customer acquisition.",ariaLabel:"Information about CAC (Google Ads)"})]}),e.jsxs("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:["â¹",s.cac.toFixed(2)]}),e.jsxs("div",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400",children:["â¹",((t=s.spend)==null?void 0:t.toFixed(2))||((n=s.total_spend)==null?void 0:n.toFixed(2))||"0.00"," spend ⢠",s.new_customers," new customers"]}),b.length>0&&e.jsx("div",{className:"h-40 mt-4",children:e.jsx(G,{width:"100%",height:"100%",children:e.jsxs(R,{data:b,margin:{top:5,right:5,left:5,bottom:5},children:[e.jsx(D,{dataKey:"week",axisLine:!1,tickLine:!1,tick:{fontSize:10,fill:"#9CA3AF"}}),e.jsx(L,{hide:!0}),e.jsx(E,{contentStyle:{backgroundColor:"#374151",border:"1px solid #6B7280",borderRadius:"6px",color:"#F3F4F6",fontSize:"12px"},formatter:v=>[`â¹${v.toFixed(2)}`,"CAC"]}),e.jsx(A,{type:"monotone",dataKey:"cac",stroke:"#4285F4",strokeWidth:2,dot:!1})]})})})]})},ae=({shop:i,className:l="",startDate:o,endDate:r})=>{var f;const[s,y]=d.useState(null),[j,u]=d.useState(!0),[a,g]=d.useState(null),p=async()=>{try{u(!0),g(null);const t={shop:i};o&&(t.start_date=o),r&&(t.end_date=r);const n=await S.get("/kpi/google/roas",{params:t});y(n.data)}catch(t){g(t instanceof Error?t.message:"Failed to fetch data"),console.error("Error fetching Google ROAS data:",t)}finally{u(!1)}};if(d.useEffect(()=>{i&&p()},[i,o,r]),j)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(a||!s)return e.jsx(C,{title:"ROAS (Google Ads)",className:l,message:a||"Something went wrong while loading Google ROAS.",onRetry:p});s.roas>=1;const b=((f=s.weekly_data)==null?void 0:f.map(t=>({week:t.week_label,roas:t.roas})))||[];return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-visible ${l} w-full`,children:[e.jsx("style",{children:` 7 .gross-sales-widget .chart-x-axis { 8 font-size: 11px;
9 fill: rgba(148, 163, 184, 1); 10 } 11 `}),e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"ROAS (Google Ads)"}),e.jsx(F,{title:"Return on Ad Spend (ROAS)",content:"ROAS measures the revenue generated for every rupee spent on Google Ads. It's calculated by dividing revenue by ad spend. A ROAS of 4x means you earn â¹4 for every â¹1 spent. Higher ROAS indicates better ad performance.",ariaLabel:"Information about ROAS (Google Ads)"})]}),e.jsxs("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:[s.roas.toFixed(2),"x"]}),e.jsxs("div",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400",children:["â¹",s.revenue.toFixed(2)," revenue ⢠â¹",s.spend.toFixed(2)," spend"]}),b.length>0&&e.jsx("div",{className:"h-40 mt-4",children:e.jsx(G,{width:"100%",height:"100%",children:e.jsxs(R,{data:b,margin:{top:5,right:5,left:5,bottom:5},children:[e.jsx(D,{dataKey:"week",axisLine:!1,tickLine:!1,tick:{fontSize:10,fill:"#9CA3AF"}}),e.jsx(L,{hide:!0}),e.jsx(E,{contentStyle:{backgroundColor:"#374151",border:"1px solid #6B7280",borderRadius:"6px",color:"#F3F4F6",fontSize:"12px"},formatter:t=>[`${t.toFixed(2)}x`,"ROAS"]}),e.jsx(A,{type:"monotone",dataKey:"roas",stroke:"#4285F4",strokeWidth:2,dot:!1})]})})})]})},se=({shop:i,className:l="",startDate:o,endDate:r})=>{var f;const[s,y]=d.useState(null),[j,u]=d.useState(!0),[a,g]=d.useState(null),p=async()=>{try{u(!0),g(null);const t={shop:i};o&&(t.start_date=o),r&&(t.end_date=r);const n=await S.get("/kpi/google/revenue",{params:t});y(n.data)}catch(t){g(t instanceof Error?t.message:"Failed to fetch data"),console.error("Error fetching Google revenue data:",t)}finally{u(!1)}};if(d.useEffect(()=>{i&&p()},[i,o,r]),j)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(a||!s)return e.jsx(C,{title:"Revenue (Google Ads)",className:l,message:a||"Something went wrong while loading Google revenue.",onRetry:p});const b=((f=s.weekly_data)==null?void 0:f.map(t=>({week:t.week_label,revenue:t.revenue})))||[];return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-hidden ${l} w-full`,children:[e.jsx("style",{children:` 12 .gross-sales-widget .chart-x-axis { 13 font-size: 11px; 14 fill: rgba(148, 163, 184, 1); 15 } 16 `}),e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"Revenue (Google Ads)"}),e.jsx(F,{title:"Revenue from Google Ads",content:"Total revenue generated from orders attributed to Google Ads during the selected period. This metric shows the direct financial impact of your Google advertising campaigns.",ariaLabel:"Information about Revenue (Google Ads)"})]}),e.jsxs("div",{className:"mb-3 text-xl font-semibold text-gray-900 dark:text-white",children:["â¹",s.revenue.toFixed(2)]}),b.length>0&&e.jsx("div",{className:"h-40 mt-2 ml-3",children:e.jsx(G,{width:"100%",height:"100%",children:e.jsxs(R,{data:b,margin:{top:5,right:5,left:5,bottom:5}
16,children:[e.jsx(D,{dataKey:"week",axisLine:!1,tickLine:!1,tick:{fontSize:10,fill:"#9CA3AF"}}),e.jsx(L,{hide:!0}),e.jsx(E,{contentStyle:{backgroundColor:"#374151",border:"1px solid #6B7280",borderRadius:"6px",color:"#F3F4F6",fontSize:"12px"},formatter:t=>[`â¹${t.toFixed(2)}`,"Revenue"]}),e.jsx(A,{type:"monotone",dataKey:"revenue",stroke:"#4285F4",strokeWidth:2,dot:!1})]})})})]})},oe=({shop:i,className:l="",startDate:o,endDate:r})=>{var f;const[s,y]=d.useState(null),[j,u]=d.useState(!0),[a,g]=d.useState(null),p=async()=>{try{u(!0),g(null);const t={shop:i};o&&(t.start_date=o),r&&(t.end_date=r);const n=await S.get("/kpi/google/mer",{params:t});y(n.data)}catch(t){g(t instanceof Error?t.message:"Failed to fetch data"),console.error("Error fetching Google MER data:",t)}finally{u(!1)}};if(d.useEffect(()=>{i&&p()},[i,o,r]),j)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(a||!s)return e.jsx(C,{title:"MER (Google Ads)",className:l,message:a||"Something went wrong while loading Google MER.",onRetry:p});s.mer>=1;const b=((f=s.weekly_data)==null?void 0:f.map(t=>({week:t.week_label,mer:t.mer})))||[];return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-visible ${l} w-full`,children:[e.jsx("style",{children:` 17 .gross-sales-widget .chart-x-axis { 18 font-size: 11px; 19 fill: rgba(148, 163, 184, 1); 20 } 21 `}),e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"MER (Google Ads)"}),e.jsx(F,{title:"Marketing Efficiency Ratio (MER)",content:"MER measures the overall marketing efficiency by comparing total revenue to total ad spend across all channels. It's calculated by dividing total revenue by total spend. A MER of 3x means you generate â¹3 in revenue for every â¹1 spent on marketing.",ariaLabel:"Information about MER (Google Ads)"})]}),e.jsxs("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:[s.mer.toFixed(2),"x"]}),e.jsxs("div",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400",children:["â¹",s.total_revenue.toFixed(2)," revenue ⢠â¹",s.total_spend.toFixed(2)," spend"]}),b.length>0&&e.jsx("div",{className:"h-40 mt-4",children:e.jsx(G,{width:"100%",height:"100%",children:e.jsxs(R,{data:b,margin:{top:5,right:5,left:5,bottom:5},children:[e.jsx(D,{dataKey:"week",axisLine:!1,tickLine:!1,tick:{fontSize:10,fill:"#9CA3AF"}}),e.jsx(L,{hide:!0}),e.jsx(E,{contentStyle:{backgroundColor:"#374151",border:"1px solid #6B7280",borderRadius:"6px",color:"#F3F4F6",fontSize:"12px"},formatter:t=>[`${t.toFixed(2)}x`,"MER"]}),e.jsx(A,{type:"monotone",dataKey:"mer",stroke:"#4285F4",strokeWidth:2,dot:!1})]})})})]})},de=({shop:i,className:l="",startDate:o,endDate:r})=>{var t;const{formatNumber:s}=I(),[y,j]=d.useState(null),[u,a]=d.useState(!0),[g,p]=d.useState(null),b=async()=>{try{a(!0),p(null);const n={shop:i};o&&(n.start_date=o),r&&(n.end_date=r);const v=await S.get("/kpi/google/new-customers",{params:n});j(v.data)}catch(n){p(n instanceof Error?n.message:"Failed to fetch data"),console.error("Error fetching Google new customers data:",n)}finally{a(!1)}};if(d.useEffect(()=>{i&&b()},[i,o,r]),u)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(g||!y)return e.jsx(C,{title:"New Customers (Google Ads)",className:l,message:g||"Something went wrong while loading Google new customers.",onRetry:b});const f=((t=y.weekly_data)==null?void 0:t.map(n=>({week:n.week_label,new_customers:n.new_customers})))||[];return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-visible ${l} w-full`,children:[e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dar
21k:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"New Customers (Google Ads)"}),e.jsx(F,{title:"New Customers",content:"The total number of new customers acquired through Google Ads during the selected period. This metric helps track customer growth and acquisition effectiveness.",ariaLabel:"Information about New Customers (Google Ads)"})]}),e.jsx("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:y.new_customers}),f.length>0&&e.jsx("div",{className:"h-40 mt-4",children:e.jsx(G,{width:"100%",height:"100%",children:e.jsxs(R,{data:f,margin:{top:5,right:5,left:5,bottom:5},children:[e.jsx(D,{dataKey:"week",axisLine:!1,tickLine:!1,tick:{fontSize:10,fill:"#9CA3AF"}}),e.jsx(L,{hide:!0}),e.jsx(E,{contentStyle:{backgroundColor:"#374151",border:"1px solid #6B7280",borderRadius:"6px",color:"#F3F4F6",fontSize:"12px"},formatter:n=>[s(n),"New Customers"]}),e.jsx(A,{type:"monotone",dataKey:"new_customers",stroke:"#4285F4",strokeWidth:2,dot:!1})]})})})]})},ie=({shop:i,className:l="",startDate:o,endDate:r})=>{var f;const[s,y]=d.useState(null),[j,u]=d.useState(!0),[a,g]=d.useState(null),p=async()=>{try{u(!0),g(null);const t={shop:i};o&&(t.start_date=o),r&&(t.end_date=r);const n=await S.get("/kpi/google/cpp",{params:t});y(n.data)}catch(t){g(t instanceof Error?t.message:"Failed to fetch data"),console.error("Error fetching Google CPP data:",t)}finally{u(!1)}};if(d.useEffect(()=>{i&&p()},[i,o,r]),j)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(a||!s)return e.jsx(C,{title:"CPP (Google Ads)",className:l,message:a||"Something went wrong while loading Google CPP.",onRetry:p});const b=((f=s.weekly_data)==null?void 0:f.map(t=>({week:t.week_label,cpp:t.cpp})))||[];return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-hidden ${l} w-full`,children:[e.jsx("style",{children:` 22 .gross-sales-widget .chart-x-axis { 23 font-size: 11px; 24 fill: rgba(148, 163, 184, 1); 25 } 26 `}),e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"CPP (Google Ads)"}),e.jsx(F,{title:"Cost Per Purchase (CPP)",content:"CPP measures the average cost to generate a purchase through Google Ads. It's calculated by dividing total ad spend by the number of purchases. Lower CPP indicates more efficient ad spending.",ariaLabel:"Information about CPP (Google Ads)"})]}),e.jsxs("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:["â¹",s.cpp.toFixed(2)]}),e.jsxs("div",{className:"mt-2 mb-3 text-xs text-gray-500 dark:text-gray-400",children:[s.purchases," purchases ⢠â¹",s.total_spend.toFixed(2)," spend"]}),b.length>0&&e.jsx("div",{className:"h-40 mt-2 ml-3",children:e.jsx(G,{width:"100%",height:"100%",children:e.jsxs(R,{data:b,margin:{top:5,right:5,left:5,bottom:5},children:[e.jsx(D,{dataKey:"week",axisLine:!1,tickLine:!1,tick:{fontSize:10,fill:"#9CA3AF"}}),e.jsx(L,{hide:!0}),e.jsx(E,{contentStyle:{backgroundColor:"#374151",border:"1px solid #6B7280",borderRadius:"6px",color:"#F3F4F6",fontSize:"12px"},formatter:t=>[`â¹${t.toFixed(2)}`,"CPP"]}),e.jsx(A,{type:"monotone",dataKey:"cpp",stroke:"#4285F4",strokeWidth:2,dot:!1})]})})})]})},ne=({shop:i,className:l="",startDate:o,endDate:r})=>{var f;
26const[s,y]=d.useState(null),[j,u]=d.useState(!0),[a,g]=d.useState(null),p=async()=>{try{u(!0),g(null);const t={shop:i};o&&(t.start_date=o),r&&(t.end_date=r);const n=await S.get("/kpi/google/blended-cac",{params:t});y(n.data)}catch(t){g(t instanceof Error?t.message:"Failed to fetch data"),console.error("Error fetching Google Blended CAC data:",t)}finally{u(!1)}};if(d.useEffect(()=>{i&&p()},[i,o,r]),j)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(a||!s)return e.jsx(C,{title:"Blended CAC (Google Ads)",className:l,message:a||"Something went wrong while loading Google blended CAC.",onRetry:p});const b=((f=s.weekly_data)==null?void 0:f.map(t=>({week:t.week_label,blended_cac:t.blended_cac})))||[];return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-hidden ${l} w-full`,children:[e.jsx("style",{children:` 27 .gross-sales-widget .chart-x-axis { 28 font-size: 11px; 29 fill: rgba(148, 163, 184, 1); 30 } 31 `}),e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"Blended CAC (Google Ads)"}),e.jsx(F,{title:"Blended Customer Acquisition Cost",content:"Blended CAC calculates the cost to acquire a customer by dividing total ad spend by all new orders (across all channels), not just Google-acquired customers. This provides a more holistic view of customer acquisition efficiency.",ariaLabel:"Information about Blended CAC (Google Ads)"})]}),e.jsxs("div",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:["â¹",s.blended_cac.toFixed(2)]}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4",children:[s.all_new_orders," new orders ⢠â¹",s.total_spend.toFixed(2)," spend"]}),b.length>0&&e.jsx("div",{className:"h-40 mt-4",children:e.jsx(G,{width:"100%",height:"100%",children:e.jsxs(R,{data:b,margin:{top:5,right:5,left:5,bottom:5},children:[e.jsx(D,{dataKey:"week",axisLine:!1,tickLine:!1,tick:{fontSize:10,fill:"#9CA3AF"}}),e.jsx(L,{hide:!0}),e.jsx(E,{contentStyle:{backgroundColor:"#374151",border:"1px solid #6B7280",borderRadius:"6px",color:"#F3F4F6",fontSize:"12px"},formatter:t=>[`â¹${t.toFixed(2)}`,"Blended CAC"]}),e.jsx(A,{type:"monotone",dataKey:"blended_cac",stroke:"#4285F4",strokeWidth:2,dot:!1})]})})})]})},le=({shop:i,className:l="",startDate:o,endDate:r,days:s=30})=>{const{formatCurrencyShort:y,formatCurrencyWithSymbol:j,formatCurrency:u}=I(),[a,g]=d.useState(null),[p,b]=d.useState(!0),[f,t]=d.useState(null),[n,v]=d.useState(null),z=async()=>{var c,x;try{const h=((c=(await S.get("/googleAd/account")).data)==null?void 0:c.accounts)??[],w=h.find(k=>k.is_primary)||(h.length>0?h[0]:null);v(w)}catch(m){((x=m.response)==null?void 0:x.status)!==404&&console.error("Error fetching Google Ads account:",m),v(null)}},T=c=>{const x=new Date(c);if(isNaN(x.getTime()))return c;const m=x.getDate().toString().padStart(2,"0"),h=x.toLocaleDateString("en-US",{month:"short"}),w=x.getFullYear();return`${m} ${h} ${w}`},K=async()=>{try{b(!0),t(null);const c={shop:i};o&&(c.start_date=o),r&&(c.end_date=r),!o&&!r&&s&&(c.days=s);const x=await S.get("/kpi/google/spend-trend",{params:c});g(x.data)}catch(c){t(c instanceof Error?c.message:"Failed to fetch data"),console.error("Error fetching Google spend trend data:",c)}finally{b(!1)}};d.useEffect(()=>{i&&(K(),z())},[i,o,r,s]);const W=({active:c,payload:x,label:m})=>{var P;if(!c||!(x!=null&&x.length))return null;const h=((P=x[0])==null?void 0:P.payload)||{},w=Number(h.spend??0),k=Number(h.prev_spend??0),N=h.raw_date!=null?T(h.raw_date):h.date||m||"Now",$=h.raw_prev_date!=null?T(h.raw_prev_date):h.prev_date||h.date||m||"Was";return e.jsx("div",{className:"rounded-md border border-gray-200 bg-white p-3 text-gray-800 shadow-lg dark:border-gray-700 dark:bg-gray-300 dark:text-white/40",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-primary font-medium",children:N}),e.jsx("br",{}),e.jsx("span",{className:"text-primary font-medium",children:j(w)})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-gray-400 font-medium",children:$}),e.jsx("br",{}),e.jsx("span",{className:"text-gray-400 font-medium",children:j(k)})]})]})})};if(p)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-40 bg-gray-200 rounded dark:bg-[#0d1828]"})]})});
31if(f||!a)return e.jsx(C,{title:"Spend Trend (Google)",className:l,message:f||"Something went wrong while loading Google Spend Trend.",onRetry:K});const q=a.trend.reduce((c,x)=>c+x.spend,0);(a.prev_trend||[]).reduce((c,x)=>c+x.spend,0);const M=(c,x)=>{if(isNaN(c.getTime())||isNaN(x.getTime()))return"";const m=c.getDate(),h=x.getDate(),w=c.toLocaleDateString("en-US",{month:"short"}),k=x.toLocaleDateString("en-US",{month:"short"}),N=c.getFullYear(),$=x.getFullYear();return N===$&&w===k?`${w} ${m}â${h}, ${N}`:N===$?`${m} ${w}â${h} ${k} ${N}`:`${m} ${w} ${N}â${h} ${k} ${$}`},U=()=>{var B,O;let c=o,x=r;if(!c||!x)if((B=a.period)!=null&&B.start_date&&((O=a.period)!=null&&O.end_date))c=a.period.start_date,x=a.period.end_date;else return{current:null,previous:null};const m=new Date(c),h=new Date(x);if(isNaN(m.getTime())||isNaN(h.getTime()))return{current:null,previous:null};const w=Math.floor((h.getTime()-m.getTime())/(1e3*60*60*24))+1,k=new Date(m);k.setDate(k.getDate()-1);const N=new Date(k);N.setDate(N.getDate()-(w-1));const $=M(m,h),P=M(N,k);return{current:$,previous:P}},{current:ge,previous:xe}=U(),Y=a.trend.map((c,x)=>{var h;const m=(h=a.prev_trend)==null?void 0:h[x];return{date:new Date(c.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),spend:c.spend,prev_spend:(m==null?void 0:m.spend)??0,raw_date:c.date,raw_prev_date:(m==null?void 0:m.date)??null,prev_date:m?new Date(m.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}):void 0}}),H=o&&r?{from:o,to:r}:null,X=Array.isArray(a.prev_trend)&&a.prev_trend.length>0;return e.jsxs("div",{className:`google-kpi-card rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-visible ${l} w-full`,children:[e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4 text-teal-600 dark:text-teal-400"})})]})}),e.jsxs("div",{className:"flex items-center justify-between mb-3 gross-sales-title",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"Google Total Spend"}),e.jsx(F,{title:"Spend Trend",content:"Shows the daily spending pattern for your Google Ads over the selected period. This helps track budget allocation, identify spending trends, and optimize ad spend distribution.",ariaLabel:"Information about Spend Trend (Google Ads)"})]}),n&&e.jsxs("div",{className:"text-right text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("div",{className:"font-medium text-teal-600 dark:text-teal-400",children:n.account_alias||n.account_name}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-500",children:"Google Ads"})]})]}),e.jsx("div",{className:"mt-1 text-xl font-semibold text-black dark:text-white",children:j(q)}),!te(H)&&e.jsx("div",{className:"h-[180px] -ml-5 mt-5",children:e.jsx(G,{width:"100%",height:"100%",minWidth:0,minHeight:0,children:e.jsxs(R,{data:Y,margin:{top:5,right:0,left:0,bottom:0},children:[e.jsx(D,{dataKey:"date",axisLine:!0,tickLine:!0,tick:{fontSize:10,fill:"#94a3b8"},tickFormatter:c=>{const x=new Date(c),m=String(x.getDate()).padStart(2,"0"),h=x.toLocaleDateString("en-US",{month:"short"});return`${m} ${h}`}}),e.jsx(L,{tick:{fontSize:10,fill:"#94a3b8"},tickFormatter:c=>u(c,{compact:!0})}),e.jsx(E,{cursor:{fill:"transparent"},content:e.jsx(W,{})}),e.jsx(A,{type:"monotone",dataKey:"spend",stroke:"#41BFB8",strokeWidth:2,dot:!1}),X&&e.jsx(A,{type:"monotone",dataKey:"prev_spend",stroke:"#7a7878",strokeWidth:2,dot:!1,strokeDasharray:"5 5"})]})})}),n&&e.jsx("div",{className:"mt-3 pt-3 border-t border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"text-gray-500 dark:text-gray-400",children:["Account: ",e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:n.account_alias||n.account_name})]}
31),e.jsx("button",{className:"text-teal-600 dark:text-teal-400 hover:text-teal-700 dark:hover:text-teal-300 font-medium",onClick:()=>{window.location.href="/integrations?tab=google"},children:"Manage Account"})]})})]})},ce=({shop:i,className:l="",startDate:o,endDate:r})=>{const[s,y]=d.useState(null),[j,u]=d.useState(!0),[a,g]=d.useState(null),p=async()=>{try{u(!0),g(null);const t={shop:i};o&&(t.start_date=o),r&&(t.end_date=r);const n=await S.get("/kpi/google/profit-per-campaign",{params:t});y(n.data)}catch(t){g(t instanceof Error?t.message:"Failed to fetch data"),console.error("Error fetching Google profit per campaign data:",t)}finally{u(!1)}};if(d.useEffect(()=>{i&&p()},[i,o,r]),j)return e.jsx("div",{className:`${l}`,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32 mb-2 dark:bg-[#0d1828]"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 dark:bg-[#0d1828]"})]})});if(a||!s)return e.jsx(C,{className:l,message:a||"Something went wrong while loading Google profit per campaign.",onRetry:p});const b=s.campaigns.reduce((t,n)=>t+n.profit,0),f=[...s.campaigns].sort((t,n)=>n.profit-t.profit).slice(0,5);return e.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-2 dark:border-gray-700 dark:bg-gray-800 relative overflow-visible ${l} w-full`,children:[e.jsx("div",{className:"z-20",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-lg"}),e.jsx("div",{className:"relative inline-flex items-center justify-center p-1 transition-transform duration-200 hover:scale-110 dark:bg-gray-900 rounded-full",children:e.jsx(_,{className:"h-4 w-4"})})]})}),e.jsxs("div",{className:"flex items-center mb-3 gross-sales-title",children:[e.jsx("div",{className:"widget-title text-gray-800 dark:text-white/90",children:"Profit Per Campaign (Google Ads)"}),e.jsx(F,{title:"Profit per Campaign",content:"Shows the profit (revenue minus spend) for each Google Ads campaign. Profit is calculated by subtracting ad spend from attributed revenue. This helps identify which campaigns are most profitable and worth scaling.",ariaLabel:"Information about Profit Per Campaign (Google Ads)"})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"text-xl font-semibold font-semibold text-gray-900 dark:text-white",children:["â¹",b.toFixed(2)]}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:[s.campaigns.length," campaigns"]})]}),f.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-xs font-semibold text-gray-700 dark:text-gray-200 mb-2",children:"Top 5 Campaigns by Profit"}),e.jsx("div",{className:"space-y-2 max-h-40 overflow-auto pr-1",children:f.map(t=>e.jsxs("div",{className:"flex items-center justify-between text-xs border-b border-gray-100 dark:border-gray-700 pb-1 last:border-b-0",children:[e.jsxs("div",{className:"flex-1 min-w-0 mr-2",children:[e.jsx("div",{className:"font-semibold text-gray-800 dark:text-gray-100 truncate",children:t.campaign_name}),e.jsxs("div",{className:"text-[10px] text-gray-500 dark:text-gray-400",children:["Rev: â¹",t.revenue.toFixed(2)," ⢠Spend: â¹",t.spend.toFixed(2)]})]}),e.jsx("div",{className:"text-right",children:e.jsxs("div",{className:`text-sm font-semibold ${t.profit>=0?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:["â¹",t.profit.toFixed(2)]})})]},t.campaign_id||t.campaign_name))})]})]})};function ve(){const{currentShop:i}=V(),[l]=J(),o=l.get("shop"),r=d.useMemo(()=>o||i||null,[o,i]),s=g=>g?{startDate:g.from,endDate:g.to}:{startDate:new Date().toISOString().split("T")[0],endDate:new Date().toISOString().split("T")[0]},[y,j]=d.useState(()=>({from:new Date(Date.now()-2592e6).toISOString().split("T")[0],to:new Date().toISOString().split("T")[0]})),u=d.useMemo(()=>y,[y]),a=d.useMemo(()=>s(y),[y]);return e.jsxs(e.Fragment,{children:[e.jsx(Q,{title:"Google Ads Dashboard - Netsights",description:"Track your Google Ads performance, ROAS, CAC, and other key metrics"}),e.jsxs("div",{className:"max-w-7xl mx-auto py-8 px-4",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white mb-6",children:"Google Ads Dashboard"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-8",children:"Connect your Google Ads account to track performance, ROAS, CAC, and revenue attribution."}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8",children:e.jsxs("div",{className:"bg-gradient-to-r from-red-50 via-orange-50 to-yellow-50 dark:from-red-900/30 dark:via-orange-900/30 dark:to-yellow-900/30 rounded-xl border-2 border-red-300 dark:border-red-700 p-6 shadow-xl",children:[e.jsxs("div",{className:"text-center mb-4",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 bg-white rounded-full mb-3 shadow-lg",children:e.jsxs("svg",{className:"w-8 h-8",viewBox:"0 0 24 24",fill:"
31currentColor",children:[e.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),e.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),e.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),e.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2 capitalize",children:"Google Ads"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-1",children:"Search & Display Ads"}),r?e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-500 mt-2",children:["Store: ",e.jsx("span",{className:"font-semibold",children:r})]}):e.jsx("p",{className:"text-xs text-yellow-600 dark:text-yellow-400 mt-2",children:"Select a shop to connect"})]}),e.jsx(ee,{})]})}),!r&&e.jsx("div",{className:"mb-8 p-6 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-400 text-center",children:["Please add ",e.jsx("code",{className:"px-2 py-1 bg-yellow-100 dark:bg-yellow-900/40 rounded",children:"?shop=yourstore.myshopify.com"})," to the URL or select a shop from your account."]})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white mb-2",children:"Google Ads Dashboard"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Real-time analytics and insights for your Google Ads campaigns"})]}),e.jsx(Z,{dateRange:u,onDateRangeChange:g=>{g&&j(g)},onApply:()=>{j({...y})},applyLabel:"Apply Filter"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 mb-8",children:[e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm min-h-[160px] flex flex-col justify-center",children:e.jsx(re,{shop:r,startDate:a.startDate,endDate:a.endDate})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm min-h-[160px] flex flex-col justify-center",children:e.jsx(ae,{shop:r,startDate:a.startDate,endDate:a.endDate})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm min-h-[160px] flex flex-col justify-center",children:e.jsx(oe,{shop:r,startDate:a.startDate,endDate:a.endDate})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm min-h-[160px] flex flex-col justify-center",children:e.jsx(se,{shop:r,startDate:a.startDate,endDate:a.endDate})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm min-h-[160px] flex flex-col justify-center",children:e.jsx(de,{shop:r,startDate:a.startDate,endDate:a.endDate})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm min-h-[160px] flex flex-col justify-center",children:e.jsx(ie,{shop:r,startDate:a.startDate,endDate:a.endDate})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm min-h-[160px] flex flex-col justify-center",children:e.jsx(ne,{shop:r,startDate:a.startDate,endDate:a.endDate})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8",children:[e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm",children:e.jsx(le,{shop:r,days:30})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 shadow-sm",children:e.jsx(ce,{shop:r,startDate:a.startDate,endD
31ate:a.endDate})})]})]})]})]})}export{ve as default}; 32//# sourceMappingURL=GoogleAdsDashboard-COGmwFmZ.js.map
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.