@shware/analytics 16.3.5 → 16.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
4
4
  const require_track_index = require("../track/index.cjs");
5
5
  const require_hooks_use_outbound_click_analytics = require("../hooks/use-outbound-click-analytics.cjs");
6
- const require_third_parties_integration = require("../third-parties/integration.cjs");
7
6
  const require_third_parties_microsoft_uet = require("../third-parties/microsoft-uet.cjs");
8
7
  const require_hooks_use_uet_id_sync = require("../hooks/use-uet-id-sync.cjs");
9
8
  const require_hooks_use_web_analytics = require("../hooks/use-web-analytics.cjs");
@@ -52,7 +51,7 @@ function Analytics({ integrations = [], facebookAppId, nonce, reportWebVitals =
52
51
  property: "fb:app_id",
53
52
  content: facebookAppId
54
53
  }),
55
- require_third_parties_integration.integrationScripts(integrations).map((script) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(next_script.default, {
54
+ integrations.flatMap(({ script }) => script ? [script] : []).map((script) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(next_script.default, {
56
55
  id: script.id,
57
56
  nonce,
58
57
  strategy: script.strategy ?? "afterInteractive",
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["usePathname","useSearchParams","uetCustomerIdOf","Suspense","integrationScripts","Script"],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { integrationScripts } from '../third-parties/integration';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrationScripts(integrations).map((script) => (\n <Script\n key={script.id}\n id={script.id}\n nonce={nonce}\n strategy={script.strategy ?? 'afterInteractive'}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBA,SAAS,YAAY;CACnB,MAAM,YAAA,GAAWA,gBAAAA,YAAAA,CAAY;CAC7B,MAAM,gBAAA,GAAeC,gBAAAA,gBAAAA,CAAgB;CACrC,gCAAA,gBAAgB,UAAU,aAAa,SAAS,CAAC;CACjD,OAAO;AACT;AAEA,SAAgB,UAAU,EACxB,eAAe,CAAC,GAChB,eACA,OACA,kBAAkB,QACD;CACjB,2CAAA,0BAA0B;CAC1B,8BAAA,aAAaC,oCAAAA,gBAAgB,YAAY,CAAC;CAC1C,sCAAA,uBAAuB,YAAY;CAEnC,CAAA,GAAA,gBAAA,mBAAA,EAAoB,WAAW;EAC7B,IAAI,CAAC,iBAAiB;EACtB,MAAM,aAAa;GACjB,OAAO,OAAO;GACd,WAAW,OAAO;GAClB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;GACtB,wBAAwB,OAAO;GAC/B,iBAAiB;EACnB;EACA,oBAAA,MAAM,OAAO,MAAM,UAAU;CAC/B,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;EACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,MAAAA,UAAD;GAAU,UAAU;GAClB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD,CAAY,CAAA;EACJ,CAAA;EACT,iBAAiB,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrEC,kCAAAA,mBAAmB,YAAY,CAAC,CAAC,KAAK,WACrC,iBAAA,GAAA,kBAAA,IAAA,CAACC,YAAAA,SAAD;GAEE,IAAI,OAAO;GACJ;GACP,UAAU,OAAO,YAAY;GAC7B,yBAAyB,EAAE,QAAQ,OAAO,OAAO;EAClD,GALM,OAAO,EAKb,CACF;CACD,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"index.cjs","names":["usePathname","useSearchParams","uetCustomerIdOf","Suspense","Script"],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrations\n .flatMap(({ script }) => (script ? [script] : []))\n .map((script) => (\n <Script\n key={script.id}\n id={script.id}\n nonce={nonce}\n strategy={script.strategy ?? 'afterInteractive'}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBA,SAAS,YAAY;CACnB,MAAM,YAAA,GAAWA,gBAAAA,YAAAA,CAAY;CAC7B,MAAM,gBAAA,GAAeC,gBAAAA,gBAAAA,CAAgB;CACrC,gCAAA,gBAAgB,UAAU,aAAa,SAAS,CAAC;CACjD,OAAO;AACT;AAEA,SAAgB,UAAU,EACxB,eAAe,CAAC,GAChB,eACA,OACA,kBAAkB,QACD;CACjB,2CAAA,0BAA0B;CAC1B,8BAAA,aAAaC,oCAAAA,gBAAgB,YAAY,CAAC;CAC1C,sCAAA,uBAAuB,YAAY;CAEnC,CAAA,GAAA,gBAAA,mBAAA,EAAoB,WAAW;EAC7B,IAAI,CAAC,iBAAiB;EACtB,MAAM,aAAa;GACjB,OAAO,OAAO;GACd,WAAW,OAAO;GAClB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;GACtB,wBAAwB,OAAO;GAC/B,iBAAiB;EACnB;EACA,oBAAA,MAAM,OAAO,MAAM,UAAU;CAC/B,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;EACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,MAAAA,UAAD;GAAU,UAAU;GAClB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD,CAAY,CAAA;EACJ,CAAA;EACT,iBAAiB,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrE,aACE,SAAS,EAAE,aAAc,SAAS,CAAC,MAAM,IAAI,CAAC,CAAE,CAAC,CACjD,KAAK,WACJ,iBAAA,GAAA,kBAAA,IAAA,CAACC,YAAAA,SAAD;GAEE,IAAI,OAAO;GACJ;GACP,UAAU,OAAO,YAAY;GAC7B,yBAAyB,EAAE,QAAQ,OAAO,OAAO;EAClD,GALM,OAAO,EAKb,CACF;CACH,EAAA,CAAA;AAEN"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";wBA0BgB,YACd,cACA,eACA,OACA,mBACC,iCAAc,IAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";wBAyBgB,YACd,cACA,eACA,OACA,mBACC,iCAAc,IAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";wBA0BgB,YACd,cACA,eACA,OACA,mBACC,iCAAc,IAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";wBAyBgB,YACd,cACA,eACA,OACA,mBACC,iCAAc,IAAA"}
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import { track } from "../track/index.mjs";
3
3
  import { useOutboundClickAnalytics } from "../hooks/use-outbound-click-analytics.mjs";
4
- import { integrationScripts } from "../third-parties/integration.mjs";
5
4
  import { uetCustomerIdOf } from "../third-parties/microsoft-uet.mjs";
6
5
  import { useUETIdSync } from "../hooks/use-uet-id-sync.mjs";
7
6
  import { useWebAnalytics } from "../hooks/use-web-analytics.mjs";
@@ -49,7 +48,7 @@ function Analytics({ integrations = [], facebookAppId, nonce, reportWebVitals =
49
48
  property: "fb:app_id",
50
49
  content: facebookAppId
51
50
  }),
52
- integrationScripts(integrations).map((script) => /* @__PURE__ */ jsx(Script, {
51
+ integrations.flatMap(({ script }) => script ? [script] : []).map((script) => /* @__PURE__ */ jsx(Script, {
53
52
  id: script.id,
54
53
  nonce,
55
54
  strategy: script.strategy ?? "afterInteractive",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { integrationScripts } from '../third-parties/integration';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrationScripts(integrations).map((script) => (\n <Script\n key={script.id}\n id={script.id}\n nonce={nonce}\n strategy={script.strategy ?? 'afterInteractive'}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAS,YAAY;CACnB,MAAM,WAAW,YAAY;CAC7B,MAAM,eAAe,gBAAgB;CACrC,gBAAgB,UAAU,aAAa,SAAS,CAAC;CACjD,OAAO;AACT;AAEA,SAAgB,UAAU,EACxB,eAAe,CAAC,GAChB,eACA,OACA,kBAAkB,QACD;CACjB,0BAA0B;CAC1B,aAAa,gBAAgB,YAAY,CAAC;CAC1C,uBAAuB,YAAY;CAEnC,oBAAoB,WAAW;EAC7B,IAAI,CAAC,iBAAiB;EACtB,MAAM,aAAa;GACjB,OAAO,OAAO;GACd,WAAW,OAAO;GAClB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;GACtB,wBAAwB,OAAO;GAC/B,iBAAiB;EACnB;EACA,MAAM,OAAO,MAAM,UAAU;CAC/B,CAAC;CAED,OACE,qBAAA,UAAA,EAAA,UAAA;EACE,oBAAC,UAAD;GAAU,UAAU;GAClB,UAAA,oBAAC,WAAD,CAAY,CAAA;EACJ,CAAA;EACT,iBAAiB,oBAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrE,mBAAmB,YAAY,CAAC,CAAC,KAAK,WACrC,oBAAC,QAAD;GAEE,IAAI,OAAO;GACJ;GACP,UAAU,OAAO,YAAY;GAC7B,yBAAyB,EAAE,QAAQ,OAAO,OAAO;EAClD,GALM,OAAO,EAKb,CACF;CACD,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrations\n .flatMap(({ script }) => (script ? [script] : []))\n .map((script) => (\n <Script\n key={script.id}\n id={script.id}\n nonce={nonce}\n strategy={script.strategy ?? 'afterInteractive'}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAS,YAAY;CACnB,MAAM,WAAW,YAAY;CAC7B,MAAM,eAAe,gBAAgB;CACrC,gBAAgB,UAAU,aAAa,SAAS,CAAC;CACjD,OAAO;AACT;AAEA,SAAgB,UAAU,EACxB,eAAe,CAAC,GAChB,eACA,OACA,kBAAkB,QACD;CACjB,0BAA0B;CAC1B,aAAa,gBAAgB,YAAY,CAAC;CAC1C,uBAAuB,YAAY;CAEnC,oBAAoB,WAAW;EAC7B,IAAI,CAAC,iBAAiB;EACtB,MAAM,aAAa;GACjB,OAAO,OAAO;GACd,WAAW,OAAO;GAClB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;GACtB,wBAAwB,OAAO;GAC/B,iBAAiB;EACnB;EACA,MAAM,OAAO,MAAM,UAAU;CAC/B,CAAC;CAED,OACE,qBAAA,UAAA,EAAA,UAAA;EACE,oBAAC,UAAD;GAAU,UAAU;GAClB,UAAA,oBAAC,WAAD,CAAY,CAAA;EACJ,CAAA;EACT,iBAAiB,oBAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrE,aACE,SAAS,EAAE,aAAc,SAAS,CAAC,MAAM,IAAI,CAAC,CAAE,CAAC,CACjD,KAAK,WACJ,oBAAC,QAAD;GAEE,IAAI,OAAO;GACJ;GACP,UAAU,OAAO,YAAY;GAC7B,yBAAyB,EAAE,QAAQ,OAAO,OAAO;EAClD,GALM,OAAO,EAKb,CACF;CACH,EAAA,CAAA;AAEN"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_third_parties_integration = require("./integration.cjs");
3
2
  let react_dom = require("react-dom");
4
3
  let react_jsx_runtime = require("react/jsx-runtime");
5
4
  // src/third-parties/analytics-props.tsx
@@ -17,7 +16,7 @@ function preconnectIntegrations(integrations = []) {
17
16
  * they are (react).
18
17
  */
19
18
  function IntegrationScripts({ integrations = [], nonce }) {
20
- return require_third_parties_integration.integrationScripts(integrations).map((script) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
19
+ return integrations.flatMap(({ script }) => script ? [script] : []).map((script) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
21
20
  id: script.id,
22
21
  nonce,
23
22
  dangerouslySetInnerHTML: { __html: script.inline }
@@ -1 +1 @@
1
- {"version":3,"file":"analytics-props.cjs","names":["preconnect","integrationScripts"],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport { type Integration, integrationScripts } from './integration';\n\n/** The props every framework's `<Analytics>` takes (react, next). */\nexport interface AnalyticsProps {\n /** The integrations passed to `setupAnalytics`, whose scripts this renders. */\n integrations?: readonly Integration[];\n /** Renders `<meta property=\"fb:app_id\">`, for Facebook's sharing insights. */\n facebookAppId?: string;\n /** The request's CSP nonce, set on every script rendered. */\n nonce?: string;\n /** Reports Core Web Vitals as events (on by default). */\n reportWebVitals?: boolean;\n}\n\n/**\n * Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes\n * the hints and, on the server, puts them at the top of `<head>`.\n */\nexport function preconnectIntegrations(integrations: readonly Integration[] = []) {\n integrations.forEach((integration) => {\n integration.preconnect?.forEach((origin) => preconnect(origin, { crossOrigin: 'anonymous' }));\n });\n}\n\n/**\n * The integrations' scripts as plain `<script>` elements, for the frameworks that render them as\n * they are (react).\n */\nexport function IntegrationScripts({\n integrations = [],\n nonce,\n}: Pick<AnalyticsProps, 'integrations' | 'nonce'>) {\n return integrationScripts(integrations).map((script) => (\n <script\n key={script.id}\n id={script.id}\n nonce={nonce}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ));\n}\n"],"mappings":";;;;;;;;;AAmBA,SAAgB,uBAAuB,eAAuC,CAAC,GAAG;CAChF,aAAa,SAAS,gBAAgB;EACpC,YAAY,YAAY,SAAS,YAAA,GAAWA,UAAAA,WAAAA,CAAW,QAAQ,EAAE,aAAa,YAAY,CAAC,CAAC;CAC9F,CAAC;AACH;;;;;AAMA,SAAgB,mBAAmB,EACjC,eAAe,CAAC,GAChB,SACiD;CACjD,OAAOC,kCAAAA,mBAAmB,YAAY,CAAC,CAAC,KAAK,WAC3C,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;EAEE,IAAI,OAAO;EACJ;EACP,yBAAyB,EAAE,QAAQ,OAAO,OAAO;CAClD,GAJM,OAAO,EAIb,CACF;AACH"}
1
+ {"version":3,"file":"analytics-props.cjs","names":["preconnect"],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport type { Integration } from './integration';\n\n/** The props every framework's `<Analytics>` takes (react, next). */\nexport interface AnalyticsProps {\n /** The integrations passed to `setupAnalytics`, whose scripts this renders. */\n integrations?: readonly Integration[];\n /** Renders `<meta property=\"fb:app_id\">`, for Facebook's sharing insights. */\n facebookAppId?: string;\n /** The request's CSP nonce, set on every script rendered. */\n nonce?: string;\n /** Reports Core Web Vitals as events (on by default). */\n reportWebVitals?: boolean;\n}\n\n/**\n * Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes\n * the hints and, on the server, puts them at the top of `<head>`.\n */\nexport function preconnectIntegrations(integrations: readonly Integration[] = []) {\n integrations.forEach((integration) => {\n integration.preconnect?.forEach((origin) => preconnect(origin, { crossOrigin: 'anonymous' }));\n });\n}\n\n/**\n * The integrations' scripts as plain `<script>` elements, for the frameworks that render them as\n * they are (react).\n */\nexport function IntegrationScripts({\n integrations = [],\n nonce,\n}: Pick<AnalyticsProps, 'integrations' | 'nonce'>) {\n return integrations\n .flatMap(({ script }) => (script ? [script] : []))\n .map((script) => (\n <script\n key={script.id}\n id={script.id}\n nonce={nonce}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ));\n}\n"],"mappings":";;;;;;;;AAmBA,SAAgB,uBAAuB,eAAuC,CAAC,GAAG;CAChF,aAAa,SAAS,gBAAgB;EACpC,YAAY,YAAY,SAAS,YAAA,GAAWA,UAAAA,WAAAA,CAAW,QAAQ,EAAE,aAAa,YAAY,CAAC,CAAC;CAC9F,CAAC;AACH;;;;;AAMA,SAAgB,mBAAmB,EACjC,eAAe,CAAC,GAChB,SACiD;CACjD,OAAO,aACJ,SAAS,EAAE,aAAc,SAAS,CAAC,MAAM,IAAI,CAAC,CAAE,CAAC,CACjD,KAAK,WACJ,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;EAEE,IAAI,OAAO;EACJ;EACP,yBAAyB,EAAE,QAAQ,OAAO,OAAO;CAClD,GAJM,OAAO,EAIb,CACF;AACL"}
@@ -1,4 +1,3 @@
1
- import { integrationScripts } from "./integration.mjs";
2
1
  import { preconnect } from "react-dom";
3
2
  import { jsx } from "react/jsx-runtime";
4
3
  // src/third-parties/analytics-props.tsx
@@ -16,7 +15,7 @@ function preconnectIntegrations(integrations = []) {
16
15
  * they are (react).
17
16
  */
18
17
  function IntegrationScripts({ integrations = [], nonce }) {
19
- return integrationScripts(integrations).map((script) => /* @__PURE__ */ jsx("script", {
18
+ return integrations.flatMap(({ script }) => script ? [script] : []).map((script) => /* @__PURE__ */ jsx("script", {
20
19
  id: script.id,
21
20
  nonce,
22
21
  dangerouslySetInnerHTML: { __html: script.inline }
@@ -1 +1 @@
1
- {"version":3,"file":"analytics-props.mjs","names":[],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport { type Integration, integrationScripts } from './integration';\n\n/** The props every framework's `<Analytics>` takes (react, next). */\nexport interface AnalyticsProps {\n /** The integrations passed to `setupAnalytics`, whose scripts this renders. */\n integrations?: readonly Integration[];\n /** Renders `<meta property=\"fb:app_id\">`, for Facebook's sharing insights. */\n facebookAppId?: string;\n /** The request's CSP nonce, set on every script rendered. */\n nonce?: string;\n /** Reports Core Web Vitals as events (on by default). */\n reportWebVitals?: boolean;\n}\n\n/**\n * Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes\n * the hints and, on the server, puts them at the top of `<head>`.\n */\nexport function preconnectIntegrations(integrations: readonly Integration[] = []) {\n integrations.forEach((integration) => {\n integration.preconnect?.forEach((origin) => preconnect(origin, { crossOrigin: 'anonymous' }));\n });\n}\n\n/**\n * The integrations' scripts as plain `<script>` elements, for the frameworks that render them as\n * they are (react).\n */\nexport function IntegrationScripts({\n integrations = [],\n nonce,\n}: Pick<AnalyticsProps, 'integrations' | 'nonce'>) {\n return integrationScripts(integrations).map((script) => (\n <script\n key={script.id}\n id={script.id}\n nonce={nonce}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ));\n}\n"],"mappings":";;;;;;;;AAmBA,SAAgB,uBAAuB,eAAuC,CAAC,GAAG;CAChF,aAAa,SAAS,gBAAgB;EACpC,YAAY,YAAY,SAAS,WAAW,WAAW,QAAQ,EAAE,aAAa,YAAY,CAAC,CAAC;CAC9F,CAAC;AACH;;;;;AAMA,SAAgB,mBAAmB,EACjC,eAAe,CAAC,GAChB,SACiD;CACjD,OAAO,mBAAmB,YAAY,CAAC,CAAC,KAAK,WAC3C,oBAAC,UAAD;EAEE,IAAI,OAAO;EACJ;EACP,yBAAyB,EAAE,QAAQ,OAAO,OAAO;CAClD,GAJM,OAAO,EAIb,CACF;AACH"}
1
+ {"version":3,"file":"analytics-props.mjs","names":[],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport type { Integration } from './integration';\n\n/** The props every framework's `<Analytics>` takes (react, next). */\nexport interface AnalyticsProps {\n /** The integrations passed to `setupAnalytics`, whose scripts this renders. */\n integrations?: readonly Integration[];\n /** Renders `<meta property=\"fb:app_id\">`, for Facebook's sharing insights. */\n facebookAppId?: string;\n /** The request's CSP nonce, set on every script rendered. */\n nonce?: string;\n /** Reports Core Web Vitals as events (on by default). */\n reportWebVitals?: boolean;\n}\n\n/**\n * Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes\n * the hints and, on the server, puts them at the top of `<head>`.\n */\nexport function preconnectIntegrations(integrations: readonly Integration[] = []) {\n integrations.forEach((integration) => {\n integration.preconnect?.forEach((origin) => preconnect(origin, { crossOrigin: 'anonymous' }));\n });\n}\n\n/**\n * The integrations' scripts as plain `<script>` elements, for the frameworks that render them as\n * they are (react).\n */\nexport function IntegrationScripts({\n integrations = [],\n nonce,\n}: Pick<AnalyticsProps, 'integrations' | 'nonce'>) {\n return integrations\n .flatMap(({ script }) => (script ? [script] : []))\n .map((script) => (\n <script\n key={script.id}\n id={script.id}\n nonce={nonce}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ));\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,uBAAuB,eAAuC,CAAC,GAAG;CAChF,aAAa,SAAS,gBAAgB;EACpC,YAAY,YAAY,SAAS,WAAW,WAAW,QAAQ,EAAE,aAAa,YAAY,CAAC,CAAC;CAC9F,CAAC;AACH;;;;;AAMA,SAAgB,mBAAmB,EACjC,eAAe,CAAC,GAChB,SACiD;CACjD,OAAO,aACJ,SAAS,EAAE,aAAc,SAAS,CAAC,MAAM,IAAI,CAAC,CAAE,CAAC,CACjD,KAAK,WACJ,oBAAC,UAAD;EAEE,IAAI,OAAO;EACJ;EACP,yBAAyB,EAAE,QAAQ,OAAO,OAAO;CAClD,GAJM,OAAO,EAIb,CACF;AACL"}
@@ -2,33 +2,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  // src/third-parties/integration.ts
3
3
  /**
4
4
  * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
5
- * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
6
- * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
5
+ * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. The
6
+ * senders skip such a page; the vendors' snippets (`fbq('track', 'PageView')` and the like) still
7
+ * run there, as the host rendered them — a host that wants none of it leaves the `ads`
8
+ * integrations out of `integrations` locally.
7
9
  */
8
- const LOCAL_HOST_PATTERN = String.raw`(^|\.)localhost(:|$)|^127\.0\.0\.1(:|$)`;
9
- const LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);
10
- /** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
10
+ const LOCAL_HOST = /(^|\.)localhost(:|$)|^127\.0\.0\.1(:|$)/;
11
+ /** Whether the page is served from a development host (see `LOCAL_HOST`). */
11
12
  function isLocalHost(host = window.location.host) {
12
13
  return LOCAL_HOST.test(host);
13
14
  }
14
15
  /**
15
- * The script an ad platform's integration puts on the page, silenced on a development host.
16
- * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
17
- * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
18
- * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
19
- * guard is in the snippet itself: the renderer has no request host on the server.
20
- */
21
- function integrationScripts(integrations) {
22
- return integrations.flatMap(({ type, script }) => {
23
- if (!script) return [];
24
- if (type !== "ads") return [script];
25
- return [{
26
- ...script,
27
- inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`
28
- }];
29
- });
30
- }
31
- /**
32
16
  * The GA4 recommended events that are conversions or close to one, for an ad platform with no
33
17
  * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
34
18
  */
@@ -68,10 +52,8 @@ function adsTracker(send, accepts) {
68
52
  };
69
53
  }
70
54
  exports.CONVERSION_EVENTS = CONVERSION_EVENTS;
71
- exports.LOCAL_HOST_PATTERN = LOCAL_HOST_PATTERN;
72
55
  exports.adEvents = adEvents;
73
56
  exports.adsTracker = adsTracker;
74
- exports.integrationScripts = integrationScripts;
75
57
  exports.isLocalHost = isLocalHost;
76
58
 
77
59
  //# sourceMappingURL=integration.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"integration.cjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under\n * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One\n * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.\n */\nexport const LOCAL_HOST_PATTERN = String.raw`(^|\\.)localhost(:|$)|^127\\.0\\.0\\.1(:|$)`;\nconst LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);\n\n/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */\nexport function isLocalHost(host: string = window.location.host): boolean {\n return LOCAL_HOST.test(host);\n}\n\n/**\n * The script an ad platform's integration puts on the page, silenced on a development host.\n * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,\n * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so\n * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The\n * guard is in the snippet itself: the renderer has no request host on the server.\n */\nexport function integrationScripts(integrations: readonly Integration[]): IntegrationScript[] {\n return integrations.flatMap(({ type, script }) => {\n if (!script) return [];\n if (type !== 'ads') return [script];\n return [\n {\n ...script,\n inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`,\n },\n ];\n });\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":";;;;;;;AAgDA,MAAa,qBAAqB,OAAO,GAAG;AAC5C,MAAM,aAAa,IAAI,OAAO,kBAAkB;;AAGhD,SAAgB,YAAY,OAAe,OAAO,SAAS,MAAe;CACxE,OAAO,WAAW,KAAK,IAAI;AAC7B;;;;;;;;AASA,SAAgB,mBAAmB,cAA2D;CAC5F,OAAO,aAAa,SAAS,EAAE,MAAM,aAAa;EAChD,IAAI,CAAC,QAAQ,OAAO,CAAC;EACrB,IAAI,SAAS,OAAO,OAAO,CAAC,MAAM;EAClC,OAAO,CACL;GACE,GAAG;GACH,QAAQ,SAAS,mBAAmB,iCAAiC,OAAO,OAAO;EACrF,CACF;CACF,CAAC;AACH;;;;;AAMA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAmBA,SAAgB,SACd,YACA,eAAkC,CAAC,GACR;CAC3B,QAAQ,SAAS,WAAW,IAAI,KAAK,aAAa,SAAS,IAAI;AACjE;;AAGA,SAAgB,WACd,MACA,SACmB;CACnB,QAAQ,MAAM,YAAY,YAAY;EACpC,IAAI,CAAC,QAAQ,IAAI,GAAG;EACpB,OAAO,KAAK,MAAM,YAAY,OAAO;CACvC;AACF"}
1
+ {"version":3,"file":"integration.cjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under\n * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. The\n * senders skip such a page; the vendors' snippets (`fbq('track', 'PageView')` and the like) still\n * run there, as the host rendered them — a host that wants none of it leaves the `ads`\n * integrations out of `integrations` locally.\n */\nconst LOCAL_HOST = /(^|\\.)localhost(:|$)|^127\\.0\\.0\\.1(:|$)/;\n\n/** Whether the page is served from a development host (see `LOCAL_HOST`). */\nexport function isLocalHost(host: string = window.location.host): boolean {\n return LOCAL_HOST.test(host);\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":";;;;;;;;;AAkDA,MAAM,aAAa;;AAGnB,SAAgB,YAAY,OAAe,OAAO,SAAS,MAAe;CACxE,OAAO,WAAW,KAAK,IAAI;AAC7B;;;;;AAMA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAmBA,SAAgB,SACd,YACA,eAAkC,CAAC,GACR;CAC3B,QAAQ,SAAS,WAAW,IAAI,KAAK,aAAa,SAAS,IAAI;AACjE;;AAGA,SAAgB,WACd,MACA,SACmB;CACnB,QAAQ,MAAM,YAAY,YAAY;EACpC,IAAI,CAAC,QAAQ,IAAI,GAAG;EACpB,OAAO,KAAK,MAAM,YAAY,OAAO;CACvC;AACF"}
@@ -38,22 +38,8 @@ export interface Integration {
38
38
  */
39
39
  readonly preconnect?: readonly string[];
40
40
  }
41
- /**
42
- * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
43
- * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
44
- * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
45
- */
46
- export declare const LOCAL_HOST_PATTERN: string;
47
- /** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
41
+ /** Whether the page is served from a development host (see `LOCAL_HOST`). */
48
42
  export declare function isLocalHost(host?: string): boolean;
49
- /**
50
- * The script an ad platform's integration puts on the page, silenced on a development host.
51
- * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
52
- * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
53
- * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
54
- * guard is in the snippet itself: the renderer has no request host on the server.
55
- */
56
- export declare function integrationScripts(integrations: readonly Integration[]): IntegrationScript[];
57
43
  /**
58
44
  * The GA4 recommended events that are conversions or close to one, for an ad platform with no
59
45
  * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
@@ -1 +1 @@
1
- {"version":3,"file":"integration.d.cts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT;;;;;;;qBAQE;;wBAIG,YAAY;;;;;;;;wBAWZ,mBAAmB,uBAAuB,gBAAgB;;;;;qBAiB7D;iBAkBI;;;;;;EAMf,wBAAwB;;;;;;;;;;wBAWV,SACd,aAAa,0BACb,oCACE;;wBAKY,WACd,MAAM,mBACN,UAAU,2BACT"}
1
+ {"version":3,"file":"integration.d.cts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT;;;wBAaK,YAAY;;;;;qBAQf;iBAkBI;;;;;;EAMf,wBAAwB;;;;;;;;;;wBAWV,SACd,aAAa,0BACb,oCACE;;wBAKY,WACd,MAAM,mBACN,UAAU,2BACT"}
@@ -38,22 +38,8 @@ export interface Integration {
38
38
  */
39
39
  readonly preconnect?: readonly string[];
40
40
  }
41
- /**
42
- * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
43
- * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
44
- * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
45
- */
46
- export declare const LOCAL_HOST_PATTERN: string;
47
- /** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
41
+ /** Whether the page is served from a development host (see `LOCAL_HOST`). */
48
42
  export declare function isLocalHost(host?: string): boolean;
49
- /**
50
- * The script an ad platform's integration puts on the page, silenced on a development host.
51
- * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
52
- * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
53
- * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
54
- * guard is in the snippet itself: the renderer has no request host on the server.
55
- */
56
- export declare function integrationScripts(integrations: readonly Integration[]): IntegrationScript[];
57
43
  /**
58
44
  * The GA4 recommended events that are conversions or close to one, for an ad platform with no
59
45
  * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
@@ -1 +1 @@
1
- {"version":3,"file":"integration.d.mts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT;;;;;;;qBAQE;;wBAIG,YAAY;;;;;;;;wBAWZ,mBAAmB,uBAAuB,gBAAgB;;;;;qBAiB7D;iBAkBI;;;;;;EAMf,wBAAwB;;;;;;;;;;wBAWV,SACd,aAAa,0BACb,oCACE;;wBAKY,WACd,MAAM,mBACN,UAAU,2BACT"}
1
+ {"version":3,"file":"integration.d.mts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT;;;wBAaK,YAAY;;;;;qBAQf;iBAkBI;;;;;;EAMf,wBAAwB;;;;;;;;;;wBAWV,SACd,aAAa,0BACb,oCACE;;wBAKY,WACd,MAAM,mBACN,UAAU,2BACT"}
@@ -1,33 +1,17 @@
1
1
  // src/third-parties/integration.ts
2
2
  /**
3
3
  * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
4
- * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
5
- * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
4
+ * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. The
5
+ * senders skip such a page; the vendors' snippets (`fbq('track', 'PageView')` and the like) still
6
+ * run there, as the host rendered them — a host that wants none of it leaves the `ads`
7
+ * integrations out of `integrations` locally.
6
8
  */
7
- const LOCAL_HOST_PATTERN = String.raw`(^|\.)localhost(:|$)|^127\.0\.0\.1(:|$)`;
8
- const LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);
9
- /** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
9
+ const LOCAL_HOST = /(^|\.)localhost(:|$)|^127\.0\.0\.1(:|$)/;
10
+ /** Whether the page is served from a development host (see `LOCAL_HOST`). */
10
11
  function isLocalHost(host = window.location.host) {
11
12
  return LOCAL_HOST.test(host);
12
13
  }
13
14
  /**
14
- * The script an ad platform's integration puts on the page, silenced on a development host.
15
- * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
16
- * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
17
- * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
18
- * guard is in the snippet itself: the renderer has no request host on the server.
19
- */
20
- function integrationScripts(integrations) {
21
- return integrations.flatMap(({ type, script }) => {
22
- if (!script) return [];
23
- if (type !== "ads") return [script];
24
- return [{
25
- ...script,
26
- inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`
27
- }];
28
- });
29
- }
30
- /**
31
15
  * The GA4 recommended events that are conversions or close to one, for an ad platform with no
32
16
  * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
33
17
  */
@@ -66,6 +50,6 @@ function adsTracker(send, accepts) {
66
50
  return send(name, properties, eventId);
67
51
  };
68
52
  }
69
- export { CONVERSION_EVENTS, LOCAL_HOST_PATTERN, adEvents, adsTracker, integrationScripts, isLocalHost };
53
+ export { CONVERSION_EVENTS, adEvents, adsTracker, isLocalHost };
70
54
 
71
55
  //# sourceMappingURL=integration.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"integration.mjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under\n * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One\n * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.\n */\nexport const LOCAL_HOST_PATTERN = String.raw`(^|\\.)localhost(:|$)|^127\\.0\\.0\\.1(:|$)`;\nconst LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);\n\n/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */\nexport function isLocalHost(host: string = window.location.host): boolean {\n return LOCAL_HOST.test(host);\n}\n\n/**\n * The script an ad platform's integration puts on the page, silenced on a development host.\n * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,\n * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so\n * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The\n * guard is in the snippet itself: the renderer has no request host on the server.\n */\nexport function integrationScripts(integrations: readonly Integration[]): IntegrationScript[] {\n return integrations.flatMap(({ type, script }) => {\n if (!script) return [];\n if (type !== 'ads') return [script];\n return [\n {\n ...script,\n inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`,\n },\n ];\n });\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":";;;;;;AAgDA,MAAa,qBAAqB,OAAO,GAAG;AAC5C,MAAM,aAAa,IAAI,OAAO,kBAAkB;;AAGhD,SAAgB,YAAY,OAAe,OAAO,SAAS,MAAe;CACxE,OAAO,WAAW,KAAK,IAAI;AAC7B;;;;;;;;AASA,SAAgB,mBAAmB,cAA2D;CAC5F,OAAO,aAAa,SAAS,EAAE,MAAM,aAAa;EAChD,IAAI,CAAC,QAAQ,OAAO,CAAC;EACrB,IAAI,SAAS,OAAO,OAAO,CAAC,MAAM;EAClC,OAAO,CACL;GACE,GAAG;GACH,QAAQ,SAAS,mBAAmB,iCAAiC,OAAO,OAAO;EACrF,CACF;CACF,CAAC;AACH;;;;;AAMA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAmBA,SAAgB,SACd,YACA,eAAkC,CAAC,GACR;CAC3B,QAAQ,SAAS,WAAW,IAAI,KAAK,aAAa,SAAS,IAAI;AACjE;;AAGA,SAAgB,WACd,MACA,SACmB;CACnB,QAAQ,MAAM,YAAY,YAAY;EACpC,IAAI,CAAC,QAAQ,IAAI,GAAG;EACpB,OAAO,KAAK,MAAM,YAAY,OAAO;CACvC;AACF"}
1
+ {"version":3,"file":"integration.mjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under\n * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. The\n * senders skip such a page; the vendors' snippets (`fbq('track', 'PageView')` and the like) still\n * run there, as the host rendered them — a host that wants none of it leaves the `ads`\n * integrations out of `integrations` locally.\n */\nconst LOCAL_HOST = /(^|\\.)localhost(:|$)|^127\\.0\\.0\\.1(:|$)/;\n\n/** Whether the page is served from a development host (see `LOCAL_HOST`). */\nexport function isLocalHost(host: string = window.location.host): boolean {\n return LOCAL_HOST.test(host);\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":";;;;;;;;AAkDA,MAAM,aAAa;;AAGnB,SAAgB,YAAY,OAAe,OAAO,SAAS,MAAe;CACxE,OAAO,WAAW,KAAK,IAAI;AAC7B;;;;;AAMA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAmBA,SAAgB,SACd,YACA,eAAkC,CAAC,GACR;CAC3B,QAAQ,SAAS,WAAW,IAAI,KAAK,aAAa,SAAS,IAAI;AACjE;;AAGA,SAAgB,WACd,MACA,SACmB;CACnB,QAAQ,MAAM,YAAY,YAAY;EACpC,IAAI,CAAC,QAAQ,IAAI,GAAG;EACpB,OAAO,KAAK,MAAM,YAAY,OAAO;CACvC;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "16.3.5",
3
+ "version": "16.3.6",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",