@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/README.md
CHANGED
|
@@ -33,7 +33,8 @@ await client.emails.send({
|
|
|
33
33
|
|
|
34
34
|
- **Type-safe**: Full TypeScript support with exported types
|
|
35
35
|
- **Lightweight**: Zero dependencies for core SDK
|
|
36
|
-
- **
|
|
36
|
+
- **Pixel Tracking**: Track website visitors and link to email campaigns
|
|
37
|
+
- **React Components**: Pre-built components and hooks
|
|
37
38
|
- **Webhook Verification**: Secure signature verification utilities
|
|
38
39
|
- **Error Handling**: Custom error classes for different scenarios
|
|
39
40
|
|
|
@@ -101,6 +102,123 @@ const { domain } = await client.domains.create({
|
|
|
101
102
|
console.log('DNS Records to add:', domain.dnsRecords);
|
|
102
103
|
```
|
|
103
104
|
|
|
105
|
+
## Pixel Tracking
|
|
106
|
+
|
|
107
|
+
Track website visitors and connect their behavior to email campaigns.
|
|
108
|
+
|
|
109
|
+
### Basic Setup
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { SendmailPixel } from '@sendmailos/sdk';
|
|
113
|
+
|
|
114
|
+
const pixel = new SendmailPixel({
|
|
115
|
+
token: 'pk_live_your_public_key',
|
|
116
|
+
debug: false // Set true for console logging
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
pixel.init();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Track Events
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// Track custom events
|
|
126
|
+
pixel.track('button_clicked', { button_id: 'cta-signup' });
|
|
127
|
+
|
|
128
|
+
// Track page views (called automatically on init)
|
|
129
|
+
pixel.pageView();
|
|
130
|
+
|
|
131
|
+
// Identify a visitor by email
|
|
132
|
+
pixel.identify('user@example.com', {
|
|
133
|
+
first_name: 'John',
|
|
134
|
+
plan: 'premium'
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Privacy Controls
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// Opt out of tracking (e.g., user declines cookies)
|
|
142
|
+
pixel.optOut();
|
|
143
|
+
|
|
144
|
+
// Opt back in
|
|
145
|
+
pixel.optIn();
|
|
146
|
+
|
|
147
|
+
// Check opt-out status
|
|
148
|
+
if (pixel.isOptedOut()) {
|
|
149
|
+
console.log('Tracking disabled');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Reset identity (e.g., on logout)
|
|
153
|
+
pixel.reset();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Global smp() Function
|
|
157
|
+
|
|
158
|
+
For script tag usage, use `createGlobalPixel` to set up a global `smp()` function:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { createGlobalPixel } from '@sendmailos/sdk';
|
|
162
|
+
|
|
163
|
+
createGlobalPixel({ token: 'pk_live_...' });
|
|
164
|
+
|
|
165
|
+
// Now use anywhere:
|
|
166
|
+
smp('track', 'event_name', { property: 'value' });
|
|
167
|
+
smp('identify', 'user@example.com');
|
|
168
|
+
smp('optOut');
|
|
169
|
+
smp('optIn');
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### React Pixel Hooks
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
import { usePixel, usePageTracking, useIdentifyOnLogin } from '@sendmailos/sdk/react';
|
|
176
|
+
|
|
177
|
+
// Basic usage
|
|
178
|
+
function MyComponent() {
|
|
179
|
+
const { track, identify, optOut } = usePixel('pk_live_...');
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<button onClick={() => track('button_clicked', { id: 'cta' })}>
|
|
183
|
+
Click Me
|
|
184
|
+
</button>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Auto page tracking (Next.js App Router)
|
|
189
|
+
function Layout({ children }) {
|
|
190
|
+
const pathname = usePathname();
|
|
191
|
+
usePageTracking('pk_live_...', pathname);
|
|
192
|
+
return <>{children}</>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Auto identify on login
|
|
196
|
+
function App() {
|
|
197
|
+
const { user } = useAuth();
|
|
198
|
+
useIdentifyOnLogin('pk_live_...', user?.email, {
|
|
199
|
+
first_name: user?.firstName,
|
|
200
|
+
plan: user?.plan
|
|
201
|
+
});
|
|
202
|
+
return <Main />;
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Data Attributes
|
|
207
|
+
|
|
208
|
+
Track clicks without JavaScript using HTML data attributes:
|
|
209
|
+
|
|
210
|
+
```html
|
|
211
|
+
<button data-smp-track="signup_clicked">Sign Up</button>
|
|
212
|
+
|
|
213
|
+
<button
|
|
214
|
+
data-smp-track="button_clicked"
|
|
215
|
+
data-smp-track-button-id="cta-main"
|
|
216
|
+
data-smp-track-variant="blue"
|
|
217
|
+
>
|
|
218
|
+
Get Started
|
|
219
|
+
</button>
|
|
220
|
+
```
|
|
221
|
+
|
|
104
222
|
## React Integration
|
|
105
223
|
|
|
106
224
|
```tsx
|
package/dist/index.d.mts
CHANGED
|
@@ -400,6 +400,93 @@ declare class SendMailOS {
|
|
|
400
400
|
static get version(): string;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
+
interface PixelConfig {
|
|
404
|
+
/** Public API key (pk_live_... or pk_test_...) or legacy token */
|
|
405
|
+
token: string;
|
|
406
|
+
/** API endpoint for tracking events */
|
|
407
|
+
endpoint?: string;
|
|
408
|
+
/** Cookie name for anonymous ID storage */
|
|
409
|
+
cookieName?: string;
|
|
410
|
+
/** Enable debug logging */
|
|
411
|
+
debug?: boolean;
|
|
412
|
+
/** Respect Do Not Track browser setting (default: true) */
|
|
413
|
+
respectDNT?: boolean;
|
|
414
|
+
}
|
|
415
|
+
/** Alias for PixelConfig for SDK consistency */
|
|
416
|
+
type PixelOptions = PixelConfig;
|
|
417
|
+
interface TrackProps {
|
|
418
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
419
|
+
}
|
|
420
|
+
/** Alias for TrackProps */
|
|
421
|
+
type TrackEventProperties = TrackProps;
|
|
422
|
+
/** Traits for identify calls */
|
|
423
|
+
interface IdentifyTraits {
|
|
424
|
+
first_name?: string;
|
|
425
|
+
last_name?: string;
|
|
426
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
427
|
+
}
|
|
428
|
+
declare class SendmailPixel {
|
|
429
|
+
private config;
|
|
430
|
+
private anonymousId;
|
|
431
|
+
private initialized;
|
|
432
|
+
private rules;
|
|
433
|
+
private identifiedEmail;
|
|
434
|
+
constructor(config: PixelConfig);
|
|
435
|
+
init(): void;
|
|
436
|
+
/**
|
|
437
|
+
* Opt out of all tracking
|
|
438
|
+
*/
|
|
439
|
+
optOut(): void;
|
|
440
|
+
/**
|
|
441
|
+
* Opt back in to tracking
|
|
442
|
+
*/
|
|
443
|
+
optIn(): void;
|
|
444
|
+
/**
|
|
445
|
+
* Check if user has opted out
|
|
446
|
+
*/
|
|
447
|
+
isOptedOut(): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Reset identity (e.g., on logout)
|
|
450
|
+
*/
|
|
451
|
+
reset(): void;
|
|
452
|
+
/**
|
|
453
|
+
* Get current visitor/anonymous ID
|
|
454
|
+
*/
|
|
455
|
+
getVisitorId(): string;
|
|
456
|
+
/**
|
|
457
|
+
* Get identified email address
|
|
458
|
+
*/
|
|
459
|
+
getIdentifiedEmail(): string | null;
|
|
460
|
+
track(eventName: string, properties?: TrackProps): void;
|
|
461
|
+
identify(email: string, traits?: TrackProps): void;
|
|
462
|
+
pageView(): void;
|
|
463
|
+
private getOrSetAnonymousId;
|
|
464
|
+
private sendEvent;
|
|
465
|
+
loadRules(): Promise<void>;
|
|
466
|
+
/**
|
|
467
|
+
* Smart Auto-Detection of Page Type & Context
|
|
468
|
+
* Uses Dynamic Rules + Static Heuristics
|
|
469
|
+
*/
|
|
470
|
+
private detectContext;
|
|
471
|
+
private setupFormListeners;
|
|
472
|
+
private setupHistoryListeners;
|
|
473
|
+
private setCookie;
|
|
474
|
+
private getCookie;
|
|
475
|
+
private log;
|
|
476
|
+
private isDNTEnabled;
|
|
477
|
+
private checkUrlForSubscriber;
|
|
478
|
+
private setupDataAttributeTracking;
|
|
479
|
+
private getStoredEmail;
|
|
480
|
+
private storeEmail;
|
|
481
|
+
private isValidEmail;
|
|
482
|
+
}
|
|
483
|
+
/** Alias for SendmailPixel for SDK consistency */
|
|
484
|
+
declare const Pixel: typeof SendmailPixel;
|
|
485
|
+
/**
|
|
486
|
+
* Create pixel and attach global smp() function
|
|
487
|
+
*/
|
|
488
|
+
declare function createGlobalPixel(config: PixelConfig): SendmailPixel;
|
|
489
|
+
|
|
403
490
|
/**
|
|
404
491
|
* Custom error classes for SendMailOS SDK
|
|
405
492
|
*/
|
|
@@ -477,4 +564,4 @@ declare function constructWebhookEvent<T = unknown>(payload: string, headers: {
|
|
|
477
564
|
timestamp: string;
|
|
478
565
|
}, secret: string): T;
|
|
479
566
|
|
|
480
|
-
export { type ApiError, AuthenticationError, type CreateDomainRequest, type CreateDomainResponse, type CreateSubscriberRequest, type CreateSubscriberResponse, type CreateWebhookRequest, type DnsRecord, type Domain, type ListDomainsResponse, type ListSubscribersRequest, type ListSubscribersResponse, NotFoundError, RateLimitError, type SendCampaignRequest, type SendCampaignResponse, type SendEmailRequest, type SendEmailResponse, SendMailOS, SendMailOSError, type SendMailOSOptions, type Subscriber, ValidationError, type VerifyWebhookParams, type Webhook, type WebhookEvent, type WebhookEventType, constructWebhookEvent, SendMailOS as default, verifyWebhookSignature, verifyWebhookSignatureAsync };
|
|
567
|
+
export { type ApiError, AuthenticationError, type CreateDomainRequest, type CreateDomainResponse, type CreateSubscriberRequest, type CreateSubscriberResponse, type CreateWebhookRequest, type DnsRecord, type Domain, type IdentifyTraits, type ListDomainsResponse, type ListSubscribersRequest, type ListSubscribersResponse, NotFoundError, Pixel, type PixelConfig, type PixelOptions, RateLimitError, type SendCampaignRequest, type SendCampaignResponse, type SendEmailRequest, type SendEmailResponse, SendMailOS, SendMailOSError, type SendMailOSOptions, SendmailPixel, type Subscriber, type TrackEventProperties, type TrackProps, ValidationError, type VerifyWebhookParams, type Webhook, type WebhookEvent, type WebhookEventType, constructWebhookEvent, createGlobalPixel, SendMailOS as default, verifyWebhookSignature, verifyWebhookSignatureAsync };
|
package/dist/index.d.ts
CHANGED
|
@@ -400,6 +400,93 @@ declare class SendMailOS {
|
|
|
400
400
|
static get version(): string;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
+
interface PixelConfig {
|
|
404
|
+
/** Public API key (pk_live_... or pk_test_...) or legacy token */
|
|
405
|
+
token: string;
|
|
406
|
+
/** API endpoint for tracking events */
|
|
407
|
+
endpoint?: string;
|
|
408
|
+
/** Cookie name for anonymous ID storage */
|
|
409
|
+
cookieName?: string;
|
|
410
|
+
/** Enable debug logging */
|
|
411
|
+
debug?: boolean;
|
|
412
|
+
/** Respect Do Not Track browser setting (default: true) */
|
|
413
|
+
respectDNT?: boolean;
|
|
414
|
+
}
|
|
415
|
+
/** Alias for PixelConfig for SDK consistency */
|
|
416
|
+
type PixelOptions = PixelConfig;
|
|
417
|
+
interface TrackProps {
|
|
418
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
419
|
+
}
|
|
420
|
+
/** Alias for TrackProps */
|
|
421
|
+
type TrackEventProperties = TrackProps;
|
|
422
|
+
/** Traits for identify calls */
|
|
423
|
+
interface IdentifyTraits {
|
|
424
|
+
first_name?: string;
|
|
425
|
+
last_name?: string;
|
|
426
|
+
[key: string]: string | number | boolean | null | undefined | object;
|
|
427
|
+
}
|
|
428
|
+
declare class SendmailPixel {
|
|
429
|
+
private config;
|
|
430
|
+
private anonymousId;
|
|
431
|
+
private initialized;
|
|
432
|
+
private rules;
|
|
433
|
+
private identifiedEmail;
|
|
434
|
+
constructor(config: PixelConfig);
|
|
435
|
+
init(): void;
|
|
436
|
+
/**
|
|
437
|
+
* Opt out of all tracking
|
|
438
|
+
*/
|
|
439
|
+
optOut(): void;
|
|
440
|
+
/**
|
|
441
|
+
* Opt back in to tracking
|
|
442
|
+
*/
|
|
443
|
+
optIn(): void;
|
|
444
|
+
/**
|
|
445
|
+
* Check if user has opted out
|
|
446
|
+
*/
|
|
447
|
+
isOptedOut(): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Reset identity (e.g., on logout)
|
|
450
|
+
*/
|
|
451
|
+
reset(): void;
|
|
452
|
+
/**
|
|
453
|
+
* Get current visitor/anonymous ID
|
|
454
|
+
*/
|
|
455
|
+
getVisitorId(): string;
|
|
456
|
+
/**
|
|
457
|
+
* Get identified email address
|
|
458
|
+
*/
|
|
459
|
+
getIdentifiedEmail(): string | null;
|
|
460
|
+
track(eventName: string, properties?: TrackProps): void;
|
|
461
|
+
identify(email: string, traits?: TrackProps): void;
|
|
462
|
+
pageView(): void;
|
|
463
|
+
private getOrSetAnonymousId;
|
|
464
|
+
private sendEvent;
|
|
465
|
+
loadRules(): Promise<void>;
|
|
466
|
+
/**
|
|
467
|
+
* Smart Auto-Detection of Page Type & Context
|
|
468
|
+
* Uses Dynamic Rules + Static Heuristics
|
|
469
|
+
*/
|
|
470
|
+
private detectContext;
|
|
471
|
+
private setupFormListeners;
|
|
472
|
+
private setupHistoryListeners;
|
|
473
|
+
private setCookie;
|
|
474
|
+
private getCookie;
|
|
475
|
+
private log;
|
|
476
|
+
private isDNTEnabled;
|
|
477
|
+
private checkUrlForSubscriber;
|
|
478
|
+
private setupDataAttributeTracking;
|
|
479
|
+
private getStoredEmail;
|
|
480
|
+
private storeEmail;
|
|
481
|
+
private isValidEmail;
|
|
482
|
+
}
|
|
483
|
+
/** Alias for SendmailPixel for SDK consistency */
|
|
484
|
+
declare const Pixel: typeof SendmailPixel;
|
|
485
|
+
/**
|
|
486
|
+
* Create pixel and attach global smp() function
|
|
487
|
+
*/
|
|
488
|
+
declare function createGlobalPixel(config: PixelConfig): SendmailPixel;
|
|
489
|
+
|
|
403
490
|
/**
|
|
404
491
|
* Custom error classes for SendMailOS SDK
|
|
405
492
|
*/
|
|
@@ -477,4 +564,4 @@ declare function constructWebhookEvent<T = unknown>(payload: string, headers: {
|
|
|
477
564
|
timestamp: string;
|
|
478
565
|
}, secret: string): T;
|
|
479
566
|
|
|
480
|
-
export { type ApiError, AuthenticationError, type CreateDomainRequest, type CreateDomainResponse, type CreateSubscriberRequest, type CreateSubscriberResponse, type CreateWebhookRequest, type DnsRecord, type Domain, type ListDomainsResponse, type ListSubscribersRequest, type ListSubscribersResponse, NotFoundError, RateLimitError, type SendCampaignRequest, type SendCampaignResponse, type SendEmailRequest, type SendEmailResponse, SendMailOS, SendMailOSError, type SendMailOSOptions, type Subscriber, ValidationError, type VerifyWebhookParams, type Webhook, type WebhookEvent, type WebhookEventType, constructWebhookEvent, SendMailOS as default, verifyWebhookSignature, verifyWebhookSignatureAsync };
|
|
567
|
+
export { type ApiError, AuthenticationError, type CreateDomainRequest, type CreateDomainResponse, type CreateSubscriberRequest, type CreateSubscriberResponse, type CreateWebhookRequest, type DnsRecord, type Domain, type IdentifyTraits, type ListDomainsResponse, type ListSubscribersRequest, type ListSubscribersResponse, NotFoundError, Pixel, type PixelConfig, type PixelOptions, RateLimitError, type SendCampaignRequest, type SendCampaignResponse, type SendEmailRequest, type SendEmailResponse, SendMailOS, SendMailOSError, type SendMailOSOptions, SendmailPixel, type Subscriber, type TrackEventProperties, type TrackProps, ValidationError, type VerifyWebhookParams, type Webhook, type WebhookEvent, type WebhookEventType, constructWebhookEvent, createGlobalPixel, SendMailOS as default, verifyWebhookSignature, verifyWebhookSignatureAsync };
|