@sendmailos/sdk 1.0.0 → 1.1.1
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 +119 -1
- package/dist/index.d.mts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +379 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +377 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +159 -1
- package/dist/react/index.d.ts +159 -1
- package/dist/react/index.js +408 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +407 -2
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -137,4 +137,162 @@ interface SubscribeFormProps {
|
|
|
137
137
|
*/
|
|
138
138
|
declare function SubscribeForm({ tags, onSuccess, onError, className, placeholder, buttonText, loadingText, successMessage, showNameFields, style, }: SubscribeFormProps): react_jsx_runtime.JSX.Element;
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
interface PixelConfig {
|
|
141
|
+
/** Public API key (pk_live_... or pk_test_...) or legacy token */
|
|
142
|
+
token: string;
|
|
143
|
+
/** API endpoint for tracking events */
|
|
144
|
+
endpoint?: string;
|
|
145
|
+
/** Cookie name for anonymous ID storage */
|
|
146
|
+
cookieName?: string;
|
|
147
|
+
/** Enable debug logging */
|
|
148
|
+
debug?: boolean;
|
|
149
|
+
/** Respect Do Not Track browser setting (default: true) */
|
|
150
|
+
respectDNT?: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface TrackProps {
|
|
153
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
154
|
+
}
|
|
155
|
+
/** Traits for identify calls */
|
|
156
|
+
interface IdentifyTraits {
|
|
157
|
+
first_name?: string;
|
|
158
|
+
last_name?: string;
|
|
159
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
160
|
+
}
|
|
161
|
+
declare class SendmailPixel {
|
|
162
|
+
private config;
|
|
163
|
+
private anonymousId;
|
|
164
|
+
private initialized;
|
|
165
|
+
private rules;
|
|
166
|
+
private identifiedEmail;
|
|
167
|
+
constructor(config: PixelConfig);
|
|
168
|
+
init(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Opt out of all tracking
|
|
171
|
+
*/
|
|
172
|
+
optOut(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Opt back in to tracking
|
|
175
|
+
*/
|
|
176
|
+
optIn(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Check if user has opted out
|
|
179
|
+
*/
|
|
180
|
+
isOptedOut(): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Reset identity (e.g., on logout)
|
|
183
|
+
*/
|
|
184
|
+
reset(): void;
|
|
185
|
+
/**
|
|
186
|
+
* Get current visitor/anonymous ID
|
|
187
|
+
*/
|
|
188
|
+
getVisitorId(): string;
|
|
189
|
+
/**
|
|
190
|
+
* Get identified email address
|
|
191
|
+
*/
|
|
192
|
+
getIdentifiedEmail(): string | null;
|
|
193
|
+
track(eventName: string, properties?: TrackProps): void;
|
|
194
|
+
identify(email: string, traits?: TrackProps): void;
|
|
195
|
+
pageView(): void;
|
|
196
|
+
private getOrSetAnonymousId;
|
|
197
|
+
private sendEvent;
|
|
198
|
+
loadRules(): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Smart Auto-Detection of Page Type & Context
|
|
201
|
+
* Uses Dynamic Rules + Static Heuristics
|
|
202
|
+
*/
|
|
203
|
+
private detectContext;
|
|
204
|
+
private setupFormListeners;
|
|
205
|
+
private setupHistoryListeners;
|
|
206
|
+
private setCookie;
|
|
207
|
+
private getCookie;
|
|
208
|
+
private log;
|
|
209
|
+
private isDNTEnabled;
|
|
210
|
+
private checkUrlForSubscriber;
|
|
211
|
+
private setupDataAttributeTracking;
|
|
212
|
+
private getStoredEmail;
|
|
213
|
+
private storeEmail;
|
|
214
|
+
private isValidEmail;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* React hook for SendMailOS Pixel tracking
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
interface UsePixelOptions extends Omit<PixelConfig, 'token'> {
|
|
222
|
+
}
|
|
223
|
+
interface UsePixelReturn {
|
|
224
|
+
/** Track a custom event */
|
|
225
|
+
track: (eventName: string, properties?: TrackProps) => void;
|
|
226
|
+
/** Track a page view */
|
|
227
|
+
page: () => void;
|
|
228
|
+
/** Identify a user by email */
|
|
229
|
+
identify: (email: string, traits?: IdentifyTraits) => void;
|
|
230
|
+
/** Opt out of tracking */
|
|
231
|
+
optOut: () => void;
|
|
232
|
+
/** Opt back in to tracking */
|
|
233
|
+
optIn: () => void;
|
|
234
|
+
/** Check if opted out */
|
|
235
|
+
isOptedOut: () => boolean;
|
|
236
|
+
/** Reset identity (e.g., on logout) */
|
|
237
|
+
reset: () => void;
|
|
238
|
+
/** Get current visitor ID */
|
|
239
|
+
getVisitorId: () => string | null;
|
|
240
|
+
/** Pixel instance (for advanced usage) */
|
|
241
|
+
pixel: SendmailPixel | null;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* React hook for pixel tracking
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```tsx
|
|
248
|
+
* import { usePixel } from '@sendmailos/sdk/react';
|
|
249
|
+
*
|
|
250
|
+
* function MyComponent() {
|
|
251
|
+
* const { track, identify } = usePixel('pk_live_...');
|
|
252
|
+
*
|
|
253
|
+
* const handleClick = () => {
|
|
254
|
+
* track('button_clicked', { button_id: 'cta' });
|
|
255
|
+
* };
|
|
256
|
+
*
|
|
257
|
+
* return <button onClick={handleClick}>Click me</button>;
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare function usePixel(token: string, options?: UsePixelOptions): UsePixelReturn;
|
|
262
|
+
/**
|
|
263
|
+
* Hook to track page views on route changes
|
|
264
|
+
* Useful for Next.js App Router or React Router
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```tsx
|
|
268
|
+
* import { usePageTracking } from '@sendmailos/sdk/react';
|
|
269
|
+
* import { usePathname } from 'next/navigation';
|
|
270
|
+
*
|
|
271
|
+
* function Layout({ children }) {
|
|
272
|
+
* const pathname = usePathname();
|
|
273
|
+
* usePageTracking('pk_live_...', pathname);
|
|
274
|
+
* return children;
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function usePageTracking(token: string, pathname: string, options?: UsePixelOptions): void;
|
|
279
|
+
/**
|
|
280
|
+
* Hook to identify user when they log in
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```tsx
|
|
284
|
+
* import { useIdentifyOnLogin } from '@sendmailos/sdk/react';
|
|
285
|
+
*
|
|
286
|
+
* function App() {
|
|
287
|
+
* const { user } = useAuth();
|
|
288
|
+
* useIdentifyOnLogin('pk_live_...', user?.email, {
|
|
289
|
+
* first_name: user?.firstName,
|
|
290
|
+
* plan: user?.plan,
|
|
291
|
+
* });
|
|
292
|
+
* return <Main />;
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
declare function useIdentifyOnLogin(token: string, email: string | null | undefined, traits?: IdentifyTraits, options?: UsePixelOptions): void;
|
|
297
|
+
|
|
298
|
+
export { SendMailOSProvider, SubscribeForm, type SubscribeFormProps, type UsePixelOptions, type UsePixelReturn, useIdentifyOnLogin, usePageTracking, usePixel, useSendMailOS, useSubscribe };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -137,4 +137,162 @@ interface SubscribeFormProps {
|
|
|
137
137
|
*/
|
|
138
138
|
declare function SubscribeForm({ tags, onSuccess, onError, className, placeholder, buttonText, loadingText, successMessage, showNameFields, style, }: SubscribeFormProps): react_jsx_runtime.JSX.Element;
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
interface PixelConfig {
|
|
141
|
+
/** Public API key (pk_live_... or pk_test_...) or legacy token */
|
|
142
|
+
token: string;
|
|
143
|
+
/** API endpoint for tracking events */
|
|
144
|
+
endpoint?: string;
|
|
145
|
+
/** Cookie name for anonymous ID storage */
|
|
146
|
+
cookieName?: string;
|
|
147
|
+
/** Enable debug logging */
|
|
148
|
+
debug?: boolean;
|
|
149
|
+
/** Respect Do Not Track browser setting (default: true) */
|
|
150
|
+
respectDNT?: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface TrackProps {
|
|
153
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
154
|
+
}
|
|
155
|
+
/** Traits for identify calls */
|
|
156
|
+
interface IdentifyTraits {
|
|
157
|
+
first_name?: string;
|
|
158
|
+
last_name?: string;
|
|
159
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
160
|
+
}
|
|
161
|
+
declare class SendmailPixel {
|
|
162
|
+
private config;
|
|
163
|
+
private anonymousId;
|
|
164
|
+
private initialized;
|
|
165
|
+
private rules;
|
|
166
|
+
private identifiedEmail;
|
|
167
|
+
constructor(config: PixelConfig);
|
|
168
|
+
init(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Opt out of all tracking
|
|
171
|
+
*/
|
|
172
|
+
optOut(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Opt back in to tracking
|
|
175
|
+
*/
|
|
176
|
+
optIn(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Check if user has opted out
|
|
179
|
+
*/
|
|
180
|
+
isOptedOut(): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Reset identity (e.g., on logout)
|
|
183
|
+
*/
|
|
184
|
+
reset(): void;
|
|
185
|
+
/**
|
|
186
|
+
* Get current visitor/anonymous ID
|
|
187
|
+
*/
|
|
188
|
+
getVisitorId(): string;
|
|
189
|
+
/**
|
|
190
|
+
* Get identified email address
|
|
191
|
+
*/
|
|
192
|
+
getIdentifiedEmail(): string | null;
|
|
193
|
+
track(eventName: string, properties?: TrackProps): void;
|
|
194
|
+
identify(email: string, traits?: TrackProps): void;
|
|
195
|
+
pageView(): void;
|
|
196
|
+
private getOrSetAnonymousId;
|
|
197
|
+
private sendEvent;
|
|
198
|
+
loadRules(): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Smart Auto-Detection of Page Type & Context
|
|
201
|
+
* Uses Dynamic Rules + Static Heuristics
|
|
202
|
+
*/
|
|
203
|
+
private detectContext;
|
|
204
|
+
private setupFormListeners;
|
|
205
|
+
private setupHistoryListeners;
|
|
206
|
+
private setCookie;
|
|
207
|
+
private getCookie;
|
|
208
|
+
private log;
|
|
209
|
+
private isDNTEnabled;
|
|
210
|
+
private checkUrlForSubscriber;
|
|
211
|
+
private setupDataAttributeTracking;
|
|
212
|
+
private getStoredEmail;
|
|
213
|
+
private storeEmail;
|
|
214
|
+
private isValidEmail;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* React hook for SendMailOS Pixel tracking
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
interface UsePixelOptions extends Omit<PixelConfig, 'token'> {
|
|
222
|
+
}
|
|
223
|
+
interface UsePixelReturn {
|
|
224
|
+
/** Track a custom event */
|
|
225
|
+
track: (eventName: string, properties?: TrackProps) => void;
|
|
226
|
+
/** Track a page view */
|
|
227
|
+
page: () => void;
|
|
228
|
+
/** Identify a user by email */
|
|
229
|
+
identify: (email: string, traits?: IdentifyTraits) => void;
|
|
230
|
+
/** Opt out of tracking */
|
|
231
|
+
optOut: () => void;
|
|
232
|
+
/** Opt back in to tracking */
|
|
233
|
+
optIn: () => void;
|
|
234
|
+
/** Check if opted out */
|
|
235
|
+
isOptedOut: () => boolean;
|
|
236
|
+
/** Reset identity (e.g., on logout) */
|
|
237
|
+
reset: () => void;
|
|
238
|
+
/** Get current visitor ID */
|
|
239
|
+
getVisitorId: () => string | null;
|
|
240
|
+
/** Pixel instance (for advanced usage) */
|
|
241
|
+
pixel: SendmailPixel | null;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* React hook for pixel tracking
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```tsx
|
|
248
|
+
* import { usePixel } from '@sendmailos/sdk/react';
|
|
249
|
+
*
|
|
250
|
+
* function MyComponent() {
|
|
251
|
+
* const { track, identify } = usePixel('pk_live_...');
|
|
252
|
+
*
|
|
253
|
+
* const handleClick = () => {
|
|
254
|
+
* track('button_clicked', { button_id: 'cta' });
|
|
255
|
+
* };
|
|
256
|
+
*
|
|
257
|
+
* return <button onClick={handleClick}>Click me</button>;
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare function usePixel(token: string, options?: UsePixelOptions): UsePixelReturn;
|
|
262
|
+
/**
|
|
263
|
+
* Hook to track page views on route changes
|
|
264
|
+
* Useful for Next.js App Router or React Router
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```tsx
|
|
268
|
+
* import { usePageTracking } from '@sendmailos/sdk/react';
|
|
269
|
+
* import { usePathname } from 'next/navigation';
|
|
270
|
+
*
|
|
271
|
+
* function Layout({ children }) {
|
|
272
|
+
* const pathname = usePathname();
|
|
273
|
+
* usePageTracking('pk_live_...', pathname);
|
|
274
|
+
* return children;
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function usePageTracking(token: string, pathname: string, options?: UsePixelOptions): void;
|
|
279
|
+
/**
|
|
280
|
+
* Hook to identify user when they log in
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```tsx
|
|
284
|
+
* import { useIdentifyOnLogin } from '@sendmailos/sdk/react';
|
|
285
|
+
*
|
|
286
|
+
* function App() {
|
|
287
|
+
* const { user } = useAuth();
|
|
288
|
+
* useIdentifyOnLogin('pk_live_...', user?.email, {
|
|
289
|
+
* first_name: user?.firstName,
|
|
290
|
+
* plan: user?.plan,
|
|
291
|
+
* });
|
|
292
|
+
* return <Main />;
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
declare function useIdentifyOnLogin(token: string, email: string | null | undefined, traits?: IdentifyTraits, options?: UsePixelOptions): void;
|
|
297
|
+
|
|
298
|
+
export { SendMailOSProvider, SubscribeForm, type SubscribeFormProps, type UsePixelOptions, type UsePixelReturn, useIdentifyOnLogin, usePageTracking, usePixel, useSendMailOS, useSubscribe };
|