PageSourceSearch

https://app.cosmicjs.com/_next/static/chunks/pages/projects/[projectID]/insights-b62abe36c53f83f4.js

js cosmicjs.com collected 2026-09-24 17:52:21 UTC 14,457 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6887],{13059:function(e,t,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/projects/[projectID]/insights",function(){return r(74470)}])},74470:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return T}});var n=r(28598),s=r(82684),i=r(12691),a=r(77203),o=r(13669),c=r(68783),l=r(34336),d=r(24919),u=function(e){return'<script\n  defer\n  src="'.concat("https://insights.cosmicinsights.dev",'/script.js"\n  data-project="').concat(e||"YOUR_PROJECT_ID",'"\n><\/script>')},g=function(e){var t=e.number,r=e.title,s=e.description,i=e.code,a=e.language;return(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("span",{className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-cosmic-blue/10 text-[11px] font-semibold text-cosmic-blue dark:bg-cosmic-blue/20 dark:text-cosmic-blue-lighter",children:t}),(0,n.jsx)("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-50",children:r})]}),(0,n.jsx)("p",{className:"text-sm text-gray-600 dark:text-gray-400 pl-7",children:s}),(0,n.jsx)("div",{className:"pl-7",children:(0,n.jsx)(d.Z,{language:a,code:i,showCopyButton:!0,overrideCopyPosition:!0})})]})},h=function(e){var t=e.projectId;return(0,n.jsxs)("div",{className:"rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 p-6 sm:p-8",children:[(0,n.jsxs)("div",{className:"flex items-start gap-4",children:[(0,n.jsx)("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-cosmic-blue/10 dark:bg-cosmic-blue/20",children:(0,n.jsx)(l.Z,{className:"h-6 w-6 text-cosmic-blue dark:text-cosmic-blue-lighter"})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-50",children:"Get started with Cosmic Insights"}),(0,n.jsx)("p",{className:"mt-1 text-sm text-gray-600 dark:text-gray-400",children:"Add the tracker to your app to see live pageviews, visitors, and sessions here. Apps generated by Cosmic AI Studio already include the tracker."})]})]}),(0,n.jsxs)("div",{className:"mt-6 space-y-6",children:[(0,n.jsx)(g,{number:1,title:"Install the tracker",description:"Drop this script tag into the head of your app. It auto-fires a pageview on every navigation, no extra setup needed.",code:u(t),language:"markup"}),(0,n.jsx)(g,{number:2,title:"Track object views",description:"Add a meta tag to pages that represent a Cosmic object so pageviews get attributed to that object on the Content tab.",code:'<meta\n  name="cosmic-context"\n  content=\'{"object_id":"OBJECT_ID","object_type":"posts"}\'\n>',language:"markup"}),(0,n.jsx)(g,{number:3,title:"Track custom events",description:"Call window.cosmicInsights() to record signups, button clicks, purchases, and any other action you want to measure.",code:"window.cosmicInsights('signup_click', {\n  plan: 'pro',\n});",language:"javascript"})]}),(0,n.jsx)("div",{className:"mt-6 pt-6 border-t border-gray-100 dark:border-gray-800",children:(0,n.jsxs)("a",{href:"https://www.cosmicjs.com/docs/insights",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-sm font-medium text-cosmic-blue hover:text-cosmic-deep-blue dark:hover:text-cosmic-blue-lighter",children:["Read the full Insights docs",(0,n.jsx)(a.Z,{className:"h-3.5 w-3.5"})]})})]})},m=r(88020),v=r(1889),p=r(66391),f=(0,r(51774).default)((function(){return Promise.all([r.e(7750),r.e(3678)]).then(r.bind(r,13678)).then((function(e){return e.RequestDistributionMap}))}),{loadableGenerated:{webpack:function(){return[13678]}},ssr:!1,loading:function(){return(0,n.jsx)("section",{className:"rounded-lg border border-gray-200 bg-white p-6 text-sm text-gray-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-400",children:"Loading map..."})}}),x=r(90597),b=r(17070),y=r(15069),j=function(e){var t=e.projectId,r=e.cap,s=e.softCapPct,i=void 0===s?.8:s,a=(0,b.vw)(t),o=a.data,c=a.isLoading;if(!t||c||!o)return null;if(!o.configured)return(0,n.jsx)(x.Z,{type:"info",children:"Cosmic Insights is not yet provisioned for this environment. Events will start appearing here within 5 minutes of deploying a tracker-enabled app."});var l=function(e){if(!e)return null;var t=new Date(e).getTime();if(Number.isNaN(t))return null;var r=Date.now()-t;if(r<0)return"just now";var n=Math.round(r/1e3);if(n<60)return"".concat(n,"s ago");var s=Math.round(n/60);if(s<60)return"".concat(s,"m ago");var i=Math.round(s/60);return"".concat(i,"h ago")}(o.last_synced_at);if(r&&o.events>=Math.floor(r*i)){var d=Math.min(100,Math.round(o.events/r*100));return o.events>=r?(0,n.jsxs)(x.Z,{type:"danger",children:["You've used ",(0,n.jsx)("strong",{children:(0,y.uf)(o.events)})," of"," ",(0,n.jsx)("strong",{children:(0,y.uf)(r)})," events this month (",d,"%). New events are being dropped until your plan resets or you upgrade.",l?(0,n.jsxs)("span",{className:"ml-1 text-xs opacity-70",children:["Counters last refreshed ",l,"."]}):null]}):(0,n.jsxs)(x.Z,{type:"warning",children:["You've used ",(0,n.jsx)("strong",{children:(0,y.uf)(o.events)})," of"," ",(0,n.jsx)("strong",{children:(0,y.uf)(r)})," events this month (",d,"%). Consider upgrading your plan to avoid the hard cap.",l?(0,n.jsxs)("span",{className:"ml-1 text-xs opacity-70",children:["Counters last refreshed ",l,"."]}):null]})}return null},w=r(76251);function k(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"===typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}
1)))),n.forEach((function(t){k(e,t,r[t])}))}return e}var _=function(e,t){return e.reduce((function(e,r){return e+(Number(r[t])||0)}),0)},C=function(){var e,t,r,l,d,u,g,x,k,C,L,T,I=(0,o.Z)().project,O=null===I||void 0===I?void 0:I.id,P=(0,w.GH)(),D=P.range,M=P.bucketSlug,V=(0,s.useState)("visitors"),E=V[0],S=V[1],Z={start:D.start,end:D.end,bucket_slug:M||void 0},J=function(){if("1d"===D.preset)return"hour";if("custom"!==D.preset)return"day";var e=(0,y.k9)(D.start),t=(0,y.k9)(D.end);if(Number.isNaN(e.getTime())||Number.isNaN(t.getTime()))return"day";var r=(t.getTime()-e.getTime())/36e5;return r>0&&r<=48?"hour":"day"}(),R=(0,b.M6)(O,N({},Z,{granularity:J})),U=(0,y.sg)(D.start,D.end),$=(0,b.M6)(O,{start:null===U||void 0===U?void 0:U.start,end:null===U||void 0===U?void 0:U.end,bucket_slug:M||void 0,granularity:J}),z=(0,b.DS)(O,Z),A=(0,b.DS)(O,{start:null===U||void 0===U?void 0:U.start,end:null===U||void 0===U?void 0:U.end,bucket_slug:M||void 0}),K=(0,b.D7)(O,N({},Z,{granularity:J})),Y=(0,b.YU)(O,N({},Z,{limit:10})),q=(0,b.hK)(O,N({},Z,{limit:10})),B=(0,b.T)(O,N({},Z,{limit:10})),G=(0,b.Uz)(O,N({},Z,{group_by:"city",limit:500})),X=(0,b.vw)(O),F=(null===(e=R.data)||void 0===e?void 0:e.rows)||[],H=R.data?(0,y.q$)(F,R.data.start||D.start,R.data.end||D.end,J):F,Q=new Map(((null===(t=K.data)||void 0===t?void 0:t.rows)||[]).map((function(e){return[e.day,e.bounce_rate]}))),W=H.map((function(e){return N({},e,{bounce_rate:null!==(C=Q.get(e.day))&&void 0!==C?C:0})})),ee=_(W,"events"),te=_(W,"visitors"),re=_(W,"sessions"),ne=(null===(r=$.data)||void 0===r?void 0:r.rows)||[],se=_(ne,"events"),ie=_(ne,"visitors"),ae=_(ne,"sessions"),oe=(0,y.J$)(ee,se),ce=(0,y.J$)(te,ie),le=(0,y.J$)(re,ae),de=null!==(L=null===(l=z.data)||void 0===l?void 0:l.bounce_rate)&&void 0!==L?L:0,ue=null!==(T=null===(d=A.data)||void 0===d?void 0:d.bounce_rate)&&void 0!==T?T:0,ge=(0,y.J$)(de,ue),he=function(e){if("1d"===e)return"vs. previous 24 hours";var t=w.D6.find((function(t){return t.key===e}));return t?"vs. previous ".concat(t.days," days"):"vs. previous period"}(D.preset),me=function(e,t){return"".concat(he,": ").concat((0,y.uf)(t)," \u2192 ").concat((0,y.uf)(e))},ve=function(e){return"".concat(Math.round(100*e),"%")},pe="".concat(he,": ").concat(ve(ue)," \u2192 ").concat(ve(de)),fe=((null===(u=X.data)||void 0===u?void 0:u.events)||0)>0||ee>0||te>0||re>0,xe=!!O&&!!X.data&&!!R.data&&X.data.configured&&!fe;return(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(j,{projectId:O}),(0,n.jsx)(c.V,{errors:[{label:"overview",error:R.error},{label:"bounce rate",error:z.error},{label:"bounce rate (chart)",error:K.error},{label:"top pages",error:q.error},{label:"top content",error:Y.error},{label:"top sources",error:B.error},{label:"geo distribution",error:G.error}]}),xe&&O&&(0,n.jsx)(h,{projectId:O}),!xe&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[(0,n.jsx)(v.f,{label:"Unique visitors",value:(0,y.uf)(te),loading:R.isLoading,delta:$.isLoading?null:ce,deltaTitle:me(te,ie),isNew:!$.isLoading&&0===ie&&te>0,active:"visitors"===E,onClick:function(){return S("visitors")}}),(0,n.jsx)(v.f,{label:"Pageviews",value:(0,y.uf)(ee),loading:R.isLoading,delta:$.isLoading?null:oe,deltaTitle:me(ee,se),isNew:!$.isLoading&&0===se&&ee>0,active:"events"===E,onClick:function(){return S("events")}}),(0,n.jsx)(v.f,{label:"Sessions",value:(0,y.uf)(re),loading:R.isLoading,delta:$.isLoading?null:le,deltaTitle:me(re,ae),isNew:!$.isLoading&&0===ae&&re>0,active:"sessions"===E,onClick:function(){return S("sessions")}}),(0,n.jsx)(v.f,{label:"Bounce Rate",value:z.data?ve(de):ve(0),loading:z.isLoading,delta:A.isLoading?null:ge,deltaInverse:!0,deltaTitle:"".concat(pe).concat(z.data&&z.data.sessions>
10?" (".concat((0,y.uf)(z.data.bounced_sessions)," of ").concat((0,y.uf)(z.data.sessions)," sessions)"):""),active:"bounce_rate"===E,onClick:function(){return S("bounce_rate")}})]}),(0,n.jsx)(p.X,{rows:W,metric:E,granularity:J}),function(){var e,t=(null===(e=G.data)||void 0===e?void 0:e.rows)||[];return G.isLoading||0!==t.length?(0,n.jsx)(f,{rows:t,loading:G.isLoading}):null}(),(0,n.jsxs)("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-2",children:[(0,n.jsxs)("section",{children:[(0,n.jsxs)("div",{className:"mb-2 flex items-baseline justify-between",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-50",children:"Top pages"}),(0,n.jsx)("a",{href:"/projects/".concat(O,"/insights/pages"),className:"text-sm text-cosmic-blue hover:text-cosmic-deep-blue",children:"View all"})]}),(0,n.jsx)(m.z,{rows:((null===(g=q.data)||void 0===g?void 0:g.rows)||[]).slice(0,10),rowKey:function(e,t){return"".concat(e.path,"|").concat(t)},empty:q.isLoading?"Loading...":"No pageviews yet",columns:[{key:"path",header:"Path",render:function(e){var t=e.path||"/",r=e.host?"https://".concat(e.host).concat(e.path||"/"):null;return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 max-w-[260px] align-bottom",children:[O?(0,n.jsx)(i.default,{href:"/projects/".concat(O,"/insights/pages?path_prefix=").concat(encodeURIComponent(e.path||"/")),children:(0,n.jsx)("a",{className:"font-mono text-xs text-cosmic-blue hover:underline truncate",title:"Filter by ".concat(t),children:t})}):(0,n.jsx)("span",{className:"font-mono text-xs text-gray-900 dark:text-gray-50 truncate",title:t,children:t}),r&&(0,n.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",onClick:function(e){return e.stopPropagation()},"aria-label":"Open ".concat(r," in new tab"),title:"Open ".concat(r),className:"opacity-0 group-hover:opacity-100 transition-opacity text-gray-400 hover:text-cosmic-blue dark:text-dark-gray-500 dark:hover:text-cosmic-blue",children:(0,n.jsx)(a.Z,{className:"w-3.5 h-3.5"})})]})}},{key:"views",header:"Views",align:"right",render:function(e){return(0,y.uf)(e.events)}},{key:"visitors",header:"Visitors",align:"right",render:function(e){return(0,y.uf)(e.visitors)}}]})]}),(0,n.jsxs)("section",{children:[(0,n.jsxs)("div",{className:"mb-2 flex items-baseline justify-between",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-50",children:"Top content"}),(0,n.jsx)("a",{href:"/projects/".concat(O,"/insights/objects"),className:"text-sm text-cosmic-blue hover:text-cosmic-deep-blue",children:"View all"})]}),(0,n.jsx)(m.z,{rows:((null===(x=Y.data)||void 0===x?void 0:x.rows)||[]).slice(0,10),rowKey:function(e){return e.object_id},empty:Y.isLoading?"Loading...":"No object pageviews yet",columns:[{key:"title",header:"Object",render:function(e){var t,r,s=(null===(t=e.entity)||void 0===t?void 0:t.title)||(null===(r=e.entity)||void 0===r?void 0:r.slug)||e.object_id.slice(0,8)+"...";return O?(0,n.jsx)(i.default,{href:"/projects/".concat(O,"/insights/objects/").concat(e.object_id),children:(0,n.jsx)("a",{className:"font-medium text-cosmic-blue hover:underline",children:s})}):(0,n.jsx)("span",{className:"font-medium text-gray-900 dark:text-gray-50",children:s})}},{key:"type",header:"Type",render:function(e){var t;return e.object_type||(null===(t=e.entity)||void 0===t?void 0:t.type)||"-"}},{key:"views",header:"Views",align:"right",render:function(e){return(0,y.uf)(e.events)}},{key:"visitors",header:"Visitors",align:"right",render:function(e){return(0,y.uf)(e.visitors)}}]})]}),(0,n.jsxs)("section",{className:"lg:col-span-2",children:[(0,n.jsxs)("div",{className:"mb-2 flex items-baseline justify-between",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-50",children:"Top sources"}),(0,n.jsx)("a",{href:"/projects/".concat(O,"/insights/sources"),className:"text-sm text-cosmic-blue hover:text-cosmic-deep-blue",children:"View all"})]}),(0,n.jsx)(m.z,{rows:((null===(k=B.data)||void 0===k?void 0:k.rows)||[]).slice(0,10),rowKey:function(e,t){return"".concat(e.source,"|").concat(e.medium,"|").concat(e.campaign,"|").concat(t)},empty:B.isLoading?"Loading...":"No traffic in this range",columns:[{key:"source",header:"Source",render:function(e){return e.source||"(direct)"}},{key:"medium",header:"Medium",render:function(e){return e.medium||"-"}},{key:"visits",header:"Visits",align:"right",render:function(e){return(0,y.uf)(e.events)}},{key:"visitors",header:"Visitors",align:"right",render:function(e){return(0,y.uf)(e.visitors)}}]})]})]})]})]})},L=r(85003),T=(0,r(27976).Z)((function(){return(0,n.jsx)(L.T,{children:(0,n.jsx)(C,{})})}))}},function(e){e.O(0,[9774,7229,2589,3893,8826,26,7359,6410,2867,8418,7556,2351,3538,3493,914,7269,8940,3680,6726,9935,2888,179],(function(){return t=13059,e(e.s=t);var t}));var t=e.O();_N_E=t}]);

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.