@sendmailos/sdk 1.1.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/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
|