@layers/client 0.1.1-alpha.0 → 1.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 +200 -12
- package/dist/index-C1d8NEFV.d.ts +306 -0
- package/dist/index-C1d8NEFV.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -616
- package/dist/react.d.ts +105 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +142 -0
- package/dist/react.js.map +1 -0
- package/dist/src-SyPoXjEy.js +399 -0
- package/dist/src-SyPoXjEy.js.map +1 -0
- package/package.json +34 -8
- package/dist/index-NMBS3y1V.d.ts +0 -372
- package/dist/index-NMBS3y1V.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,36 +1,224 @@
|
|
|
1
1
|
# @layers/client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Web browser SDK for Layers Analytics. Thin wrapper over the Rust/WASM core (`@layers/core-wasm`) that adds browser-specific features: localStorage persistence, network detection, page lifecycle flush via `sendBeacon`, and React integration.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```bash
|
|
8
8
|
npm install @layers/client
|
|
9
9
|
# or
|
|
10
10
|
pnpm add @layers/client
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
## Quick
|
|
13
|
+
## Quick Start
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
import { LayersClient } from '@layers/client';
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const layers = new LayersClient({
|
|
19
19
|
apiKey: 'your-api-key',
|
|
20
20
|
appId: 'your-app-id',
|
|
21
|
-
environment: 'production'
|
|
22
|
-
|
|
21
|
+
environment: 'production'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await layers.init();
|
|
25
|
+
|
|
26
|
+
// Track events
|
|
27
|
+
await layers.track('button_click', { button: 'signup' });
|
|
28
|
+
|
|
29
|
+
// Track screen views
|
|
30
|
+
await layers.screen('home_page');
|
|
31
|
+
|
|
32
|
+
// Identify a user
|
|
33
|
+
layers.setAppUserId('user-123');
|
|
34
|
+
|
|
35
|
+
// Shut down gracefully
|
|
36
|
+
await layers.shutdownAsync();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
All fields for `LayersConfig`:
|
|
42
|
+
|
|
43
|
+
| Field | Type | Default | Description |
|
|
44
|
+
| ----------------- | -------------------------------------------- | ----------------------- | ------------------------------------------ |
|
|
45
|
+
| `apiKey` | `string` | _required_ | API key from the Layers dashboard |
|
|
46
|
+
| `appId` | `string` | _required_ | Application identifier |
|
|
47
|
+
| `environment` | `'development' \| 'staging' \| 'production'` | _required_ | Deployment environment |
|
|
48
|
+
| `appUserId` | `string` | `undefined` | Pre-set user ID at init time |
|
|
49
|
+
| `enableDebug` | `boolean` | `false` | Verbose console logging for all SDK calls |
|
|
50
|
+
| `baseUrl` | `string` | `https://in.layers.com` | Override the ingest endpoint |
|
|
51
|
+
| `flushIntervalMs` | `number` | `30000` | Periodic flush interval (ms) |
|
|
52
|
+
| `flushThreshold` | `number` | `10` | Queue depth that triggers auto-flush |
|
|
53
|
+
| `maxQueueSize` | `number` | `1000` | Max events in queue before dropping oldest |
|
|
54
|
+
|
|
55
|
+
## React Integration
|
|
56
|
+
|
|
57
|
+
The SDK includes first-class React bindings via `@layers/client/react`.
|
|
58
|
+
|
|
59
|
+
### Provider
|
|
60
|
+
|
|
61
|
+
Wrap your app in `<LayersProvider>` to initialize the SDK and make it available to hooks:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { LayersProvider } from '@layers/client/react';
|
|
65
|
+
|
|
66
|
+
function App() {
|
|
67
|
+
return (
|
|
68
|
+
<LayersProvider
|
|
69
|
+
config={{
|
|
70
|
+
apiKey: 'your-api-key',
|
|
71
|
+
appId: 'your-app-id',
|
|
72
|
+
environment: 'production'
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
<MyApp />
|
|
76
|
+
</LayersProvider>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The provider creates a `LayersClient` on mount, calls `init()`, and shuts it down on unmount.
|
|
82
|
+
|
|
83
|
+
### Hooks
|
|
84
|
+
|
|
85
|
+
All hooks must be used inside a `<LayersProvider>`.
|
|
86
|
+
|
|
87
|
+
#### `useTrack()`
|
|
88
|
+
|
|
89
|
+
Returns a stable, memoized function for tracking events:
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
import { useTrack } from '@layers/client/react';
|
|
93
|
+
|
|
94
|
+
function SignupButton() {
|
|
95
|
+
const track = useTrack();
|
|
96
|
+
|
|
97
|
+
return <button onClick={() => track('signup_click', { source: 'hero' })}>Sign up</button>;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### `useScreen()`
|
|
102
|
+
|
|
103
|
+
Returns a stable, memoized function for tracking screen views:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { useScreen } from '@layers/client/react';
|
|
107
|
+
import { useEffect } from 'react';
|
|
108
|
+
|
|
109
|
+
function Dashboard() {
|
|
110
|
+
const screen = useScreen();
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
screen('dashboard');
|
|
113
|
+
}, [screen]);
|
|
114
|
+
|
|
115
|
+
return <div>...</div>;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### `useIdentify()`
|
|
120
|
+
|
|
121
|
+
Returns a function to set (or clear) the app user ID:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import { useIdentify } from '@layers/client/react';
|
|
125
|
+
|
|
126
|
+
function LoginForm() {
|
|
127
|
+
const identify = useIdentify();
|
|
128
|
+
|
|
129
|
+
const onLogin = (userId: string) => {
|
|
130
|
+
identify(userId);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const onLogout = () => {
|
|
134
|
+
identify(undefined);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### `useConsent()`
|
|
140
|
+
|
|
141
|
+
Returns functions to get and set consent state:
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import { useConsent } from '@layers/client/react';
|
|
145
|
+
|
|
146
|
+
function ConsentBanner() {
|
|
147
|
+
const { setConsent, getConsentState } = useConsent();
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<button onClick={() => setConsent({ analytics: true, advertising: false })}>
|
|
151
|
+
Accept Analytics Only
|
|
152
|
+
</button>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### `useLayers()`
|
|
158
|
+
|
|
159
|
+
Returns the raw `LayersClient` instance for advanced usage:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import { useLayers } from '@layers/client/react';
|
|
163
|
+
|
|
164
|
+
function Advanced() {
|
|
165
|
+
const layers = useLayers();
|
|
166
|
+
// layers.setUserProperties({ plan: 'pro' });
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Error Handling
|
|
171
|
+
|
|
172
|
+
Register error listeners to catch errors from `track()`, `screen()`, and `flush()` that would otherwise be silently dropped:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const layers = new LayersClient({ ... });
|
|
176
|
+
|
|
177
|
+
layers.on('error', (err) => {
|
|
178
|
+
console.error('Layers SDK error:', err.message);
|
|
179
|
+
// Send to your error reporting service
|
|
23
180
|
});
|
|
24
181
|
|
|
25
|
-
|
|
26
|
-
|
|
182
|
+
// Remove a specific listener
|
|
183
|
+
layers.off('error', myListener);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
When `enableDebug` is `true` and no error listeners are registered, errors are logged to `console.warn`.
|
|
187
|
+
|
|
188
|
+
## Consent Management
|
|
189
|
+
|
|
190
|
+
Control what data the SDK collects:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
// Allow analytics, deny advertising
|
|
194
|
+
layers.setConsent({ analytics: true, advertising: false });
|
|
195
|
+
|
|
196
|
+
// Check current state
|
|
197
|
+
const consent = layers.getConsentState();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
When `analytics` is `false`, `track()` and `screen()` calls are silently dropped.
|
|
201
|
+
|
|
202
|
+
## Page Lifecycle (sendBeacon)
|
|
203
|
+
|
|
204
|
+
The SDK automatically flushes events when the page becomes hidden using `navigator.sendBeacon()` for reliable delivery. If `sendBeacon` fails, events are persisted to localStorage and retried on the next page load.
|
|
205
|
+
|
|
206
|
+
On `beforeunload`, events are synchronously written to localStorage as a last resort.
|
|
207
|
+
|
|
208
|
+
## Debug Mode
|
|
209
|
+
|
|
210
|
+
Enable `enableDebug: true` to see detailed logs for every SDK operation:
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
[Layers] track("button_click", 2 properties)
|
|
214
|
+
[Layers] screen("home_page", 0 properties)
|
|
215
|
+
[Layers] setAppUserId("user-123")
|
|
27
216
|
```
|
|
28
217
|
|
|
29
|
-
##
|
|
218
|
+
## Server-Side Rendering
|
|
30
219
|
|
|
31
|
-
-
|
|
32
|
-
- Issues: https://github.com/layersai/sdks/issues
|
|
220
|
+
The SDK safely handles SSR environments where `window`, `document`, and `navigator` are unavailable. Device detection and lifecycle listeners are skipped in SSR. For server-side tracking, use [@layers/node](../node) instead.
|
|
33
221
|
|
|
34
222
|
## License
|
|
35
223
|
|
|
36
|
-
|
|
224
|
+
MIT
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
//#region ../wasm/src/types.d.ts
|
|
2
|
+
type Environment = 'development' | 'staging' | 'production';
|
|
3
|
+
type Platform = 'ios' | 'android' | 'react-native' | 'web' | 'node' | 'flutter' | 'macos';
|
|
4
|
+
interface DeviceContext {
|
|
5
|
+
platform?: Platform;
|
|
6
|
+
osVersion?: string;
|
|
7
|
+
appVersion?: string;
|
|
8
|
+
deviceModel?: string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
buildNumber?: string;
|
|
11
|
+
screenSize?: string;
|
|
12
|
+
installId?: string;
|
|
13
|
+
idfa?: string;
|
|
14
|
+
idfv?: string;
|
|
15
|
+
attStatus?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ConsentState {
|
|
18
|
+
analytics?: boolean | null;
|
|
19
|
+
advertising?: boolean | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Event properties attached to track/screen calls.
|
|
23
|
+
*
|
|
24
|
+
* Supported value types:
|
|
25
|
+
* - `string` — text values (max 64 KB per value)
|
|
26
|
+
* - `number` — integers and floating-point numbers
|
|
27
|
+
* - `boolean` — true/false flags
|
|
28
|
+
* - `null` — explicit null to clear a property
|
|
29
|
+
* - Nested `Record<string, unknown>` objects (one level deep recommended)
|
|
30
|
+
*
|
|
31
|
+
* Keys must be plain strings (max 128 chars). Prototype-pollution keys
|
|
32
|
+
* (`__proto__`, `constructor`, `prototype`) are rejected. Maximum 100 keys
|
|
33
|
+
* per call, 1 MB total payload.
|
|
34
|
+
*/
|
|
35
|
+
interface EventProperties {
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* User properties set via `setUserProperties()`.
|
|
40
|
+
*
|
|
41
|
+
* Supported value types:
|
|
42
|
+
* - `string` — text values (max 64 KB per value)
|
|
43
|
+
* - `number` — integers and floating-point numbers
|
|
44
|
+
* - `boolean` — true/false flags
|
|
45
|
+
* - `null` — explicit null to clear a property
|
|
46
|
+
* - Nested `Record<string, unknown>` objects (one level deep recommended)
|
|
47
|
+
*
|
|
48
|
+
* Keys must be plain strings (max 128 chars). Prototype-pollution keys
|
|
49
|
+
* (`__proto__`, `constructor`, `prototype`) are rejected. Maximum 100 keys
|
|
50
|
+
* per call.
|
|
51
|
+
*/
|
|
52
|
+
interface UserProperties {
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
}
|
|
55
|
+
type LayersErrorCode = 'NOT_INITIALIZED' | 'ALREADY_INITIALIZED' | 'SHUT_DOWN' | 'INVALID_CONFIG' | 'INVALID_ARGUMENT' | 'QUEUE_FULL' | 'SERIALIZATION' | 'NETWORK' | 'HTTP' | 'CIRCUIT_OPEN' | 'RATE_LIMITED' | 'CONSENT_NOT_GRANTED' | 'PERSISTENCE' | 'REMOTE_CONFIG' | 'EVENT_DENIED' | 'INTERNAL';
|
|
56
|
+
declare class LayersError extends Error {
|
|
57
|
+
readonly code: LayersErrorCode;
|
|
58
|
+
readonly status?: number;
|
|
59
|
+
constructor(code: LayersErrorCode, message: string, status?: number);
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/api-types.d.ts
|
|
63
|
+
interface BaseEvent {
|
|
64
|
+
event: string;
|
|
65
|
+
timestamp: string;
|
|
66
|
+
event_id?: string;
|
|
67
|
+
app_id: string;
|
|
68
|
+
app_user_id?: string;
|
|
69
|
+
user_id?: string;
|
|
70
|
+
anonymous_id?: string;
|
|
71
|
+
session_id?: string;
|
|
72
|
+
environment: 'development' | 'staging' | 'production';
|
|
73
|
+
platform: 'ios' | 'android' | 'react-native' | 'web' | 'node' | 'flutter' | 'macos';
|
|
74
|
+
os_version: string;
|
|
75
|
+
app_version: string;
|
|
76
|
+
build_number?: string;
|
|
77
|
+
device_model: string;
|
|
78
|
+
screen_size?: string;
|
|
79
|
+
locale: string;
|
|
80
|
+
install_id?: string;
|
|
81
|
+
install_source?: string;
|
|
82
|
+
campaign_hint?: string;
|
|
83
|
+
referrer?: string;
|
|
84
|
+
referrer_source?: string;
|
|
85
|
+
utm_source?: string;
|
|
86
|
+
utm_medium?: string;
|
|
87
|
+
utm_campaign?: string;
|
|
88
|
+
utm_content?: string;
|
|
89
|
+
utm_term?: string;
|
|
90
|
+
click_id_param?: string;
|
|
91
|
+
idfa?: string;
|
|
92
|
+
idfv?: string;
|
|
93
|
+
att_status?: 'authorized' | 'denied' | 'restricted' | 'not_determined';
|
|
94
|
+
country_code?: string;
|
|
95
|
+
subdivision1_code?: string;
|
|
96
|
+
properties?: Record<string, unknown>;
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
}
|
|
99
|
+
interface EventsBatchPayload {
|
|
100
|
+
events: BaseEvent[];
|
|
101
|
+
batch_id?: string;
|
|
102
|
+
sent_at: string;
|
|
103
|
+
}
|
|
104
|
+
interface UserPropertiesPayload {
|
|
105
|
+
app_user_id?: string;
|
|
106
|
+
user_id?: string;
|
|
107
|
+
app_id: string;
|
|
108
|
+
properties: Record<string, unknown>;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
}
|
|
111
|
+
interface ConsentPayload {
|
|
112
|
+
app_user_id?: string;
|
|
113
|
+
user_id?: string;
|
|
114
|
+
app_id: string;
|
|
115
|
+
consent: {
|
|
116
|
+
advertising?: boolean | null;
|
|
117
|
+
analytics?: boolean | null;
|
|
118
|
+
};
|
|
119
|
+
att_status?: 'authorized' | 'denied' | 'restricted' | 'not_determined';
|
|
120
|
+
timestamp: string;
|
|
121
|
+
}
|
|
122
|
+
interface RemoteConfigResponse {
|
|
123
|
+
config: {
|
|
124
|
+
att?: {
|
|
125
|
+
strategy: 'immediate' | 'after_onboarding' | 'after_paywall_view' | 'manual';
|
|
126
|
+
prompt_copy?: {
|
|
127
|
+
title?: string;
|
|
128
|
+
message?: string;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
skan?: {
|
|
132
|
+
preset?: 'subscriptions' | 'engagement' | 'iap';
|
|
133
|
+
rules?: Record<string, unknown>;
|
|
134
|
+
lock_policy?: string;
|
|
135
|
+
};
|
|
136
|
+
events?: {
|
|
137
|
+
allowlist?: string[];
|
|
138
|
+
denylist?: string[];
|
|
139
|
+
sampling?: Record<string, number>;
|
|
140
|
+
sampling_rate?: number;
|
|
141
|
+
rate_limit?: {
|
|
142
|
+
per_minute?: number;
|
|
143
|
+
per_hour?: number;
|
|
144
|
+
per_event?: Record<string, {
|
|
145
|
+
per_minute?: number;
|
|
146
|
+
per_hour?: number;
|
|
147
|
+
}>;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
connectors?: Record<string, {
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
app_id?: string;
|
|
153
|
+
pixel_id?: string;
|
|
154
|
+
test_mode?: boolean;
|
|
155
|
+
}>;
|
|
156
|
+
deeplinks?: {
|
|
157
|
+
allowed_hosts?: string[];
|
|
158
|
+
behavior?: string;
|
|
159
|
+
};
|
|
160
|
+
privacy?: {
|
|
161
|
+
killswitches?: string[];
|
|
162
|
+
analytics_enabled?: boolean;
|
|
163
|
+
advertising_enabled?: boolean;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
version: string;
|
|
167
|
+
cache_ttl: number;
|
|
168
|
+
}
|
|
169
|
+
interface SKANPostbackPayload {
|
|
170
|
+
app_id: string;
|
|
171
|
+
version: string;
|
|
172
|
+
ad_network_id: string;
|
|
173
|
+
campaign_id?: string;
|
|
174
|
+
source_app_id?: string;
|
|
175
|
+
conversion_value?: number;
|
|
176
|
+
coarse_conversion_value?: string;
|
|
177
|
+
lock_window?: boolean;
|
|
178
|
+
postback_sequence_index?: number;
|
|
179
|
+
did_win?: boolean;
|
|
180
|
+
timestamp: string;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/attribution.d.ts
|
|
184
|
+
interface AttributionData {
|
|
185
|
+
click_id_param?: string;
|
|
186
|
+
click_id_value?: string;
|
|
187
|
+
utm_source?: string;
|
|
188
|
+
utm_medium?: string;
|
|
189
|
+
utm_campaign?: string;
|
|
190
|
+
utm_content?: string;
|
|
191
|
+
utm_term?: string;
|
|
192
|
+
referrer_url?: string;
|
|
193
|
+
captured_at: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Read stored attribution data, returning null if missing or expired.
|
|
197
|
+
*/
|
|
198
|
+
declare function getAttribution(): AttributionData | null;
|
|
199
|
+
/**
|
|
200
|
+
* Return a flat property bag suitable for merging into event properties.
|
|
201
|
+
* Keys are prefixed with `$attribution_` to avoid collisions.
|
|
202
|
+
*/
|
|
203
|
+
declare function getAttributionProperties(): Record<string, string>;
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/index.d.ts
|
|
206
|
+
interface LayersConfig {
|
|
207
|
+
/** API key used to authenticate requests to the Layers ingest endpoint. */
|
|
208
|
+
apiKey: string;
|
|
209
|
+
/** Unique application identifier issued by the Layers dashboard. */
|
|
210
|
+
appId: string;
|
|
211
|
+
/** Deployment environment label. @default "production" */
|
|
212
|
+
environment: Environment;
|
|
213
|
+
/** Optional user identifier to associate events with from the start. */
|
|
214
|
+
appUserId?: string;
|
|
215
|
+
/** Enable verbose debug logging to the console. @default false */
|
|
216
|
+
enableDebug?: boolean;
|
|
217
|
+
/** Base URL for the Layers ingest API. @default "https://in.layers.com" */
|
|
218
|
+
baseUrl?: string;
|
|
219
|
+
/** How often the event queue is flushed, in milliseconds. @default 30000 */
|
|
220
|
+
flushIntervalMs?: number;
|
|
221
|
+
/** Number of queued events that triggers an automatic flush. @default 10 */
|
|
222
|
+
flushThreshold?: number;
|
|
223
|
+
/** Maximum number of events to hold in the queue before dropping. @default 1000 */
|
|
224
|
+
maxQueueSize?: number;
|
|
225
|
+
}
|
|
226
|
+
type ErrorListener = (error: Error) => void;
|
|
227
|
+
declare class LayersClient {
|
|
228
|
+
private core;
|
|
229
|
+
private appUserId;
|
|
230
|
+
private isOnline;
|
|
231
|
+
private readonly enableDebug;
|
|
232
|
+
private readonly baseUrl;
|
|
233
|
+
private onlineListener;
|
|
234
|
+
private offlineListener;
|
|
235
|
+
private visibilityListener;
|
|
236
|
+
private beforeUnloadListener;
|
|
237
|
+
private readonly errorListeners;
|
|
238
|
+
constructor(config: LayersConfig);
|
|
239
|
+
/** Initialize the client: detects device info, attaches lifecycle listeners, and fetches remote config. */
|
|
240
|
+
init(): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* Record a custom analytics event with an optional property bag.
|
|
243
|
+
*
|
|
244
|
+
* Events are batched and flushed automatically when the queue reaches
|
|
245
|
+
* `flushThreshold` or the periodic flush timer fires.
|
|
246
|
+
*/
|
|
247
|
+
track(eventName: string, properties?: EventProperties): void;
|
|
248
|
+
/**
|
|
249
|
+
* Record a screen view event with an optional property bag.
|
|
250
|
+
*
|
|
251
|
+
* Events are batched and flushed automatically when the queue reaches
|
|
252
|
+
* `flushThreshold` or the periodic flush timer fires.
|
|
253
|
+
*/
|
|
254
|
+
screen(screenName: string, properties?: EventProperties): void;
|
|
255
|
+
/** Set or update user-level properties that persist across sessions. */
|
|
256
|
+
setUserProperties(properties: UserProperties): void;
|
|
257
|
+
/** Update the user's consent state for analytics and advertising data collection. */
|
|
258
|
+
setConsent(consent: ConsentState): void;
|
|
259
|
+
/** Associate all subsequent events with the given user ID, or clear it with `undefined`. */
|
|
260
|
+
setAppUserId(appUserId: string | undefined): void;
|
|
261
|
+
/** @deprecated Use setAppUserId instead */
|
|
262
|
+
setUserId(userId: string): void;
|
|
263
|
+
/** Return the current app user ID, or `undefined` if not set. */
|
|
264
|
+
getAppUserId(): string | undefined;
|
|
265
|
+
/** @deprecated Use getAppUserId instead */
|
|
266
|
+
getUserId(): string | undefined;
|
|
267
|
+
/** Return the current anonymous session ID. */
|
|
268
|
+
getSessionId(): string;
|
|
269
|
+
/** Return the current consent state for analytics and advertising. */
|
|
270
|
+
getConsentState(): ConsentState;
|
|
271
|
+
/** Override device-level context fields (platform, OS, locale, etc.). */
|
|
272
|
+
setDeviceInfo(deviceInfo: DeviceContext): void;
|
|
273
|
+
/** Flush all queued events to the server. Falls back to synchronous persistence on failure. */
|
|
274
|
+
flush(): Promise<void>;
|
|
275
|
+
/** Immediately shut down the client, removing all event listeners. Queued events are persisted but not flushed. */
|
|
276
|
+
shutdown(): void;
|
|
277
|
+
/**
|
|
278
|
+
* Async shutdown: flushes remaining events before shutting down.
|
|
279
|
+
* @param timeoutMs Maximum time to wait for flush (default 3000ms).
|
|
280
|
+
*/
|
|
281
|
+
shutdownAsync(timeoutMs?: number): Promise<void>;
|
|
282
|
+
private cleanupListeners;
|
|
283
|
+
/** End the current session and start a new one with a fresh session ID. */
|
|
284
|
+
startNewSession(): void;
|
|
285
|
+
/**
|
|
286
|
+
* Register an error listener. Errors from track/screen/flush
|
|
287
|
+
* that would otherwise be silently dropped are forwarded here.
|
|
288
|
+
*/
|
|
289
|
+
on(event: 'error', listener: ErrorListener): this;
|
|
290
|
+
/**
|
|
291
|
+
* Remove a previously registered error listener.
|
|
292
|
+
*/
|
|
293
|
+
off(event: 'error', listener: ErrorListener): this;
|
|
294
|
+
private emitError;
|
|
295
|
+
private initializeDeviceInfo;
|
|
296
|
+
private detectOS;
|
|
297
|
+
private detectDeviceModel;
|
|
298
|
+
private detectLocale;
|
|
299
|
+
private detectScreenSize;
|
|
300
|
+
private setupNetworkListener;
|
|
301
|
+
private getBeaconUrl;
|
|
302
|
+
private setupLifecycleListeners;
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
export { LayersError as _, getAttribution as a, ConsentPayload as c, SKANPostbackPayload as d, UserPropertiesPayload as f, EventProperties as g, Environment as h, AttributionData as i, EventsBatchPayload as l, DeviceContext as m, LayersClient as n, getAttributionProperties as o, ConsentState as p, LayersConfig as r, BaseEvent as s, ErrorListener as t, RemoteConfigResponse as u, UserProperties as v };
|
|
306
|
+
//# sourceMappingURL=index-C1d8NEFV.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-C1d8NEFV.d.ts","names":[],"sources":["../../wasm/src/types.ts","../src/api-types.ts","../src/attribution.ts","../src/index.ts"],"sourcesContent":[],"mappings":";KAGY,WAAA;AAAA,KAEA,QAAA,GAFW,KAAA,GAAA,SAAA,GAAA,cAAA,GAAA,KAAA,GAAA,MAAA,GAAA,SAAA,GAAA,OAAA;UAiBN,aAAA;aACJ;EClBI,SAAA,CAAA,E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A;;;ADjBN,UGnCA,YAAA,CHmCc;EAsBnB;EAkBC,MAAA,EAAA,MAAY;EACR;EAGG,KAAA,EAAA,MAAA;EAJa;EAAK,WAAA,EGrEvB,WHqEuB;;;;EC5GrB,WAAA,CAAS,EAAA,OAAA;EAqCT;EAMA,OAAA,CAAA,EAAA,MAAA;EAQA;EAYA,eAAA,CAAA,EAAA,MAAoB;EAQvB;EAMG,cAAA,CAAA,EAAA,MAAA;EAKG;EAGH,YAAA,CAAA,EAAA,MAAA;;AAkBA,KEjDL,aAAA,GFiDwB,CAAA,KAAA,EEjDA,KFiDA,EAAA,GAAA,IAAA;cE/CvB,YAAA;;;ED9CI,QAAA,QAAA;EAkGD,iBAAc,WAAA;EAsBd,iBAAA,OAAA;;;;ECjGC,QAAA,oBAMF;EAeH,iBAAa,cAAW;EAEvB,WAAA,CAAA,MAAY,EAgBH,YAhBG;EAgBH;EA8BN,IAAA,CAAA,CAAA,EAAA,OAAA,CAAA,IAAA,CAAA;EAgBwB;;;;;;EAwFvB,KAAA,CAAA,SAAA,EAAA,MAAA,EAAA,UAAA,CAAA,EAxFuB,eAwFvB,CAAA,EAAA,IAAA;EAmBwB;;;;;;0CAvFC;;gCAeV;;sBAKV;;;;;;;;;;;;qBAsCD;;4BAKO;;WAKX;;;;;;;qCAmBwB;;;;;;;;+BA2CV;;;;gCAQC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as LayersError, a as getAttribution, c as ConsentPayload, d as SKANPostbackPayload, f as UserPropertiesPayload, g as EventProperties, h as Environment, i as AttributionData, l as EventsBatchPayload, m as DeviceContext, n as LayersClient, o as getAttributionProperties, p as ConsentState, r as LayersConfig, s as BaseEvent, t as ErrorListener, u as RemoteConfigResponse, v as UserProperties } from "./index-C1d8NEFV.js";
|
|
2
|
+
export { AttributionData, BaseEvent, ConsentPayload, ConsentState, DeviceContext, Environment, ErrorListener, EventProperties, EventsBatchPayload, LayersClient, LayersConfig, LayersError, RemoteConfigResponse, SKANPostbackPayload, UserProperties, UserPropertiesPayload, getAttribution, getAttributionProperties };
|