@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
package/README.md
CHANGED
|
@@ -16,27 +16,26 @@ pnpm add @shware/analytics zod
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Every framework and platform integration is an optional peer dependency: install only what your
|
|
19
|
-
entry point imports (`next`, `@tanstack/react-start`,
|
|
19
|
+
entry point imports (`next`, `@tanstack/react-start`, the `expo-*`
|
|
20
20
|
modules for `/native`, `react-native-fbsdk-next` for `/native/fbsdk`, and so on).
|
|
21
21
|
|
|
22
22
|
## Entry points
|
|
23
23
|
|
|
24
|
-
| Import
|
|
25
|
-
|
|
|
26
|
-
| `@shware/analytics`
|
|
27
|
-
| `@shware/analytics/web`
|
|
28
|
-
| `@shware/analytics/native`
|
|
29
|
-
| `@shware/analytics/native/firebase`
|
|
30
|
-
| `@shware/analytics/native/fbsdk`
|
|
31
|
-
| `@shware/analytics/next`
|
|
32
|
-
| `@shware/analytics/
|
|
33
|
-
| `@shware/analytics/
|
|
34
|
-
| `@shware/analytics/third-parties`
|
|
35
|
-
| `@shware/analytics/
|
|
36
|
-
| `@shware/analytics/server`
|
|
37
|
-
| `@shware/analytics/
|
|
38
|
-
| `@shware/analytics/
|
|
39
|
-
| `@shware/analytics/ads` | server | Pulling spend and performance from Google Ads and Meta |
|
|
24
|
+
| Import | Runs on | What it is for |
|
|
25
|
+
| ----------------------------------- | ------- | --------------------------------------------------------------------------- |
|
|
26
|
+
| `@shware/analytics` | client | `setupAnalytics`, `track`, `identify`, `reset`, `sendFeedback`, links, bots |
|
|
27
|
+
| `@shware/analytics/web` | browser | `storage`, `getTags`, `getDeviceId` for `setupAnalytics` on the web |
|
|
28
|
+
| `@shware/analytics/native` | Expo | The same for React Native, plus `deepLink` and `useAppAnalytics` |
|
|
29
|
+
| `@shware/analytics/native/firebase` | Expo | `firebaseAnalytics()`, the integration for Firebase Analytics |
|
|
30
|
+
| `@shware/analytics/native/fbsdk` | Expo | `metaAppEvents()`, the integration for Facebook App Events |
|
|
31
|
+
| `@shware/analytics/next` | browser | `<Analytics />` for the Next.js App Router |
|
|
32
|
+
| `@shware/analytics/react` | browser | `<Analytics />` for any React router (TanStack Router, React Router, …) |
|
|
33
|
+
| `@shware/analytics/tanstack` | both | `createClickIdMiddleware` for TanStack Start |
|
|
34
|
+
| `@shware/analytics/third-parties` | browser | GA4, Meta Pixel, Reddit, LinkedIn, OpenAI and UET trackers and setters |
|
|
35
|
+
| `@shware/analytics/server` | server | Conversions APIs: Meta, Google Ads, Microsoft, Reddit, LinkedIn, OpenAI |
|
|
36
|
+
| `@shware/analytics/server/legacy` | server | The old Meta sender built on `facebook-nodejs-business-sdk` |
|
|
37
|
+
| `@shware/analytics/attribution` | server | `classifyTouch` and the channel vocabulary for reading sessions |
|
|
38
|
+
| `@shware/analytics/ads` | server | Pulling spend and performance from Google Ads and Meta |
|
|
40
39
|
|
|
41
40
|
## Client-side only
|
|
42
41
|
|
|
@@ -56,10 +55,9 @@ Call `setupAnalytics` once, at module scope of the client entry, before anything
|
|
|
56
55
|
|
|
57
56
|
```ts
|
|
58
57
|
import { setupAnalytics } from '@shware/analytics';
|
|
59
|
-
import { sendGAEvent, setGAUser } from '@shware/analytics/third-parties';
|
|
60
|
-
import { sendPosthogEvent, setPosthogUser } from '@shware/analytics/third-parties/posthog';
|
|
61
58
|
import { getDeviceId, getTags, storage } from '@shware/analytics/web';
|
|
62
59
|
import { version } from '../package.json';
|
|
60
|
+
import { integrations } from './integrations';
|
|
63
61
|
|
|
64
62
|
setupAnalytics({
|
|
65
63
|
storage,
|
|
@@ -68,13 +66,63 @@ setupAnalytics({
|
|
|
68
66
|
release: version,
|
|
69
67
|
platform: 'web',
|
|
70
68
|
environment: process.env.NODE_ENV === 'development' ? 'development' : 'production',
|
|
71
|
-
// Optional: every tracked event is also handed to these, and identify / reset to the setters.
|
|
72
|
-
thirdPartyTrackers: [sendGAEvent, sendPosthogEvent],
|
|
73
|
-
thirdPartyUserSetters: [setGAUser, setPosthogUser],
|
|
74
69
|
endpoint: 'https://api.example.com/v1/analytics',
|
|
70
|
+
integrations,
|
|
71
|
+
// Still sent to the analytics server, but to no integration: report them server-side instead.
|
|
72
|
+
excludeFromIntegrations: ['purchase', 'refund'],
|
|
75
73
|
});
|
|
76
74
|
```
|
|
77
75
|
|
|
76
|
+
### Integrations
|
|
77
|
+
|
|
78
|
+
Each third party is one `integrations` entry that carries everything about it: how events reach it, how it learns the signed-in user (`identify` / `reset()`), and the ids of the script it needs. Pass the same array to `<Analytics integrations>`, which renders those scripts, so an id is written once.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
// integrations.ts
|
|
82
|
+
import {
|
|
83
|
+
googleAnalytics,
|
|
84
|
+
linkedInAds,
|
|
85
|
+
metaAds,
|
|
86
|
+
microsoftAds,
|
|
87
|
+
posthogAnalytics,
|
|
88
|
+
} from '@shware/analytics/third-parties';
|
|
89
|
+
|
|
90
|
+
export const integrations = [
|
|
91
|
+
googleAnalytics({ id: 'G-XXXXXXX', debug: import.meta.env.DEV }),
|
|
92
|
+
posthogAnalytics({
|
|
93
|
+
token: 'phc_XXXXXXX',
|
|
94
|
+
config: { api_host: 'https://us.i.posthog.com', defaults: '2026-01-30' },
|
|
95
|
+
}),
|
|
96
|
+
metaAds({ pixelId: '1234567890', customEvents: ['onboarding_completed'] }),
|
|
97
|
+
linkedInAds({ partnerId: '123456', conversions: { sign_up: 7654321 } }),
|
|
98
|
+
microsoftAds({ tagId: '987654', customerId: '1234' }),
|
|
99
|
+
];
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
| Type | Integrations | Receives |
|
|
103
|
+
| ----------- | ------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
104
|
+
| `analytics` | `googleAnalytics`, `posthogAnalytics` | every event |
|
|
105
|
+
| `ads` | `metaAds`, `redditAds`, `openaiAds` | the events it maps to its own standard events, plus `customEvents` |
|
|
106
|
+
| `ads` | `linkedInAds` | the events in `conversions`, each as its conversion id |
|
|
107
|
+
| `ads` | `microsoftAds` | `events` (the GA4 conversion events, `CONVERSION_EVENTS`, by default), plus `customEvents` |
|
|
108
|
+
|
|
109
|
+
An ad platform needs conversions to optimize and build audiences, not the product's day-to-day events, which are behavior analysis for GA4 and PostHog. `excludeFromIntegrations` applies to every integration, analytics included. PostHog loads from its HTML snippet like the pixels, so `posthog-js` is not bundled: the library comes from PostHog's assets host after the page loads, and `config` (only its JSON survives) goes to `posthog.init`. Until it loads, `window.posthog` is a stub that queues calls returning nothing (`capture`, `identify`, `onFeatureFlags`) and replays them, while calls returning a value (`getFeatureFlag`) return `undefined`. So: `getPosthog()` for queued calls, `getLoadedPosthog()` (undefined until loaded) for values, and `useFeatureFlag(key)` from `@shware/analytics/react` in components. `useFeatureFlag` renders the default until flags arrive, then the variant. To show a `<Suspense>` fallback until then instead, wait for them with React 19.3's `browser()` (so the server renders the fallback) and `posthogFlagsReady()` (one promise per page, resolving when flags load or after a 3 s timeout, for when an ad blocker stops the library):
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { useFeatureFlag } from '@shware/analytics/react';
|
|
113
|
+
import { posthogFlagsReady } from '@shware/analytics/third-parties';
|
|
114
|
+
import { use } from 'react';
|
|
115
|
+
import { browser } from 'react-dom';
|
|
116
|
+
|
|
117
|
+
function Checkout() {
|
|
118
|
+
use(browser());
|
|
119
|
+
use(posthogFlagsReady());
|
|
120
|
+
return useFeatureFlag('new-checkout') === 'test' ? <NewCheckout /> : <OldCheckout />;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
With server-evaluated flags in `config.bootstrap` the wait ends as soon as the library loads. On Next.js its snippet uses `next/script`'s `beforeInteractive`, so the stub exists before hydration tracks anything; render `<Analytics>` in the root layout for that. `<Analytics>` also preconnects to PostHog's assets host (`Integration.preconnect`, through `react-dom`'s `preconnect`), so `array.js` starts sooner. The `PostHog` and `PostHogConfig` types come from `posthog-js`: install it as a dev dependency for them. In an app, `firebaseAnalytics()` (every event) and `metaAppEvents({ customEvents })` (the conversions Meta maps, like `metaAds`) are the `integrations`. A platform the SDK does not cover is an object implementing `Integration` (`type`, `track`, and optionally `setUser` and `script`).
|
|
125
|
+
|
|
78
126
|
`getHeaders` is also accepted, for a backend that wants extra headers on the analytics requests.
|
|
79
127
|
|
|
80
128
|
React Native (Expo):
|
|
@@ -108,16 +156,23 @@ so screen changes are tracked as page views.
|
|
|
108
156
|
### The `<Analytics />` component (web)
|
|
109
157
|
|
|
110
158
|
Each web framework entry exports an `Analytics` component. Render it once in the document head:
|
|
111
|
-
it tracks page views, outbound clicks and web vitals, and
|
|
112
|
-
|
|
113
|
-
|
|
159
|
+
it tracks page views, outbound clicks and web vitals, and renders the script of each of the
|
|
160
|
+
`integrations` you pass — the same array given to `setupAnalytics`, so each id is written once.
|
|
161
|
+
Every integration carries one script (`Integration.script`: an inline snippet that loads the
|
|
162
|
+
vendor's script from its host, as the vendors' official snippets do). Next.js has its own entry
|
|
163
|
+
(`@shware/analytics/next`); any other React router uses `@shware/analytics/react` and passes the
|
|
164
|
+
current location. On TanStack Start:
|
|
114
165
|
|
|
115
166
|
```tsx
|
|
116
|
-
import { Analytics } from '@shware/analytics/
|
|
167
|
+
import { Analytics } from '@shware/analytics/react';
|
|
168
|
+
import { useLocation } from '@tanstack/react-router';
|
|
169
|
+
import { integrations } from './integrations';
|
|
170
|
+
|
|
171
|
+
const { pathname, searchStr } = useLocation();
|
|
117
172
|
|
|
118
173
|
<head>
|
|
119
174
|
<HeadContent />
|
|
120
|
-
<Analytics
|
|
175
|
+
<Analytics pathname={pathname} search={searchStr} nonce={nonce} integrations={integrations} />
|
|
121
176
|
</head>;
|
|
122
177
|
```
|
|
123
178
|
|
|
@@ -842,21 +897,19 @@ Microsoft recommends the UET tag and the Conversions API (CAPI) together. The tw
|
|
|
842
897
|
(`tagId`, `eventName`, `eventId`): the browser sends the internal event name as the UET action with
|
|
843
898
|
the event id as `event_id`, the server sends the same name as `eventName` with the same id.
|
|
844
899
|
|
|
845
|
-
Browser —
|
|
846
|
-
|
|
847
|
-
|
|
900
|
+
Browser — the `microsoftAds` integration below carries the tag id and the customer id, and the
|
|
901
|
+
framework `Analytics` component (from `@shware/analytics/react` or `/next`)
|
|
902
|
+
renders its tag from `integrations`. It inlines Microsoft's snippet with `enableAutoSpaTracking: true` (the
|
|
848
903
|
tag owns page loads, `sendUETEvent` drops `page_view` and forwards everything else) and fires the
|
|
849
904
|
Conversions API's ID Sync pixel once per visit for the SDK visitor — anonymous visitors included,
|
|
850
905
|
they are who remarketing audiences are built from. Then:
|
|
851
906
|
|
|
852
907
|
```ts
|
|
853
|
-
import {
|
|
908
|
+
import { microsoftAds, setUETConsent } from '@shware/analytics/third-parties';
|
|
854
909
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
thirdPartyUserSetters: [setUETUser],
|
|
859
|
-
});
|
|
910
|
+
// One integration: conversions to UET, enhanced conversions (the tag hashes the email/phone itself
|
|
911
|
+
// before they leave the page), and the tag id and customer id `<Analytics integrations>` renders.
|
|
912
|
+
setupAnalytics({ integrations: [microsoftAds({ tagId: '97267979', customerId: '255004870' })] });
|
|
860
913
|
// Consent mode (EEA/UK/CH): push `default` before the tag loads, `update` on the visitor's choice.
|
|
861
914
|
setUETConsent('default', { ad_storage: 'denied', wait_for_update: 2000 });
|
|
862
915
|
```
|
package/dist/native/fbsdk.cjs
CHANGED
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_field = require("../utils/field.cjs");
|
|
3
|
+
const require_third_parties_integration = require("../third-parties/integration.cjs");
|
|
2
4
|
const require_track_fbq = require("../track/fbq.cjs");
|
|
3
5
|
let react_native_fbsdk_next = require("react-native-fbsdk-next");
|
|
4
6
|
// src/native/fbsdk.ts
|
|
5
7
|
/**
|
|
6
8
|
* ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/
|
|
9
|
+
*
|
|
10
|
+
* Synchronous, like `logEvent`: a tracker returns `void | boolean`, which an `async` function's
|
|
11
|
+
* promise would not satisfy. Callers that still `await` it keep compiling.
|
|
7
12
|
*/
|
|
8
|
-
|
|
13
|
+
function sendFBEvent(name, properties) {
|
|
9
14
|
const [_, fbEventName, fbEventProperties] = require_track_fbq.mapFBEvent(name, properties);
|
|
10
15
|
react_native_fbsdk_next.AppEventsLogger.logEvent(fbEventName, fbEventProperties);
|
|
11
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Hands the signed-in user to Facebook App Events, as `setFBUser` does the Pixel: the user id
|
|
19
|
+
* (`external_id`) and the advanced matching fields, which the SDK hashes on the device. No user is
|
|
20
|
+
* sign-out (`reset()`): the user id is cleared, but the matching fields may not be.
|
|
21
|
+
*
|
|
22
|
+
* Known gap, kept on purpose: the fields go to the native `setUserData`, which on Android only
|
|
23
|
+
* updates the fields it is given, so the empty ones sent at sign-out leave the previous user's
|
|
24
|
+
* email and phone in place, and later anonymous events (or another user's without an email) can
|
|
25
|
+
* still carry them. `react-native-fbsdk-next` does not expose the native `clearUserData`. Dropping
|
|
26
|
+
* the fields would avoid it, but cost more in ad conversion matching than the gap does.
|
|
27
|
+
*/
|
|
28
|
+
function setFBUser({ user_id, user_data }) {
|
|
29
|
+
react_native_fbsdk_next.AppEventsLogger.setUserID(user_id || null);
|
|
30
|
+
const address = require_utils_field.getFirst(user_data?.address);
|
|
31
|
+
react_native_fbsdk_next.AppEventsLogger.setUserData({
|
|
32
|
+
email: require_utils_field.getFirst(user_data?.email),
|
|
33
|
+
phone: require_utils_field.getFirst(user_data?.phone_number),
|
|
34
|
+
firstName: address?.first_name,
|
|
35
|
+
lastName: address?.last_name,
|
|
36
|
+
city: address?.city,
|
|
37
|
+
state: address?.region,
|
|
38
|
+
zip: address?.postal_code,
|
|
39
|
+
country: address?.country
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Facebook App Events: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`
|
|
44
|
+
* — the app's counterpart of `metaAds`.
|
|
45
|
+
*/
|
|
46
|
+
function metaAppEvents(options = {}) {
|
|
47
|
+
const isStandard = (name) => require_track_fbq.mapFBEvent(name)[0] === "track";
|
|
48
|
+
return {
|
|
49
|
+
type: "ads",
|
|
50
|
+
track: require_third_parties_integration.adsTracker(sendFBEvent, isStandard, options.customEvents ?? []),
|
|
51
|
+
setUser: setFBUser
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.metaAppEvents = metaAppEvents;
|
|
12
55
|
exports.sendFBEvent = sendFBEvent;
|
|
56
|
+
exports.setFBUser = setFBUser;
|
|
13
57
|
|
|
14
58
|
//# sourceMappingURL=fbsdk.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fbsdk.cjs","names":["mapFBEvent"],"sources":["../../src/native/fbsdk.ts"],"sourcesContent":["import { AppEventsLogger, type Params } from 'react-native-fbsdk-next';\nimport { mapFBEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\n/**\n * ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/\n
|
|
1
|
+
{"version":3,"file":"fbsdk.cjs","names":["mapFBEvent","getFirst","adsTracker"],"sources":["../../src/native/fbsdk.ts"],"sourcesContent":["import { AppEventsLogger, type Params } from 'react-native-fbsdk-next';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport { type AdsOptions, type Integration, adsTracker } from '../third-parties/integration';\nimport { mapFBEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\n\n/**\n * ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/\n *\n * Synchronous, like `logEvent`: a tracker returns `void | boolean`, which an `async` function's\n * promise would not satisfy. Callers that still `await` it keep compiling.\n */\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n const [_, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n AppEventsLogger.logEvent(fbEventName, fbEventProperties as Params);\n}\n\n/**\n * Hands the signed-in user to Facebook App Events, as `setFBUser` does the Pixel: the user id\n * (`external_id`) and the advanced matching fields, which the SDK hashes on the device. No user is\n * sign-out (`reset()`): the user id is cleared, but the matching fields may not be.\n *\n * Known gap, kept on purpose: the fields go to the native `setUserData`, which on Android only\n * updates the fields it is given, so the empty ones sent at sign-out leave the previous user's\n * email and phone in place, and later anonymous events (or another user's without an email) can\n * still carry them. `react-native-fbsdk-next` does not expose the native `clearUserData`. Dropping\n * the fields would avoid it, but cost more in ad conversion matching than the gap does.\n */\nexport function setFBUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>) {\n AppEventsLogger.setUserID(user_id || null);\n const address = getFirst(user_data?.address);\n AppEventsLogger.setUserData({\n email: getFirst(user_data?.email),\n phone: getFirst(user_data?.phone_number),\n firstName: address?.first_name,\n lastName: address?.last_name,\n city: address?.city,\n state: address?.region,\n zip: address?.postal_code,\n country: address?.country,\n });\n}\n\n/**\n * Facebook App Events: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`\n * — the app's counterpart of `metaAds`.\n */\nexport function metaAppEvents(options: AdsOptions = {}): Integration {\n const isStandard = (name: string) => mapFBEvent(name as TrackName)[0] === 'track';\n return {\n type: 'ads',\n track: adsTracker(sendFBEvent, isStandard, options.customEvents ?? []),\n setUser: setFBUser,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,YACd,MACA,YACA;CACA,MAAM,CAAC,GAAG,aAAa,qBAAqBA,kBAAAA,WAAW,MAAM,UAAU;CACvE,wBAAA,gBAAgB,SAAS,aAAa,iBAA2B;AACnE;;;;;;;;;;;;AAaA,SAAgB,UAAU,EAAE,SAAS,aAA6C;CAChF,wBAAA,gBAAgB,UAAU,WAAW,IAAI;CACzC,MAAM,UAAUC,oBAAAA,SAAS,WAAW,OAAO;CAC3C,wBAAA,gBAAgB,YAAY;EAC1B,OAAOA,oBAAAA,SAAS,WAAW,KAAK;EAChC,OAAOA,oBAAAA,SAAS,WAAW,YAAY;EACvC,WAAW,SAAS;EACpB,UAAU,SAAS;EACnB,MAAM,SAAS;EACf,OAAO,SAAS;EAChB,KAAK,SAAS;EACd,SAAS,SAAS;CACpB,CAAC;AACH;;;;;AAMA,SAAgB,cAAc,UAAsB,CAAC,GAAgB;CACnE,MAAM,cAAc,SAAiBD,kBAAAA,WAAW,IAAiB,CAAC,CAAC,OAAO;CAC1E,OAAO;EACL,MAAM;EACN,OAAOE,kCAAAA,WAAW,aAAa,YAAY,QAAQ,gBAAgB,CAAC,CAAC;EACrE,SAAS;CACX;AACF"}
|
package/dist/native/fbsdk.d.cts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
2
|
+
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
3
|
+
import { AdsOptions, Integration } from "../third-parties/integration.cjs";
|
|
2
4
|
/**
|
|
3
5
|
* ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/
|
|
6
|
+
*
|
|
7
|
+
* Synchronous, like `logEvent`: a tracker returns `void | boolean`, which an `async` function's
|
|
8
|
+
* promise would not satisfy. Callers that still `await` it keep compiling.
|
|
4
9
|
*/
|
|
5
|
-
export declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>):
|
|
10
|
+
export declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Hands the signed-in user to Facebook App Events, as `setFBUser` does the Pixel: the user id
|
|
13
|
+
* (`external_id`) and the advanced matching fields, which the SDK hashes on the device. No user is
|
|
14
|
+
* sign-out (`reset()`): the user id is cleared, but the matching fields may not be.
|
|
15
|
+
*
|
|
16
|
+
* Known gap, kept on purpose: the fields go to the native `setUserData`, which on Android only
|
|
17
|
+
* updates the fields it is given, so the empty ones sent at sign-out leave the previous user's
|
|
18
|
+
* email and phone in place, and later anonymous events (or another user's without an email) can
|
|
19
|
+
* still carry them. `react-native-fbsdk-next` does not expose the native `clearUserData`. Dropping
|
|
20
|
+
* the fields would avoid it, but cost more in ad conversion matching than the gap does.
|
|
21
|
+
*/
|
|
22
|
+
export declare function setFBUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Facebook App Events: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`
|
|
25
|
+
* — the app's counterpart of `metaAds`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function metaAppEvents(options?: AdsOptions): Integration;
|
|
6
28
|
//# sourceMappingURL=fbsdk.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fbsdk.d.cts","names":[],"sources":["../../src/native/fbsdk.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fbsdk.d.cts","names":[],"sources":["../../src/native/fbsdk.ts"],"mappings":";;;;;;;;;wBAagB,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB;;;;;;;;;;;;wBAiBf,YAAY,SAAS,aAAa,KAAK;;;;;wBAmBvC,cAAc,UAAS,aAAkB"}
|
package/dist/native/fbsdk.d.mts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
2
|
+
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
3
|
+
import { AdsOptions, Integration } from "../third-parties/integration.mjs";
|
|
2
4
|
/**
|
|
3
5
|
* ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/
|
|
6
|
+
*
|
|
7
|
+
* Synchronous, like `logEvent`: a tracker returns `void | boolean`, which an `async` function's
|
|
8
|
+
* promise would not satisfy. Callers that still `await` it keep compiling.
|
|
4
9
|
*/
|
|
5
|
-
export declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>):
|
|
10
|
+
export declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Hands the signed-in user to Facebook App Events, as `setFBUser` does the Pixel: the user id
|
|
13
|
+
* (`external_id`) and the advanced matching fields, which the SDK hashes on the device. No user is
|
|
14
|
+
* sign-out (`reset()`): the user id is cleared, but the matching fields may not be.
|
|
15
|
+
*
|
|
16
|
+
* Known gap, kept on purpose: the fields go to the native `setUserData`, which on Android only
|
|
17
|
+
* updates the fields it is given, so the empty ones sent at sign-out leave the previous user's
|
|
18
|
+
* email and phone in place, and later anonymous events (or another user's without an email) can
|
|
19
|
+
* still carry them. `react-native-fbsdk-next` does not expose the native `clearUserData`. Dropping
|
|
20
|
+
* the fields would avoid it, but cost more in ad conversion matching than the gap does.
|
|
21
|
+
*/
|
|
22
|
+
export declare function setFBUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Facebook App Events: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`
|
|
25
|
+
* — the app's counterpart of `metaAds`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function metaAppEvents(options?: AdsOptions): Integration;
|
|
6
28
|
//# sourceMappingURL=fbsdk.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fbsdk.d.mts","names":[],"sources":["../../src/native/fbsdk.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fbsdk.d.mts","names":[],"sources":["../../src/native/fbsdk.ts"],"mappings":";;;;;;;;;wBAagB,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB;;;;;;;;;;;;wBAiBf,YAAY,SAAS,aAAa,KAAK;;;;;wBAmBvC,cAAc,UAAS,aAAkB"}
|
package/dist/native/fbsdk.mjs
CHANGED
|
@@ -1,13 +1,55 @@
|
|
|
1
|
+
import { getFirst } from "../utils/field.mjs";
|
|
2
|
+
import { adsTracker } from "../third-parties/integration.mjs";
|
|
1
3
|
import { mapFBEvent } from "../track/fbq.mjs";
|
|
2
4
|
import { AppEventsLogger } from "react-native-fbsdk-next";
|
|
3
5
|
// src/native/fbsdk.ts
|
|
4
6
|
/**
|
|
5
7
|
* ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/
|
|
8
|
+
*
|
|
9
|
+
* Synchronous, like `logEvent`: a tracker returns `void | boolean`, which an `async` function's
|
|
10
|
+
* promise would not satisfy. Callers that still `await` it keep compiling.
|
|
6
11
|
*/
|
|
7
|
-
|
|
12
|
+
function sendFBEvent(name, properties) {
|
|
8
13
|
const [_, fbEventName, fbEventProperties] = mapFBEvent(name, properties);
|
|
9
14
|
AppEventsLogger.logEvent(fbEventName, fbEventProperties);
|
|
10
15
|
}
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Hands the signed-in user to Facebook App Events, as `setFBUser` does the Pixel: the user id
|
|
18
|
+
* (`external_id`) and the advanced matching fields, which the SDK hashes on the device. No user is
|
|
19
|
+
* sign-out (`reset()`): the user id is cleared, but the matching fields may not be.
|
|
20
|
+
*
|
|
21
|
+
* Known gap, kept on purpose: the fields go to the native `setUserData`, which on Android only
|
|
22
|
+
* updates the fields it is given, so the empty ones sent at sign-out leave the previous user's
|
|
23
|
+
* email and phone in place, and later anonymous events (or another user's without an email) can
|
|
24
|
+
* still carry them. `react-native-fbsdk-next` does not expose the native `clearUserData`. Dropping
|
|
25
|
+
* the fields would avoid it, but cost more in ad conversion matching than the gap does.
|
|
26
|
+
*/
|
|
27
|
+
function setFBUser({ user_id, user_data }) {
|
|
28
|
+
AppEventsLogger.setUserID(user_id || null);
|
|
29
|
+
const address = getFirst(user_data?.address);
|
|
30
|
+
AppEventsLogger.setUserData({
|
|
31
|
+
email: getFirst(user_data?.email),
|
|
32
|
+
phone: getFirst(user_data?.phone_number),
|
|
33
|
+
firstName: address?.first_name,
|
|
34
|
+
lastName: address?.last_name,
|
|
35
|
+
city: address?.city,
|
|
36
|
+
state: address?.region,
|
|
37
|
+
zip: address?.postal_code,
|
|
38
|
+
country: address?.country
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Facebook App Events: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`
|
|
43
|
+
* — the app's counterpart of `metaAds`.
|
|
44
|
+
*/
|
|
45
|
+
function metaAppEvents(options = {}) {
|
|
46
|
+
const isStandard = (name) => mapFBEvent(name)[0] === "track";
|
|
47
|
+
return {
|
|
48
|
+
type: "ads",
|
|
49
|
+
track: adsTracker(sendFBEvent, isStandard, options.customEvents ?? []),
|
|
50
|
+
setUser: setFBUser
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { metaAppEvents, sendFBEvent, setFBUser };
|
|
12
54
|
|
|
13
55
|
//# sourceMappingURL=fbsdk.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fbsdk.mjs","names":[],"sources":["../../src/native/fbsdk.ts"],"sourcesContent":["import { AppEventsLogger, type Params } from 'react-native-fbsdk-next';\nimport { mapFBEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\n/**\n * ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/\n
|
|
1
|
+
{"version":3,"file":"fbsdk.mjs","names":[],"sources":["../../src/native/fbsdk.ts"],"sourcesContent":["import { AppEventsLogger, type Params } from 'react-native-fbsdk-next';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport { type AdsOptions, type Integration, adsTracker } from '../third-parties/integration';\nimport { mapFBEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\n\n/**\n * ref: https://developers.facebook.com/docs/app-events/guides/maximize-in-app-ad-revenue/\n *\n * Synchronous, like `logEvent`: a tracker returns `void | boolean`, which an `async` function's\n * promise would not satisfy. Callers that still `await` it keep compiling.\n */\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n const [_, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n AppEventsLogger.logEvent(fbEventName, fbEventProperties as Params);\n}\n\n/**\n * Hands the signed-in user to Facebook App Events, as `setFBUser` does the Pixel: the user id\n * (`external_id`) and the advanced matching fields, which the SDK hashes on the device. No user is\n * sign-out (`reset()`): the user id is cleared, but the matching fields may not be.\n *\n * Known gap, kept on purpose: the fields go to the native `setUserData`, which on Android only\n * updates the fields it is given, so the empty ones sent at sign-out leave the previous user's\n * email and phone in place, and later anonymous events (or another user's without an email) can\n * still carry them. `react-native-fbsdk-next` does not expose the native `clearUserData`. Dropping\n * the fields would avoid it, but cost more in ad conversion matching than the gap does.\n */\nexport function setFBUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>) {\n AppEventsLogger.setUserID(user_id || null);\n const address = getFirst(user_data?.address);\n AppEventsLogger.setUserData({\n email: getFirst(user_data?.email),\n phone: getFirst(user_data?.phone_number),\n firstName: address?.first_name,\n lastName: address?.last_name,\n city: address?.city,\n state: address?.region,\n zip: address?.postal_code,\n country: address?.country,\n });\n}\n\n/**\n * Facebook App Events: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`\n * — the app's counterpart of `metaAds`.\n */\nexport function metaAppEvents(options: AdsOptions = {}): Integration {\n const isStandard = (name: string) => mapFBEvent(name as TrackName)[0] === 'track';\n return {\n type: 'ads',\n track: adsTracker(sendFBEvent, isStandard, options.customEvents ?? []),\n setUser: setFBUser,\n };\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,YACd,MACA,YACA;CACA,MAAM,CAAC,GAAG,aAAa,qBAAqB,WAAW,MAAM,UAAU;CACvE,gBAAgB,SAAS,aAAa,iBAA2B;AACnE;;;;;;;;;;;;AAaA,SAAgB,UAAU,EAAE,SAAS,aAA6C;CAChF,gBAAgB,UAAU,WAAW,IAAI;CACzC,MAAM,UAAU,SAAS,WAAW,OAAO;CAC3C,gBAAgB,YAAY;EAC1B,OAAO,SAAS,WAAW,KAAK;EAChC,OAAO,SAAS,WAAW,YAAY;EACvC,WAAW,SAAS;EACpB,UAAU,SAAS;EACnB,MAAM,SAAS;EACf,OAAO,SAAS;EAChB,KAAK,SAAS;EACd,SAAS,SAAS;CACpB,CAAC;AACH;;;;;AAMA,SAAgB,cAAc,UAAsB,CAAC,GAAgB;CACnE,MAAM,cAAc,SAAiB,WAAW,IAAiB,CAAC,CAAC,OAAO;CAC1E,OAAO;EACL,MAAM;EACN,OAAO,WAAW,aAAa,YAAY,QAAQ,gBAAgB,CAAC,CAAC;EACrE,SAAS;CACX;AACF"}
|
package/dist/native/firebase.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_field = require("../utils/field.cjs");
|
|
2
3
|
let _react_native_firebase_analytics = require("@react-native-firebase/analytics");
|
|
3
4
|
// src/native/firebase.ts
|
|
4
5
|
const analytics = (0, _react_native_firebase_analytics.getAnalytics)();
|
|
@@ -15,6 +16,32 @@ function sendFirebaseEvent(name, properties) {
|
|
|
15
16
|
});
|
|
16
17
|
else (0, _react_native_firebase_analytics.logEvent)(analytics, name, properties);
|
|
17
18
|
}
|
|
19
|
+
function logError(e) {
|
|
20
|
+
if (e instanceof Error) console.log(e.message);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets Firebase's user id to the signed-in user, as `setGAUser` does GA's; no user is sign-out
|
|
24
|
+
* (`reset()`), which clears it. The user properties stay free of PII, as Google requires: the
|
|
25
|
+
* email and phone number go to on-device conversion measurement instead, which matches Google
|
|
26
|
+
* Ads app campaign clicks on the device without them leaving it — iOS only, a no-op elsewhere.
|
|
27
|
+
*/
|
|
28
|
+
function setFirebaseUser({ user_id, user_data }) {
|
|
29
|
+
(0, _react_native_firebase_analytics.setUserId)(analytics, user_id || null).catch(logError);
|
|
30
|
+
const email = require_utils_field.getFirst(user_data?.email);
|
|
31
|
+
if (email) (0, _react_native_firebase_analytics.initiateOnDeviceConversionMeasurementWithEmailAddress)(analytics, email).catch(logError);
|
|
32
|
+
const phone = require_utils_field.getFirst(user_data?.phone_number);
|
|
33
|
+
if (phone) (0, _react_native_firebase_analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber)(analytics, phone).catch(logError);
|
|
34
|
+
}
|
|
35
|
+
/** Firebase Analytics: every event, for behavior analysis — the app's counterpart of GA4. */
|
|
36
|
+
function firebaseAnalytics() {
|
|
37
|
+
return {
|
|
38
|
+
type: "analytics",
|
|
39
|
+
track: sendFirebaseEvent,
|
|
40
|
+
setUser: setFirebaseUser
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.firebaseAnalytics = firebaseAnalytics;
|
|
18
44
|
exports.sendFirebaseEvent = sendFirebaseEvent;
|
|
45
|
+
exports.setFirebaseUser = setFirebaseUser;
|
|
19
46
|
|
|
20
47
|
//# sourceMappingURL=firebase.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.cjs","names":["getAnalytics"],"sources":["../../src/native/firebase.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"firebase.cjs","names":["getAnalytics","getFirst"],"sources":["../../src/native/firebase.ts"],"sourcesContent":["import {\n getAnalytics,\n initiateOnDeviceConversionMeasurementWithEmailAddress,\n initiateOnDeviceConversionMeasurementWithPhoneNumber,\n logEvent,\n setUserId,\n} from '@react-native-firebase/analytics';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport type { Integration } from '../third-parties/integration';\nimport type { StandardEvents } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\n\nconst analytics = getAnalytics();\n\n/**\n * A `ThirdPartyTracker` for Firebase Analytics. Synchronous: @react-native-firebase/analytics 26\n * made the modular `logEvent` fire-and-forget (void), and a tracker's return is `void | boolean`\n * (`false` meaning \"not ready\"), which an `async` function's promise would not satisfy. Callers\n * that still `await` it keep compiling.\n */\nexport function sendFirebaseEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (name === 'screen_view') {\n logEvent(analytics, 'screen_view', {\n firebase_screen: (properties as StandardEvents['screen_view'] | undefined)?.screen_name,\n firebase_screen_class: (properties as StandardEvents['screen_view'] | undefined)\n ?.screen_class,\n });\n } else {\n logEvent(analytics, name, properties);\n }\n}\n\nfunction logError(e: unknown) {\n if (e instanceof Error) console.log(e.message);\n}\n\n/**\n * Sets Firebase's user id to the signed-in user, as `setGAUser` does GA's; no user is sign-out\n * (`reset()`), which clears it. The user properties stay free of PII, as Google requires: the\n * email and phone number go to on-device conversion measurement instead, which matches Google\n * Ads app campaign clicks on the device without them leaving it — iOS only, a no-op elsewhere.\n */\nexport function setFirebaseUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>) {\n setUserId(analytics, user_id || null).catch(logError);\n const email = getFirst(user_data?.email);\n if (email)\n initiateOnDeviceConversionMeasurementWithEmailAddress(analytics, email).catch(logError);\n const phone = getFirst(user_data?.phone_number);\n if (phone) initiateOnDeviceConversionMeasurementWithPhoneNumber(analytics, phone).catch(logError);\n}\n\n/** Firebase Analytics: every event, for behavior analysis — the app's counterpart of GA4. */\nexport function firebaseAnalytics(): Integration {\n return { type: 'analytics', track: sendFirebaseEvent, setUser: setFirebaseUser };\n}\n"],"mappings":";;;;AAaA,MAAM,aAAA,GAAYA,iCAAAA,aAAAA,CAAa;;;;;;;AAQ/B,SAAgB,kBACd,MACA,YACA;CACA,IAAI,SAAS,eACX,CAAA,GAAA,iCAAA,SAAA,CAAS,WAAW,eAAe;EACjC,iBAAkB,YAA0D;EAC5E,uBAAwB,YACpB;CACN,CAAC;MAED,CAAA,GAAA,iCAAA,SAAA,CAAS,WAAW,MAAM,UAAU;AAExC;AAEA,SAAS,SAAS,GAAY;CAC5B,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;AAC/C;;;;;;;AAQA,SAAgB,gBAAgB,EAAE,SAAS,aAA6C;CACtF,CAAA,GAAA,iCAAA,UAAA,CAAU,WAAW,WAAW,IAAI,CAAC,CAAC,MAAM,QAAQ;CACpD,MAAM,QAAQC,oBAAAA,SAAS,WAAW,KAAK;CACvC,IAAI,OACF,CAAA,GAAA,iCAAA,sDAAA,CAAsD,WAAW,KAAK,CAAC,CAAC,MAAM,QAAQ;CACxF,MAAM,QAAQA,oBAAAA,SAAS,WAAW,YAAY;CAC9C,IAAI,OAAO,CAAA,GAAA,iCAAA,qDAAA,CAAqD,WAAW,KAAK,CAAC,CAAC,MAAM,QAAQ;AAClG;;AAGA,SAAgB,oBAAiC;CAC/C,OAAO;EAAE,MAAM;EAAa,OAAO;EAAmB,SAAS;CAAgB;AACjF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
2
|
+
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
3
|
+
import { Integration } from "../third-parties/integration.cjs";
|
|
2
4
|
/**
|
|
3
5
|
* A `ThirdPartyTracker` for Firebase Analytics. Synchronous: @react-native-firebase/analytics 26
|
|
4
6
|
* made the modular `logEvent` fire-and-forget (void), and a tracker's return is `void | boolean`
|
|
@@ -6,4 +8,13 @@ import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
|
6
8
|
* that still `await` it keep compiling.
|
|
7
9
|
*/
|
|
8
10
|
export declare function sendFirebaseEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Sets Firebase's user id to the signed-in user, as `setGAUser` does GA's; no user is sign-out
|
|
13
|
+
* (`reset()`), which clears it. The user properties stay free of PII, as Google requires: the
|
|
14
|
+
* email and phone number go to on-device conversion measurement instead, which matches Google
|
|
15
|
+
* Ads app campaign clicks on the device without them leaving it — iOS only, a no-op elsewhere.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setFirebaseUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>): void;
|
|
18
|
+
/** Firebase Analytics: every event, for behavior analysis — the app's counterpart of GA4. */
|
|
19
|
+
export declare function firebaseAnalytics(): Integration;
|
|
9
20
|
//# sourceMappingURL=firebase.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.d.cts","names":[],"sources":["../../src/native/firebase.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"firebase.d.cts","names":[],"sources":["../../src/native/firebase.ts"],"mappings":";;;;;;;;;wBAqBgB,kBAAkB,UAAU,WAC1C,MAAM,UAAU,IAChB,aAAa,gBAAgB;;;;;;;wBAuBf,kBAAkB,SAAS,aAAa,KAAK;;wBAU7C,qBAAqB"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
2
|
+
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
3
|
+
import { Integration } from "../third-parties/integration.mjs";
|
|
2
4
|
/**
|
|
3
5
|
* A `ThirdPartyTracker` for Firebase Analytics. Synchronous: @react-native-firebase/analytics 26
|
|
4
6
|
* made the modular `logEvent` fire-and-forget (void), and a tracker's return is `void | boolean`
|
|
@@ -6,4 +8,13 @@ import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
|
6
8
|
* that still `await` it keep compiling.
|
|
7
9
|
*/
|
|
8
10
|
export declare function sendFirebaseEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Sets Firebase's user id to the signed-in user, as `setGAUser` does GA's; no user is sign-out
|
|
13
|
+
* (`reset()`), which clears it. The user properties stay free of PII, as Google requires: the
|
|
14
|
+
* email and phone number go to on-device conversion measurement instead, which matches Google
|
|
15
|
+
* Ads app campaign clicks on the device without them leaving it — iOS only, a no-op elsewhere.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setFirebaseUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>): void;
|
|
18
|
+
/** Firebase Analytics: every event, for behavior analysis — the app's counterpart of GA4. */
|
|
19
|
+
export declare function firebaseAnalytics(): Integration;
|
|
9
20
|
//# sourceMappingURL=firebase.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.d.mts","names":[],"sources":["../../src/native/firebase.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"firebase.d.mts","names":[],"sources":["../../src/native/firebase.ts"],"mappings":";;;;;;;;;wBAqBgB,kBAAkB,UAAU,WAC1C,MAAM,UAAU,IAChB,aAAa,gBAAgB;;;;;;;wBAuBf,kBAAkB,SAAS,aAAa,KAAK;;wBAU7C,qBAAqB"}
|
package/dist/native/firebase.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getFirst } from "../utils/field.mjs";
|
|
2
|
+
import { getAnalytics, initiateOnDeviceConversionMeasurementWithEmailAddress, initiateOnDeviceConversionMeasurementWithPhoneNumber, logEvent, setUserId } from "@react-native-firebase/analytics";
|
|
2
3
|
// src/native/firebase.ts
|
|
3
4
|
const analytics = getAnalytics();
|
|
4
5
|
/**
|
|
@@ -14,6 +15,30 @@ function sendFirebaseEvent(name, properties) {
|
|
|
14
15
|
});
|
|
15
16
|
else logEvent(analytics, name, properties);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
function logError(e) {
|
|
19
|
+
if (e instanceof Error) console.log(e.message);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sets Firebase's user id to the signed-in user, as `setGAUser` does GA's; no user is sign-out
|
|
23
|
+
* (`reset()`), which clears it. The user properties stay free of PII, as Google requires: the
|
|
24
|
+
* email and phone number go to on-device conversion measurement instead, which matches Google
|
|
25
|
+
* Ads app campaign clicks on the device without them leaving it — iOS only, a no-op elsewhere.
|
|
26
|
+
*/
|
|
27
|
+
function setFirebaseUser({ user_id, user_data }) {
|
|
28
|
+
setUserId(analytics, user_id || null).catch(logError);
|
|
29
|
+
const email = getFirst(user_data?.email);
|
|
30
|
+
if (email) initiateOnDeviceConversionMeasurementWithEmailAddress(analytics, email).catch(logError);
|
|
31
|
+
const phone = getFirst(user_data?.phone_number);
|
|
32
|
+
if (phone) initiateOnDeviceConversionMeasurementWithPhoneNumber(analytics, phone).catch(logError);
|
|
33
|
+
}
|
|
34
|
+
/** Firebase Analytics: every event, for behavior analysis — the app's counterpart of GA4. */
|
|
35
|
+
function firebaseAnalytics() {
|
|
36
|
+
return {
|
|
37
|
+
type: "analytics",
|
|
38
|
+
track: sendFirebaseEvent,
|
|
39
|
+
setUser: setFirebaseUser
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export { firebaseAnalytics, sendFirebaseEvent, setFirebaseUser };
|
|
18
43
|
|
|
19
44
|
//# sourceMappingURL=firebase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.mjs","names":[],"sources":["../../src/native/firebase.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"firebase.mjs","names":[],"sources":["../../src/native/firebase.ts"],"sourcesContent":["import {\n getAnalytics,\n initiateOnDeviceConversionMeasurementWithEmailAddress,\n initiateOnDeviceConversionMeasurementWithPhoneNumber,\n logEvent,\n setUserId,\n} from '@react-native-firebase/analytics';\nimport type { UpdateVisitorDTO } from '../schema/index';\nimport type { Integration } from '../third-parties/integration';\nimport type { StandardEvents } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\n\nconst analytics = getAnalytics();\n\n/**\n * A `ThirdPartyTracker` for Firebase Analytics. Synchronous: @react-native-firebase/analytics 26\n * made the modular `logEvent` fire-and-forget (void), and a tracker's return is `void | boolean`\n * (`false` meaning \"not ready\"), which an `async` function's promise would not satisfy. Callers\n * that still `await` it keep compiling.\n */\nexport function sendFirebaseEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (name === 'screen_view') {\n logEvent(analytics, 'screen_view', {\n firebase_screen: (properties as StandardEvents['screen_view'] | undefined)?.screen_name,\n firebase_screen_class: (properties as StandardEvents['screen_view'] | undefined)\n ?.screen_class,\n });\n } else {\n logEvent(analytics, name, properties);\n }\n}\n\nfunction logError(e: unknown) {\n if (e instanceof Error) console.log(e.message);\n}\n\n/**\n * Sets Firebase's user id to the signed-in user, as `setGAUser` does GA's; no user is sign-out\n * (`reset()`), which clears it. The user properties stay free of PII, as Google requires: the\n * email and phone number go to on-device conversion measurement instead, which matches Google\n * Ads app campaign clicks on the device without them leaving it — iOS only, a no-op elsewhere.\n */\nexport function setFirebaseUser({ user_id, user_data }: Omit<UpdateVisitorDTO, 'tags'>) {\n setUserId(analytics, user_id || null).catch(logError);\n const email = getFirst(user_data?.email);\n if (email)\n initiateOnDeviceConversionMeasurementWithEmailAddress(analytics, email).catch(logError);\n const phone = getFirst(user_data?.phone_number);\n if (phone) initiateOnDeviceConversionMeasurementWithPhoneNumber(analytics, phone).catch(logError);\n}\n\n/** Firebase Analytics: every event, for behavior analysis — the app's counterpart of GA4. */\nexport function firebaseAnalytics(): Integration {\n return { type: 'analytics', track: sendFirebaseEvent, setUser: setFirebaseUser };\n}\n"],"mappings":";;;AAaA,MAAM,YAAY,aAAa;;;;;;;AAQ/B,SAAgB,kBACd,MACA,YACA;CACA,IAAI,SAAS,eACX,SAAS,WAAW,eAAe;EACjC,iBAAkB,YAA0D;EAC5E,uBAAwB,YACpB;CACN,CAAC;MAED,SAAS,WAAW,MAAM,UAAU;AAExC;AAEA,SAAS,SAAS,GAAY;CAC5B,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;AAC/C;;;;;;;AAQA,SAAgB,gBAAgB,EAAE,SAAS,aAA6C;CACtF,UAAU,WAAW,WAAW,IAAI,CAAC,CAAC,MAAM,QAAQ;CACpD,MAAM,QAAQ,SAAS,WAAW,KAAK;CACvC,IAAI,OACF,sDAAsD,WAAW,KAAK,CAAC,CAAC,MAAM,QAAQ;CACxF,MAAM,QAAQ,SAAS,WAAW,YAAY;CAC9C,IAAI,OAAO,qDAAqD,WAAW,KAAK,CAAC,CAAC,MAAM,QAAQ;AAClG;;AAGA,SAAgB,oBAAiC;CAC/C,OAAO;EAAE,MAAM;EAAa,OAAO;EAAmB,SAAS;CAAgB;AACjF"}
|