@shware/analytics 15.0.1 → 16.0.0
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.
- package/README.md +89 -36
- package/dist/native/fbsdk.cjs +45 -1
- package/dist/native/fbsdk.cjs.map +1 -1
- package/dist/native/fbsdk.d.cts +23 -1
- package/dist/native/fbsdk.d.cts.map +1 -1
- package/dist/native/fbsdk.d.mts +23 -1
- package/dist/native/fbsdk.d.mts.map +1 -1
- package/dist/native/fbsdk.mjs +44 -2
- package/dist/native/fbsdk.mjs.map +1 -1
- package/dist/native/firebase.cjs +27 -0
- package/dist/native/firebase.cjs.map +1 -1
- package/dist/native/firebase.d.cts +11 -0
- package/dist/native/firebase.d.cts.map +1 -1
- package/dist/native/firebase.d.mts +11 -0
- package/dist/native/firebase.d.mts.map +1 -1
- package/dist/native/firebase.mjs +27 -2
- package/dist/native/firebase.mjs.map +1 -1
- package/dist/next/index.cjs +10 -123
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +2 -31
- package/dist/next/index.d.cts.map +1 -1
- package/dist/next/index.d.mts +2 -31
- package/dist/next/index.d.mts.map +1 -1
- package/dist/next/index.mjs +10 -123
- package/dist/next/index.mjs.map +1 -1
- package/dist/react/index.cjs +45 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +15 -0
- package/dist/react/index.d.cts.map +1 -0
- package/dist/react/index.d.mts +15 -0
- package/dist/react/index.d.mts.map +1 -0
- package/dist/react/index.mjs +43 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/react/use-feature-flag.cjs +23 -0
- package/dist/react/use-feature-flag.cjs.map +1 -0
- package/dist/react/use-feature-flag.d.cts +10 -0
- package/dist/react/use-feature-flag.d.cts.map +1 -0
- package/dist/react/use-feature-flag.d.mts +10 -0
- package/dist/react/use-feature-flag.d.mts.map +1 -0
- package/dist/react/use-feature-flag.mjs +22 -0
- package/dist/react/use-feature-flag.mjs.map +1 -0
- package/dist/server/reddit-conversions-api.d.cts +1 -1
- package/dist/server/reddit-conversions-api.d.mts +1 -1
- package/dist/setup/index.cjs +4 -4
- package/dist/setup/index.cjs.map +1 -1
- package/dist/setup/index.d.cts +16 -6
- package/dist/setup/index.d.cts.map +1 -1
- package/dist/setup/index.d.mts +16 -6
- package/dist/setup/index.d.mts.map +1 -1
- package/dist/setup/index.mjs +4 -4
- package/dist/setup/index.mjs.map +1 -1
- package/dist/tanstack/index.cjs +0 -2
- package/dist/tanstack/index.d.cts +1 -2
- package/dist/tanstack/index.d.mts +1 -2
- package/dist/tanstack/index.mjs +1 -3
- package/dist/third-parties/analytics-props.cjs +28 -0
- package/dist/third-parties/analytics-props.cjs.map +1 -0
- package/dist/third-parties/analytics-props.d.cts +23 -0
- package/dist/third-parties/analytics-props.d.cts.map +1 -0
- package/dist/third-parties/analytics-props.d.mts +23 -0
- package/dist/third-parties/analytics-props.d.mts.map +1 -0
- package/dist/third-parties/analytics-props.mjs +26 -0
- package/dist/third-parties/analytics-props.mjs.map +1 -0
- package/dist/third-parties/google-analytics.cjs +32 -0
- package/dist/third-parties/google-analytics.cjs.map +1 -1
- package/dist/third-parties/google-analytics.d.cts +11 -1
- package/dist/third-parties/google-analytics.d.cts.map +1 -1
- package/dist/third-parties/google-analytics.d.mts +11 -1
- package/dist/third-parties/google-analytics.d.mts.map +1 -1
- package/dist/third-parties/google-analytics.mjs +32 -1
- package/dist/third-parties/google-analytics.mjs.map +1 -1
- package/dist/third-parties/index.cjs +16 -0
- package/dist/third-parties/index.d.cts +9 -7
- package/dist/third-parties/index.d.mts +9 -7
- package/dist/third-parties/index.mjs +9 -7
- package/dist/third-parties/integration.cjs +39 -0
- package/dist/third-parties/integration.cjs.map +1 -0
- package/dist/third-parties/integration.d.cts +57 -0
- package/dist/third-parties/integration.d.cts.map +1 -0
- package/dist/third-parties/integration.d.mts +57 -0
- package/dist/third-parties/integration.d.mts.map +1 -0
- package/dist/third-parties/integration.mjs +37 -0
- package/dist/third-parties/integration.mjs.map +1 -0
- package/dist/third-parties/linkedin-insight-tag.cjs +33 -0
- package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.cts +12 -8
- package/dist/third-parties/linkedin-insight-tag.d.cts.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.mts +12 -8
- package/dist/third-parties/linkedin-insight-tag.d.mts.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.mjs +33 -1
- package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -1
- package/dist/third-parties/meta-pixel.cjs +34 -0
- package/dist/third-parties/meta-pixel.cjs.map +1 -1
- package/dist/third-parties/meta-pixel.d.cts +5 -0
- package/dist/third-parties/meta-pixel.d.cts.map +1 -1
- package/dist/third-parties/meta-pixel.d.mts +5 -0
- package/dist/third-parties/meta-pixel.d.mts.map +1 -1
- package/dist/third-parties/meta-pixel.mjs +34 -1
- package/dist/third-parties/meta-pixel.mjs.map +1 -1
- package/dist/third-parties/microsoft-uet.cjs +49 -0
- package/dist/third-parties/microsoft-uet.cjs.map +1 -1
- package/dist/third-parties/microsoft-uet.d.cts +29 -0
- package/dist/third-parties/microsoft-uet.d.cts.map +1 -1
- package/dist/third-parties/microsoft-uet.d.mts +29 -0
- package/dist/third-parties/microsoft-uet.d.mts.map +1 -1
- package/dist/third-parties/microsoft-uet.mjs +48 -1
- package/dist/third-parties/microsoft-uet.mjs.map +1 -1
- package/dist/third-parties/openai-pixel.cjs +31 -0
- package/dist/third-parties/openai-pixel.cjs.map +1 -1
- package/dist/third-parties/openai-pixel.d.cts +5 -0
- package/dist/third-parties/openai-pixel.d.cts.map +1 -1
- package/dist/third-parties/openai-pixel.d.mts +5 -0
- package/dist/third-parties/openai-pixel.d.mts.map +1 -1
- package/dist/third-parties/openai-pixel.mjs +31 -1
- package/dist/third-parties/openai-pixel.mjs.map +1 -1
- package/dist/third-parties/posthog.cjs +97 -4
- package/dist/third-parties/posthog.cjs.map +1 -1
- package/dist/third-parties/posthog.d.cts +56 -1
- package/dist/third-parties/posthog.d.cts.map +1 -1
- package/dist/third-parties/posthog.d.mts +56 -1
- package/dist/third-parties/posthog.d.mts.map +1 -1
- package/dist/third-parties/posthog.mjs +91 -2
- package/dist/third-parties/posthog.mjs.map +1 -1
- package/dist/third-parties/reddit-pixel.cjs +32 -0
- package/dist/third-parties/reddit-pixel.cjs.map +1 -1
- package/dist/third-parties/reddit-pixel.d.cts +5 -0
- package/dist/third-parties/reddit-pixel.d.cts.map +1 -1
- package/dist/third-parties/reddit-pixel.d.mts +5 -0
- package/dist/third-parties/reddit-pixel.d.mts.map +1 -1
- package/dist/third-parties/reddit-pixel.mjs +32 -1
- package/dist/third-parties/reddit-pixel.mjs.map +1 -1
- package/dist/track/fbq.cjs +1 -1
- package/dist/track/fbq.cjs.map +1 -1
- package/dist/track/fbq.mjs +1 -1
- package/dist/track/fbq.mjs.map +1 -1
- package/dist/track/index.cjs +7 -7
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.d.cts.map +1 -1
- package/dist/track/index.d.mts.map +1 -1
- package/dist/track/index.mjs +7 -7
- package/dist/track/index.mjs.map +1 -1
- package/dist/visitor/index.cjs +3 -3
- package/dist/visitor/index.cjs.map +1 -1
- package/dist/visitor/index.mjs +3 -3
- package/dist/visitor/index.mjs.map +1 -1
- package/package.json +11 -24
- package/dist/react-router/index.cjs +0 -160
- package/dist/react-router/index.cjs.map +0 -1
- package/dist/react-router/index.d.cts +0 -22
- package/dist/react-router/index.d.cts.map +0 -1
- package/dist/react-router/index.d.mts +0 -22
- package/dist/react-router/index.d.mts.map +0 -1
- package/dist/react-router/index.mjs +0 -159
- package/dist/react-router/index.mjs.map +0 -1
- package/dist/tanstack/analytics.cjs +0 -184
- package/dist/tanstack/analytics.cjs.map +0 -1
- package/dist/tanstack/analytics.d.cts +0 -33
- package/dist/tanstack/analytics.d.cts.map +0 -1
- package/dist/tanstack/analytics.d.mts +0 -33
- package/dist/tanstack/analytics.d.mts.map +0 -1
- package/dist/tanstack/analytics.mjs +0 -183
- package/dist/tanstack/analytics.mjs.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_third_parties_posthog = require("../third-parties/posthog.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
// src/react/use-feature-flag.ts
|
|
5
|
+
const noop = () => {};
|
|
6
|
+
/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */
|
|
7
|
+
function subscribe(onChange) {
|
|
8
|
+
return require_third_parties_posthog.getPosthog()?.onFeatureFlags(onChange) ?? noop;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
12
|
+
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
13
|
+
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
14
|
+
*
|
|
15
|
+
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
16
|
+
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
17
|
+
*/
|
|
18
|
+
function useFeatureFlag(key) {
|
|
19
|
+
return (0, react.useSyncExternalStore)(subscribe, () => require_third_parties_posthog.getLoadedPosthog()?.getFeatureFlag(key), () => void 0);
|
|
20
|
+
}
|
|
21
|
+
exports.useFeatureFlag = useFeatureFlag;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=use-feature-flag.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-feature-flag.cjs","names":["getPosthog","useSyncExternalStore","getLoadedPosthog"],"sources":["../../src/react/use-feature-flag.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport { getLoadedPosthog, getPosthog } from '../third-parties/posthog';\n\nconst noop = () => {};\n\n/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */\nfunction subscribe(onChange: () => void): () => void {\n const unsubscribe: (() => void) | undefined = getPosthog()?.onFeatureFlags(onChange);\n return unsubscribe ?? noop;\n}\n\n/**\n * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`\n * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).\n * `undefined` on the server and through hydration, so the server markup always matches.\n *\n * Renders the default first and the variant once flags arrive. To wait for them instead, call\n * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.\n */\nexport function useFeatureFlag(key: string): string | boolean | undefined {\n return useSyncExternalStore(\n subscribe,\n () => getLoadedPosthog()?.getFeatureFlag(key),\n () => undefined\n );\n}\n"],"mappings":";;;;AAGA,MAAM,aAAa,CAAC;;AAGpB,SAAS,UAAU,UAAkC;CAEnD,OAD8CA,8BAAAA,WAAW,CAAC,EAAE,eAAe,QAAQ,KAC7D;AACxB;;;;;;;;;AAUA,SAAgB,eAAe,KAA2C;CACxE,QAAA,GAAOC,MAAAA,qBAAAA,CACL,iBACMC,8BAAAA,iBAAiB,CAAC,EAAE,eAAe,GAAG,SACtC,KAAA,CACR;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
3
|
+
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
4
|
+
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
5
|
+
*
|
|
6
|
+
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
7
|
+
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useFeatureFlag(key: string): string | boolean | undefined;
|
|
10
|
+
//# sourceMappingURL=use-feature-flag.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-feature-flag.d.cts","names":[],"sources":["../../src/react/use-feature-flag.ts"],"mappings":";;;;;;;;wBAmBgB,eAAe"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
3
|
+
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
4
|
+
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
5
|
+
*
|
|
6
|
+
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
7
|
+
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useFeatureFlag(key: string): string | boolean | undefined;
|
|
10
|
+
//# sourceMappingURL=use-feature-flag.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-feature-flag.d.mts","names":[],"sources":["../../src/react/use-feature-flag.ts"],"mappings":";;;;;;;;wBAmBgB,eAAe"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getLoadedPosthog, getPosthog } from "../third-parties/posthog.mjs";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
// src/react/use-feature-flag.ts
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */
|
|
6
|
+
function subscribe(onChange) {
|
|
7
|
+
return getPosthog()?.onFeatureFlags(onChange) ?? noop;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
|
|
11
|
+
* until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
|
|
12
|
+
* `undefined` on the server and through hydration, so the server markup always matches.
|
|
13
|
+
*
|
|
14
|
+
* Renders the default first and the variant once flags arrive. To wait for them instead, call
|
|
15
|
+
* `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
|
|
16
|
+
*/
|
|
17
|
+
function useFeatureFlag(key) {
|
|
18
|
+
return useSyncExternalStore(subscribe, () => getLoadedPosthog()?.getFeatureFlag(key), () => void 0);
|
|
19
|
+
}
|
|
20
|
+
export { useFeatureFlag };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=use-feature-flag.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-feature-flag.mjs","names":[],"sources":["../../src/react/use-feature-flag.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport { getLoadedPosthog, getPosthog } from '../third-parties/posthog';\n\nconst noop = () => {};\n\n/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */\nfunction subscribe(onChange: () => void): () => void {\n const unsubscribe: (() => void) | undefined = getPosthog()?.onFeatureFlags(onChange);\n return unsubscribe ?? noop;\n}\n\n/**\n * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`\n * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).\n * `undefined` on the server and through hydration, so the server markup always matches.\n *\n * Renders the default first and the variant once flags arrive. To wait for them instead, call\n * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.\n */\nexport function useFeatureFlag(key: string): string | boolean | undefined {\n return useSyncExternalStore(\n subscribe,\n () => getLoadedPosthog()?.getFeatureFlag(key),\n () => undefined\n );\n}\n"],"mappings":";;;AAGA,MAAM,aAAa,CAAC;;AAGpB,SAAS,UAAU,UAAkC;CAEnD,OAD8C,WAAW,CAAC,EAAE,eAAe,QAAQ,KAC7D;AACxB;;;;;;;;;AAUA,SAAgB,eAAe,KAA2C;CACxE,OAAO,qBACL,iBACM,iBAAiB,CAAC,EAAE,eAAe,GAAG,SACtC,KAAA,CACR;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TrackEvent, UserProvidedData } from "../track/types.cjs";
|
|
2
|
-
import { ServerStandardEvent } from "../track/rdt.cjs";
|
|
3
2
|
import { EventActionSource } from "./action-source.cjs";
|
|
3
|
+
import { ServerStandardEvent } from "../track/rdt.cjs";
|
|
4
4
|
/**
|
|
5
5
|
* https://ads-api.reddit.com/docs/v3/operations/Post%20Conversion%20Events
|
|
6
6
|
* https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TrackEvent, UserProvidedData } from "../track/types.mjs";
|
|
2
|
-
import { ServerStandardEvent } from "../track/rdt.mjs";
|
|
3
2
|
import { EventActionSource } from "./action-source.mjs";
|
|
3
|
+
import { ServerStandardEvent } from "../track/rdt.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* https://ads-api.reddit.com/docs/v3/operations/Post%20Conversion%20Events
|
|
6
6
|
* https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source
|
package/dist/setup/index.cjs
CHANGED
|
@@ -10,8 +10,8 @@ const config = {
|
|
|
10
10
|
getTags: null,
|
|
11
11
|
getDeviceId: null,
|
|
12
12
|
getHeaders: null,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
integrations: [],
|
|
14
|
+
excludeFromIntegrations: [],
|
|
15
15
|
deepLink: void 0
|
|
16
16
|
};
|
|
17
17
|
function setupAnalytics(init) {
|
|
@@ -26,8 +26,8 @@ function setupAnalytics(init) {
|
|
|
26
26
|
"Content-Type": "application/json",
|
|
27
27
|
...await init.getHeaders?.()
|
|
28
28
|
});
|
|
29
|
-
config.
|
|
30
|
-
config.
|
|
29
|
+
config.integrations = init.integrations ?? [];
|
|
30
|
+
config.excludeFromIntegrations = init.excludeFromIntegrations ?? [];
|
|
31
31
|
config.deepLink = init.deepLink;
|
|
32
32
|
try {
|
|
33
33
|
init.deepLink?.listen();
|
package/dist/setup/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/setup/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/setup/index.ts"],"sourcesContent":["import type { Integration } from '../third-parties/integration';\nimport type { Environment, EventName, Platform, TrackTags } from '../track/types';\n\nexport interface Storage {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n}\n\n/**\n * The link that opened the current visit of an app — a universal link, an app link, a custom\n * scheme — whose URL, utm and click ids land the visit as a web page's URL does.\n * `@shware/analytics/native` provides one (`deepLink`).\n */\nexport interface DeepLink {\n /** Starts following the links that open the app; `setupAnalytics` calls it once. */\n listen: () => void;\n /** The opening link's tags (`page_location`, utm, click ids); empty without one. */\n getTags: () => TrackTags | Promise<TrackTags>;\n}\n\nexport interface Options {\n release: string;\n storage: Storage;\n endpoint: string;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;\n /**\n * The third parties events and the signed-in user go to, each configured in one place\n * (`googleAnalytics`, `metaAds`, … from `@shware/analytics/third-parties`). Pass the same array\n * to `<Analytics integrations>` for their scripts.\n */\n integrations?: readonly Integration[];\n /**\n * Events reported server-side only (the Conversions APIs, Google's Data Manager API): stored\n * like any event, but handed to no browser tracker, analytics included — a browser copy under\n * another event id would be counted twice by the platforms. `purchase` and `refund`, typically.\n */\n excludeFromIntegrations?: readonly EventName[];\n /** An app's opening link, which native's `getTags` merges into every event's tags. */\n deepLink?: DeepLink;\n}\n\ninterface Config {\n release: string;\n endpoint: string;\n storage: Storage;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders: () => Record<string, string> | Promise<Record<string, string>>;\n integrations: readonly Integration[];\n excludeFromIntegrations: readonly string[];\n deepLink: DeepLink | undefined;\n}\n\ninterface Cache {\n tags: TrackTags | null;\n}\n\nexport const cache: Cache = {\n tags: null,\n};\n\n// oxlint-disable typescript/no-non-null-assertion\nexport const config: Config = {\n endpoint: '',\n release: '0.0.0',\n storage: null!,\n platform: null!,\n environment: null!,\n getTags: null!,\n getDeviceId: null!,\n getHeaders: null!,\n integrations: [],\n excludeFromIntegrations: [],\n deepLink: undefined,\n};\n// oxlint-enable typescript/no-non-null-assertion\n\nexport function setupAnalytics(init: Options) {\n config.release = init.release;\n config.storage = init.storage;\n config.platform = init.platform;\n config.environment = init.environment;\n config.endpoint = init.endpoint.endsWith('/') ? init.endpoint.slice(0, -1) : init.endpoint;\n config.getTags = init.getTags;\n config.getDeviceId = init.getDeviceId;\n config.getHeaders = async () => ({\n 'Content-Type': 'application/json',\n ...(await init.getHeaders?.()),\n });\n config.integrations = init.integrations ?? [];\n config.excludeFromIntegrations = init.excludeFromIntegrations ?? [];\n config.deepLink = init.deepLink;\n // Logged, not thrown: the links are worth less than the setup they would break.\n try {\n init.deepLink?.listen();\n } catch (error) {\n console.error('analytics deepLink.listen failed', error);\n }\n}\n"],"mappings":";;AA+DA,MAAa,QAAe,EAC1B,MAAM,KACR;AAGA,MAAa,SAAiB;CAC5B,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACV,aAAa;CACb,SAAS;CACT,aAAa;CACb,YAAY;CACZ,cAAc,CAAC;CACf,yBAAyB,CAAC;CAC1B,UAAU,KAAA;AACZ;AAGA,SAAgB,eAAe,MAAe;CAC5C,OAAO,UAAU,KAAK;CACtB,OAAO,UAAU,KAAK;CACtB,OAAO,WAAW,KAAK;CACvB,OAAO,cAAc,KAAK;CAC1B,OAAO,WAAW,KAAK,SAAS,SAAS,GAAG,IAAI,KAAK,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK;CAClF,OAAO,UAAU,KAAK;CACtB,OAAO,cAAc,KAAK;CAC1B,OAAO,aAAa,aAAa;EAC/B,gBAAgB;EAChB,GAAI,MAAM,KAAK,aAAa;CAC9B;CACA,OAAO,eAAe,KAAK,gBAAgB,CAAC;CAC5C,OAAO,0BAA0B,KAAK,2BAA2B,CAAC;CAClE,OAAO,WAAW,KAAK;CAEvB,IAAI;EACF,KAAK,UAAU,OAAO;CACxB,SAAS,OAAO;EACd,QAAQ,MAAM,oCAAoC,KAAK;CACzD;AACF"}
|
package/dist/setup/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Environment,
|
|
2
|
-
import {
|
|
1
|
+
import { Environment, EventName, Platform, TrackTags } from "../track/types.cjs";
|
|
2
|
+
import { Integration } from "../third-parties/integration.cjs";
|
|
3
3
|
export interface Storage {
|
|
4
4
|
getItem: (key: string) => string | null;
|
|
5
5
|
setItem: (key: string, value: string) => void;
|
|
@@ -24,8 +24,18 @@ export interface Options {
|
|
|
24
24
|
getTags: () => TrackTags | Promise<TrackTags>;
|
|
25
25
|
getDeviceId: () => string | Promise<string>;
|
|
26
26
|
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The third parties events and the signed-in user go to, each configured in one place
|
|
29
|
+
* (`googleAnalytics`, `metaAds`, … from `@shware/analytics/third-parties`). Pass the same array
|
|
30
|
+
* to `<Analytics integrations>` for their scripts.
|
|
31
|
+
*/
|
|
32
|
+
integrations?: readonly Integration[];
|
|
33
|
+
/**
|
|
34
|
+
* Events reported server-side only (the Conversions APIs, Google's Data Manager API): stored
|
|
35
|
+
* like any event, but handed to no browser tracker, analytics included — a browser copy under
|
|
36
|
+
* another event id would be counted twice by the platforms. `purchase` and `refund`, typically.
|
|
37
|
+
*/
|
|
38
|
+
excludeFromIntegrations?: readonly EventName[];
|
|
29
39
|
/** An app's opening link, which native's `getTags` merges into every event's tags. */
|
|
30
40
|
deepLink?: DeepLink;
|
|
31
41
|
}
|
|
@@ -38,8 +48,8 @@ interface Config {
|
|
|
38
48
|
getTags: () => TrackTags | Promise<TrackTags>;
|
|
39
49
|
getDeviceId: () => string | Promise<string>;
|
|
40
50
|
getHeaders: () => Record<string, string> | Promise<Record<string, string>>;
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
integrations: readonly Integration[];
|
|
52
|
+
excludeFromIntegrations: readonly string[];
|
|
43
53
|
deepLink: DeepLink | undefined;
|
|
44
54
|
}
|
|
45
55
|
interface Cache {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/setup/index.ts"],"mappings":";;iBAGiB;EACf,UAAU;EACV,UAAU,aAAa;;;;;;;iBAQR;;EAEf;;EAEA,eAAe,YAAY,QAAQ;;iBAGpB;EACf;EACA,SAAS;EACT;EACA,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,mBAAmB,yBAAyB,QAAQ
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/setup/index.ts"],"mappings":";;iBAGiB;EACf,UAAU;EACV,UAAU,aAAa;;;;;;;iBAQR;;EAEf;;EAEA,eAAe,YAAY,QAAQ;;iBAGpB;EACf;EACA,SAAS;EACT;EACA,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,mBAAmB,yBAAyB,QAAQ;;;;;;EAMpD,wBAAwB;;;;;;EAMxB,mCAAmC;;EAEnC,WAAW;;UAGH;EACR;EACA;EACA,SAAS;EACT,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,kBAAkB,yBAAyB,QAAQ;EACnD,uBAAuB;EACvB;EACA,UAAU;;UAGF;EACR,MAAM;;qBAGK,OAAO;qBAKP,QAAQ;wBAeL,eAAe,MAAM"}
|
package/dist/setup/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Environment,
|
|
2
|
-
import {
|
|
1
|
+
import { Environment, EventName, Platform, TrackTags } from "../track/types.mjs";
|
|
2
|
+
import { Integration } from "../third-parties/integration.mjs";
|
|
3
3
|
export interface Storage {
|
|
4
4
|
getItem: (key: string) => string | null;
|
|
5
5
|
setItem: (key: string, value: string) => void;
|
|
@@ -24,8 +24,18 @@ export interface Options {
|
|
|
24
24
|
getTags: () => TrackTags | Promise<TrackTags>;
|
|
25
25
|
getDeviceId: () => string | Promise<string>;
|
|
26
26
|
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The third parties events and the signed-in user go to, each configured in one place
|
|
29
|
+
* (`googleAnalytics`, `metaAds`, … from `@shware/analytics/third-parties`). Pass the same array
|
|
30
|
+
* to `<Analytics integrations>` for their scripts.
|
|
31
|
+
*/
|
|
32
|
+
integrations?: readonly Integration[];
|
|
33
|
+
/**
|
|
34
|
+
* Events reported server-side only (the Conversions APIs, Google's Data Manager API): stored
|
|
35
|
+
* like any event, but handed to no browser tracker, analytics included — a browser copy under
|
|
36
|
+
* another event id would be counted twice by the platforms. `purchase` and `refund`, typically.
|
|
37
|
+
*/
|
|
38
|
+
excludeFromIntegrations?: readonly EventName[];
|
|
29
39
|
/** An app's opening link, which native's `getTags` merges into every event's tags. */
|
|
30
40
|
deepLink?: DeepLink;
|
|
31
41
|
}
|
|
@@ -38,8 +48,8 @@ interface Config {
|
|
|
38
48
|
getTags: () => TrackTags | Promise<TrackTags>;
|
|
39
49
|
getDeviceId: () => string | Promise<string>;
|
|
40
50
|
getHeaders: () => Record<string, string> | Promise<Record<string, string>>;
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
integrations: readonly Integration[];
|
|
52
|
+
excludeFromIntegrations: readonly string[];
|
|
43
53
|
deepLink: DeepLink | undefined;
|
|
44
54
|
}
|
|
45
55
|
interface Cache {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/setup/index.ts"],"mappings":";;iBAGiB;EACf,UAAU;EACV,UAAU,aAAa;;;;;;;iBAQR;;EAEf;;EAEA,eAAe,YAAY,QAAQ;;iBAGpB;EACf;EACA,SAAS;EACT;EACA,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,mBAAmB,yBAAyB,QAAQ
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/setup/index.ts"],"mappings":";;iBAGiB;EACf,UAAU;EACV,UAAU,aAAa;;;;;;;iBAQR;;EAEf;;EAEA,eAAe,YAAY,QAAQ;;iBAGpB;EACf;EACA,SAAS;EACT;EACA,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,mBAAmB,yBAAyB,QAAQ;;;;;;EAMpD,wBAAwB;;;;;;EAMxB,mCAAmC;;EAEnC,WAAW;;UAGH;EACR;EACA;EACA,SAAS;EACT,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,kBAAkB,yBAAyB,QAAQ;EACnD,uBAAuB;EACvB;EACA,UAAU;;UAGF;EACR,MAAM;;qBAGK,OAAO;qBAKP,QAAQ;wBAeL,eAAe,MAAM"}
|
package/dist/setup/index.mjs
CHANGED
|
@@ -9,8 +9,8 @@ const config = {
|
|
|
9
9
|
getTags: null,
|
|
10
10
|
getDeviceId: null,
|
|
11
11
|
getHeaders: null,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
integrations: [],
|
|
13
|
+
excludeFromIntegrations: [],
|
|
14
14
|
deepLink: void 0
|
|
15
15
|
};
|
|
16
16
|
function setupAnalytics(init) {
|
|
@@ -25,8 +25,8 @@ function setupAnalytics(init) {
|
|
|
25
25
|
"Content-Type": "application/json",
|
|
26
26
|
...await init.getHeaders?.()
|
|
27
27
|
});
|
|
28
|
-
config.
|
|
29
|
-
config.
|
|
28
|
+
config.integrations = init.integrations ?? [];
|
|
29
|
+
config.excludeFromIntegrations = init.excludeFromIntegrations ?? [];
|
|
30
30
|
config.deepLink = init.deepLink;
|
|
31
31
|
try {
|
|
32
32
|
init.deepLink?.listen();
|
package/dist/setup/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/setup/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/setup/index.ts"],"sourcesContent":["import type { Integration } from '../third-parties/integration';\nimport type { Environment, EventName, Platform, TrackTags } from '../track/types';\n\nexport interface Storage {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n}\n\n/**\n * The link that opened the current visit of an app — a universal link, an app link, a custom\n * scheme — whose URL, utm and click ids land the visit as a web page's URL does.\n * `@shware/analytics/native` provides one (`deepLink`).\n */\nexport interface DeepLink {\n /** Starts following the links that open the app; `setupAnalytics` calls it once. */\n listen: () => void;\n /** The opening link's tags (`page_location`, utm, click ids); empty without one. */\n getTags: () => TrackTags | Promise<TrackTags>;\n}\n\nexport interface Options {\n release: string;\n storage: Storage;\n endpoint: string;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;\n /**\n * The third parties events and the signed-in user go to, each configured in one place\n * (`googleAnalytics`, `metaAds`, … from `@shware/analytics/third-parties`). Pass the same array\n * to `<Analytics integrations>` for their scripts.\n */\n integrations?: readonly Integration[];\n /**\n * Events reported server-side only (the Conversions APIs, Google's Data Manager API): stored\n * like any event, but handed to no browser tracker, analytics included — a browser copy under\n * another event id would be counted twice by the platforms. `purchase` and `refund`, typically.\n */\n excludeFromIntegrations?: readonly EventName[];\n /** An app's opening link, which native's `getTags` merges into every event's tags. */\n deepLink?: DeepLink;\n}\n\ninterface Config {\n release: string;\n endpoint: string;\n storage: Storage;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders: () => Record<string, string> | Promise<Record<string, string>>;\n integrations: readonly Integration[];\n excludeFromIntegrations: readonly string[];\n deepLink: DeepLink | undefined;\n}\n\ninterface Cache {\n tags: TrackTags | null;\n}\n\nexport const cache: Cache = {\n tags: null,\n};\n\n// oxlint-disable typescript/no-non-null-assertion\nexport const config: Config = {\n endpoint: '',\n release: '0.0.0',\n storage: null!,\n platform: null!,\n environment: null!,\n getTags: null!,\n getDeviceId: null!,\n getHeaders: null!,\n integrations: [],\n excludeFromIntegrations: [],\n deepLink: undefined,\n};\n// oxlint-enable typescript/no-non-null-assertion\n\nexport function setupAnalytics(init: Options) {\n config.release = init.release;\n config.storage = init.storage;\n config.platform = init.platform;\n config.environment = init.environment;\n config.endpoint = init.endpoint.endsWith('/') ? init.endpoint.slice(0, -1) : init.endpoint;\n config.getTags = init.getTags;\n config.getDeviceId = init.getDeviceId;\n config.getHeaders = async () => ({\n 'Content-Type': 'application/json',\n ...(await init.getHeaders?.()),\n });\n config.integrations = init.integrations ?? [];\n config.excludeFromIntegrations = init.excludeFromIntegrations ?? [];\n config.deepLink = init.deepLink;\n // Logged, not thrown: the links are worth less than the setup they would break.\n try {\n init.deepLink?.listen();\n } catch (error) {\n console.error('analytics deepLink.listen failed', error);\n }\n}\n"],"mappings":";AA+DA,MAAa,QAAe,EAC1B,MAAM,KACR;AAGA,MAAa,SAAiB;CAC5B,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACV,aAAa;CACb,SAAS;CACT,aAAa;CACb,YAAY;CACZ,cAAc,CAAC;CACf,yBAAyB,CAAC;CAC1B,UAAU,KAAA;AACZ;AAGA,SAAgB,eAAe,MAAe;CAC5C,OAAO,UAAU,KAAK;CACtB,OAAO,UAAU,KAAK;CACtB,OAAO,WAAW,KAAK;CACvB,OAAO,cAAc,KAAK;CAC1B,OAAO,WAAW,KAAK,SAAS,SAAS,GAAG,IAAI,KAAK,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK;CAClF,OAAO,UAAU,KAAK;CACtB,OAAO,cAAc,KAAK;CAC1B,OAAO,aAAa,aAAa;EAC/B,gBAAgB;EAChB,GAAI,MAAM,KAAK,aAAa;CAC9B;CACA,OAAO,eAAe,KAAK,gBAAgB,CAAC;CAC5C,OAAO,0BAA0B,KAAK,2BAA2B,CAAC;CAClE,OAAO,WAAW,KAAK;CAEvB,IAAI;EACF,KAAK,UAAU,OAAO;CACxB,SAAS,OAAO;EACd,QAAQ,MAAM,oCAAoC,KAAK;CACzD;AACF"}
|
package/dist/tanstack/index.cjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_tanstack_analytics = require("./analytics.cjs");
|
|
3
2
|
const require_tanstack_middleware = require("./middleware.cjs");
|
|
4
|
-
exports.Analytics = require_tanstack_analytics.Analytics;
|
|
5
3
|
exports.createClickIdMiddleware = require_tanstack_middleware.createClickIdMiddleware;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Analytics } from "./analytics.cjs";
|
|
2
1
|
import { ClickIdMiddlewareOptions, createClickIdMiddleware } from "./middleware.cjs";
|
|
3
|
-
export {
|
|
2
|
+
export { type ClickIdMiddlewareOptions, createClickIdMiddleware };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Analytics } from "./analytics.mjs";
|
|
2
1
|
import { ClickIdMiddlewareOptions, createClickIdMiddleware } from "./middleware.mjs";
|
|
3
|
-
export {
|
|
2
|
+
export { type ClickIdMiddlewareOptions, createClickIdMiddleware };
|
package/dist/tanstack/index.mjs
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let react_dom = require("react-dom");
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
// src/third-parties/analytics-props.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes
|
|
7
|
+
* the hints and, on the server, puts them at the top of `<head>`.
|
|
8
|
+
*/
|
|
9
|
+
function preconnectIntegrations(integrations = []) {
|
|
10
|
+
integrations.forEach((integration) => {
|
|
11
|
+
integration.preconnect?.forEach((origin) => (0, react_dom.preconnect)(origin, { crossOrigin: "anonymous" }));
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The integrations' scripts as plain `<script>` elements, for the frameworks that render them as
|
|
16
|
+
* they are (react).
|
|
17
|
+
*/
|
|
18
|
+
function IntegrationScripts({ integrations = [], nonce }) {
|
|
19
|
+
return integrations.flatMap(({ script }) => script ? [script] : []).map((script) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
20
|
+
id: script.id,
|
|
21
|
+
nonce,
|
|
22
|
+
dangerouslySetInnerHTML: { __html: script.inline }
|
|
23
|
+
}, script.id));
|
|
24
|
+
}
|
|
25
|
+
exports.IntegrationScripts = IntegrationScripts;
|
|
26
|
+
exports.preconnectIntegrations = preconnectIntegrations;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=analytics-props.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Integration } from "./integration.cjs";
|
|
2
|
+
/** The props every framework's `<Analytics>` takes (react, next). */
|
|
3
|
+
export interface AnalyticsProps {
|
|
4
|
+
/** The integrations passed to `setupAnalytics`, whose scripts this renders. */
|
|
5
|
+
integrations?: readonly Integration[];
|
|
6
|
+
/** Renders `<meta property="fb:app_id">`, for Facebook's sharing insights. */
|
|
7
|
+
facebookAppId?: string;
|
|
8
|
+
/** The request's CSP nonce, set on every script rendered. */
|
|
9
|
+
nonce?: string;
|
|
10
|
+
/** Reports Core Web Vitals as events (on by default). */
|
|
11
|
+
reportWebVitals?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes
|
|
15
|
+
* the hints and, on the server, puts them at the top of `<head>`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function preconnectIntegrations(integrations?: readonly Integration[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* The integrations' scripts as plain `<script>` elements, for the frameworks that render them as
|
|
20
|
+
* they are (react).
|
|
21
|
+
*/
|
|
22
|
+
export declare function IntegrationScripts({ integrations, nonce }: Pick<AnalyticsProps, 'integrations' | 'nonce'>): import("react").JSX.Element[];
|
|
23
|
+
//# sourceMappingURL=analytics-props.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics-props.d.cts","names":[],"sources":["../../src/third-parties/analytics-props.tsx"],"mappings":";;iBAIiB;;EAEf,wBAAwB;;EAExB;;EAEA;;EAEA;;;;;;wBAOc,uBAAuB,wBAAuB;;;;;wBAU9C,qBACd,cACA,SACC,KAAK,4DAAyC,IAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Integration } from "./integration.mjs";
|
|
2
|
+
/** The props every framework's `<Analytics>` takes (react, next). */
|
|
3
|
+
export interface AnalyticsProps {
|
|
4
|
+
/** The integrations passed to `setupAnalytics`, whose scripts this renders. */
|
|
5
|
+
integrations?: readonly Integration[];
|
|
6
|
+
/** Renders `<meta property="fb:app_id">`, for Facebook's sharing insights. */
|
|
7
|
+
facebookAppId?: string;
|
|
8
|
+
/** The request's CSP nonce, set on every script rendered. */
|
|
9
|
+
nonce?: string;
|
|
10
|
+
/** Reports Core Web Vitals as events (on by default). */
|
|
11
|
+
reportWebVitals?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes
|
|
15
|
+
* the hints and, on the server, puts them at the top of `<head>`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function preconnectIntegrations(integrations?: readonly Integration[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* The integrations' scripts as plain `<script>` elements, for the frameworks that render them as
|
|
20
|
+
* they are (react).
|
|
21
|
+
*/
|
|
22
|
+
export declare function IntegrationScripts({ integrations, nonce }: Pick<AnalyticsProps, 'integrations' | 'nonce'>): import("react").JSX.Element[];
|
|
23
|
+
//# sourceMappingURL=analytics-props.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics-props.d.mts","names":[],"sources":["../../src/third-parties/analytics-props.tsx"],"mappings":";;iBAIiB;;EAEf,wBAAwB;;EAExB;;EAEA;;EAEA;;;;;;wBAOc,uBAAuB,wBAAuB;;;;;wBAU9C,qBACd,cACA,SACC,KAAK,4DAAyC,IAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { preconnect } from "react-dom";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/third-parties/analytics-props.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes
|
|
6
|
+
* the hints and, on the server, puts them at the top of `<head>`.
|
|
7
|
+
*/
|
|
8
|
+
function preconnectIntegrations(integrations = []) {
|
|
9
|
+
integrations.forEach((integration) => {
|
|
10
|
+
integration.preconnect?.forEach((origin) => preconnect(origin, { crossOrigin: "anonymous" }));
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The integrations' scripts as plain `<script>` elements, for the frameworks that render them as
|
|
15
|
+
* they are (react).
|
|
16
|
+
*/
|
|
17
|
+
function IntegrationScripts({ integrations = [], nonce }) {
|
|
18
|
+
return integrations.flatMap(({ script }) => script ? [script] : []).map((script) => /* @__PURE__ */ jsx("script", {
|
|
19
|
+
id: script.id,
|
|
20
|
+
nonce,
|
|
21
|
+
dangerouslySetInnerHTML: { __html: script.inline }
|
|
22
|
+
}, script.id));
|
|
23
|
+
}
|
|
24
|
+
export { IntegrationScripts, preconnectIntegrations };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=analytics-props.mjs.map
|
|
@@ -0,0 +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 } 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"}
|
|
@@ -15,6 +15,38 @@ function setGAUser({ user_id, user_data }) {
|
|
|
15
15
|
window.gtag("set", "user_id", user_id || null);
|
|
16
16
|
if (user_data) window.gtag("set", "user_data", user_data);
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Google Analytics 4 (gtag.js): every event, for behavior analysis. `src` serves gtag.js from
|
|
20
|
+
* another path (a first-party proxy); `debug` turns on GA4's DebugView for this page.
|
|
21
|
+
*/
|
|
22
|
+
function googleAnalytics(options) {
|
|
23
|
+
const src = options.src ?? `https://www.googletagmanager.com/gtag/js?id=${options.id}`;
|
|
24
|
+
return {
|
|
25
|
+
type: "analytics",
|
|
26
|
+
track: sendGAEvent,
|
|
27
|
+
setUser: setGAUser,
|
|
28
|
+
script: {
|
|
29
|
+
id: "gtag",
|
|
30
|
+
inline: `
|
|
31
|
+
window.dataLayer = window.dataLayer || [];
|
|
32
|
+
function gtag(){dataLayer.push(arguments);}
|
|
33
|
+
gtag('js', new Date());
|
|
34
|
+
gtag('config', ${JSON.stringify(options.id)}${options.debug ? ", { debug_mode: true }" : ""});
|
|
35
|
+
(function (d, s, u) {
|
|
36
|
+
var j = d.createElement(s);
|
|
37
|
+
j.async = true;
|
|
38
|
+
// A script added here does not inherit the nonce: hand it this one's, or a CSP that
|
|
39
|
+
// allows scripts by nonce (without 'strict-dynamic') blocks gtag.js.
|
|
40
|
+
j.nonce = d.currentScript && d.currentScript.nonce;
|
|
41
|
+
j.src = u;
|
|
42
|
+
var f = d.getElementsByTagName(s)[0];
|
|
43
|
+
f.parentNode.insertBefore(j, f);
|
|
44
|
+
})(document, 'script', ${JSON.stringify(src)});
|
|
45
|
+
`
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.googleAnalytics = googleAnalytics;
|
|
18
50
|
exports.sendGAEvent = sendGAEvent;
|
|
19
51
|
exports.setGAUser = setGAUser;
|
|
20
52
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-analytics.cjs","names":[],"sources":["../../src/third-parties/google-analytics.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { Gtag } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ndeclare global {\n interface Window {\n /** Undefined until the Google tag (gtag.js) script has loaded. */\n gtag?: Gtag['gtag'];\n }\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('GA has not been initialized');\n return false;\n }\n window.gtag('event', name, properties);\n}\n\nexport function setGAUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n // No user is sign-out (`reset()`): GA keeps a set user_id for every later event on the page, so\n // it is cleared explicitly.\n window.gtag('set', 'user_id', user_id || null);\n if (user_data) window.gtag('set', 'user_data', user_data);\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"google-analytics.cjs","names":[],"sources":["../../src/third-parties/google-analytics.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { GaId, Gtag } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport type { Integration } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the Google tag (gtag.js) script has loaded. */\n gtag?: Gtag['gtag'];\n }\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('GA has not been initialized');\n return false;\n }\n window.gtag('event', name, properties);\n}\n\nexport function setGAUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n // No user is sign-out (`reset()`): GA keeps a set user_id for every later event on the page, so\n // it is cleared explicitly.\n window.gtag('set', 'user_id', user_id || null);\n if (user_data) window.gtag('set', 'user_data', user_data);\n}\n\n/**\n * Google Analytics 4 (gtag.js): every event, for behavior analysis. `src` serves gtag.js from\n * another path (a first-party proxy); `debug` turns on GA4's DebugView for this page.\n */\nexport function googleAnalytics(options: { id: GaId; src?: string; debug?: boolean }): Integration {\n const src = options.src ?? `https://www.googletagmanager.com/gtag/js?id=${options.id}`;\n return {\n type: 'analytics',\n track: sendGAEvent,\n setUser: setGAUser,\n script: {\n id: 'gtag',\n inline: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', ${JSON.stringify(options.id)}${options.debug ? ', { debug_mode: true }' : ''});\n (function (d, s, u) {\n var j = d.createElement(s);\n j.async = true;\n // A script added here does not inherit the nonce: hand it this one's, or a CSP that\n // allows scripts by nonce (without 'strict-dynamic') blocks gtag.js.\n j.nonce = d.currentScript && d.currentScript.nonce;\n j.src = u;\n var f = d.getElementsByTagName(s)[0];\n f.parentNode.insertBefore(j, f);\n })(document, 'script', ${JSON.stringify(src)});\n `,\n },\n };\n}\n"],"mappings":";;AAYA,SAAgB,YACd,MACA,YACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,6BAA6B;EAC1C,OAAO;CACT;CACA,OAAO,KAAK,SAAS,MAAM,UAAU;AACvC;AAEA,SAAgB,UAAU,EAAE,SAAS,aAA+B;CAClE,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,6BAA6B;EAC1C;CACF;CAGA,OAAO,KAAK,OAAO,WAAW,WAAW,IAAI;CAC7C,IAAI,WAAW,OAAO,KAAK,OAAO,aAAa,SAAS;AAC1D;;;;;AAMA,SAAgB,gBAAgB,SAAmE;CACjG,MAAM,MAAM,QAAQ,OAAO,+CAA+C,QAAQ;CAClF,OAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,QAAQ;GACN,IAAI;GACJ,QAAQ;;;;yBAIW,KAAK,UAAU,QAAQ,EAAE,IAAI,QAAQ,QAAQ,2BAA2B,GAAG;;;;;;;;;;iCAUnE,KAAK,UAAU,GAAG,EAAE;;EAEjD;CACF;AACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Gtag } from "../track/gtag.cjs";
|
|
1
|
+
import { GaId, Gtag } from "../track/gtag.cjs";
|
|
2
2
|
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
3
3
|
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
4
|
+
import { Integration } from "./integration.cjs";
|
|
4
5
|
declare global {
|
|
5
6
|
interface Window {
|
|
6
7
|
/** Undefined until the Google tag (gtag.js) script has loaded. */
|
|
@@ -9,4 +10,13 @@ declare global {
|
|
|
9
10
|
}
|
|
10
11
|
export declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): false | undefined;
|
|
11
12
|
export declare function setGAUser({ user_id, user_data }: UpdateVisitorDTO): void;
|
|
13
|
+
/**
|
|
14
|
+
* Google Analytics 4 (gtag.js): every event, for behavior analysis. `src` serves gtag.js from
|
|
15
|
+
* another path (a first-party proxy); `debug` turns on GA4's DebugView for this page.
|
|
16
|
+
*/
|
|
17
|
+
export declare function googleAnalytics(options: {
|
|
18
|
+
id: GaId;
|
|
19
|
+
src?: string;
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
}): Integration;
|
|
12
22
|
//# sourceMappingURL=google-analytics.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-analytics.d.cts","names":[],"sources":["../../src/third-parties/google-analytics.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-analytics.d.cts","names":[],"sources":["../../src/third-parties/google-analytics.ts"],"mappings":";;;;QAKQ;YACI;;IAER,OAAO;;;wBAIK,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB;wBASf,YAAY,SAAS,aAAa;;;;;wBAelC,gBAAgB;EAAW,IAAI;EAAM;EAAc;IAAoB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Gtag } from "../track/gtag.mjs";
|
|
1
|
+
import { GaId, Gtag } from "../track/gtag.mjs";
|
|
2
2
|
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
3
3
|
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
4
|
+
import { Integration } from "./integration.mjs";
|
|
4
5
|
declare global {
|
|
5
6
|
interface Window {
|
|
6
7
|
/** Undefined until the Google tag (gtag.js) script has loaded. */
|
|
@@ -9,4 +10,13 @@ declare global {
|
|
|
9
10
|
}
|
|
10
11
|
export declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): false | undefined;
|
|
11
12
|
export declare function setGAUser({ user_id, user_data }: UpdateVisitorDTO): void;
|
|
13
|
+
/**
|
|
14
|
+
* Google Analytics 4 (gtag.js): every event, for behavior analysis. `src` serves gtag.js from
|
|
15
|
+
* another path (a first-party proxy); `debug` turns on GA4's DebugView for this page.
|
|
16
|
+
*/
|
|
17
|
+
export declare function googleAnalytics(options: {
|
|
18
|
+
id: GaId;
|
|
19
|
+
src?: string;
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
}): Integration;
|
|
12
22
|
//# sourceMappingURL=google-analytics.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-analytics.d.mts","names":[],"sources":["../../src/third-parties/google-analytics.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-analytics.d.mts","names":[],"sources":["../../src/third-parties/google-analytics.ts"],"mappings":";;;;QAKQ;YACI;;IAER,OAAO;;;wBAIK,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB;wBASf,YAAY,SAAS,aAAa;;;;;wBAelC,gBAAgB;EAAW,IAAI;EAAM;EAAc;IAAoB"}
|
|
@@ -14,6 +14,37 @@ function setGAUser({ user_id, user_data }) {
|
|
|
14
14
|
window.gtag("set", "user_id", user_id || null);
|
|
15
15
|
if (user_data) window.gtag("set", "user_data", user_data);
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Google Analytics 4 (gtag.js): every event, for behavior analysis. `src` serves gtag.js from
|
|
19
|
+
* another path (a first-party proxy); `debug` turns on GA4's DebugView for this page.
|
|
20
|
+
*/
|
|
21
|
+
function googleAnalytics(options) {
|
|
22
|
+
const src = options.src ?? `https://www.googletagmanager.com/gtag/js?id=${options.id}`;
|
|
23
|
+
return {
|
|
24
|
+
type: "analytics",
|
|
25
|
+
track: sendGAEvent,
|
|
26
|
+
setUser: setGAUser,
|
|
27
|
+
script: {
|
|
28
|
+
id: "gtag",
|
|
29
|
+
inline: `
|
|
30
|
+
window.dataLayer = window.dataLayer || [];
|
|
31
|
+
function gtag(){dataLayer.push(arguments);}
|
|
32
|
+
gtag('js', new Date());
|
|
33
|
+
gtag('config', ${JSON.stringify(options.id)}${options.debug ? ", { debug_mode: true }" : ""});
|
|
34
|
+
(function (d, s, u) {
|
|
35
|
+
var j = d.createElement(s);
|
|
36
|
+
j.async = true;
|
|
37
|
+
// A script added here does not inherit the nonce: hand it this one's, or a CSP that
|
|
38
|
+
// allows scripts by nonce (without 'strict-dynamic') blocks gtag.js.
|
|
39
|
+
j.nonce = d.currentScript && d.currentScript.nonce;
|
|
40
|
+
j.src = u;
|
|
41
|
+
var f = d.getElementsByTagName(s)[0];
|
|
42
|
+
f.parentNode.insertBefore(j, f);
|
|
43
|
+
})(document, 'script', ${JSON.stringify(src)});
|
|
44
|
+
`
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export { googleAnalytics, sendGAEvent, setGAUser };
|
|
18
49
|
|
|
19
50
|
//# sourceMappingURL=google-analytics.mjs.map
|