aurea-tracking-sdk 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 +429 -0
- package/dist/index.d.mts +144 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +473 -0
- package/dist/index.mjs +444 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
# Aurea Tracking SDK
|
|
2
|
+
|
|
3
|
+
A standalone tracking SDK for Aurea CRM external funnels. Track user behavior, conversions, and analytics events in your web applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install aurea-tracking-sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add aurea-tracking-sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add aurea-tracking-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### 1. Initialize the SDK
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { initAurea } from 'aurea-tracking-sdk';
|
|
21
|
+
|
|
22
|
+
initAurea({
|
|
23
|
+
apiKey: 'your-api-key',
|
|
24
|
+
funnelId: 'your-funnel-id',
|
|
25
|
+
apiUrl: 'https://your-aurea-instance.com/api',
|
|
26
|
+
debug: true, // Enable debug logging in development
|
|
27
|
+
autoTrack: {
|
|
28
|
+
pageViews: true,
|
|
29
|
+
forms: true,
|
|
30
|
+
scrollDepth: true,
|
|
31
|
+
clicks: false,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Track Custom Events
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { trackEvent } from 'aurea-tracking-sdk';
|
|
40
|
+
|
|
41
|
+
// Track a custom event
|
|
42
|
+
trackEvent('button_clicked', {
|
|
43
|
+
buttonName: 'Get Started',
|
|
44
|
+
location: 'hero',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Track a conversion
|
|
48
|
+
import { trackConversion } from 'aurea-tracking-sdk';
|
|
49
|
+
|
|
50
|
+
trackConversion({
|
|
51
|
+
type: 'purchase',
|
|
52
|
+
revenue: 99.00,
|
|
53
|
+
currency: 'USD',
|
|
54
|
+
orderId: 'order_123',
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Identify Users
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { identifyUser } from 'aurea-tracking-sdk';
|
|
62
|
+
|
|
63
|
+
identifyUser('user_123', {
|
|
64
|
+
email: 'user@example.com',
|
|
65
|
+
name: 'John Doe',
|
|
66
|
+
plan: 'premium',
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Features
|
|
71
|
+
|
|
72
|
+
### ✅ Auto-Tracking
|
|
73
|
+
|
|
74
|
+
- **Page Views** - Automatically tracks page visits and navigation
|
|
75
|
+
- **Form Submissions** - Captures form submit events
|
|
76
|
+
- **Scroll Depth** - Tracks user engagement (25%, 50%, 75%, 100%)
|
|
77
|
+
- **Clicks** - Optional click tracking
|
|
78
|
+
|
|
79
|
+
### 📊 Analytics
|
|
80
|
+
|
|
81
|
+
- **Custom Events** - Track any custom event with properties
|
|
82
|
+
- **Conversions** - Track purchases and revenue
|
|
83
|
+
- **User Identification** - Link events to specific users
|
|
84
|
+
- **Session Tracking** - Automatic session management
|
|
85
|
+
|
|
86
|
+
### 🔄 Purchase Detection
|
|
87
|
+
|
|
88
|
+
- **Webhook Integration** - Detects purchases from server-side webhooks
|
|
89
|
+
- **Auto-Redirect** - Automatically redirects users to thank-you page after purchase
|
|
90
|
+
- **Polling System** - Checks for purchases every 3 seconds
|
|
91
|
+
|
|
92
|
+
### 🛡️ Privacy & Security
|
|
93
|
+
|
|
94
|
+
- **Do Not Track** - Respects browser DNT settings
|
|
95
|
+
- **IP Anonymization** - Optional IP address anonymization
|
|
96
|
+
- **GDPR Compliant** - Built with privacy in mind
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### `initAurea(config)`
|
|
101
|
+
|
|
102
|
+
Initialize the tracking SDK.
|
|
103
|
+
|
|
104
|
+
**Parameters:**
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
interface AureaConfig {
|
|
108
|
+
apiKey: string; // Required: Your Aurea API key
|
|
109
|
+
funnelId: string; // Required: Your funnel ID
|
|
110
|
+
apiUrl?: string; // Optional: API endpoint URL
|
|
111
|
+
debug?: boolean; // Optional: Enable debug logging
|
|
112
|
+
autoTrack?: { // Optional: Auto-tracking settings
|
|
113
|
+
pageViews?: boolean; // Default: true
|
|
114
|
+
forms?: boolean; // Default: true
|
|
115
|
+
clicks?: boolean; // Default: false
|
|
116
|
+
scrollDepth?: boolean; // Default: false
|
|
117
|
+
};
|
|
118
|
+
respectDoNotTrack?: boolean; // Optional: Respect DNT header (default: true)
|
|
119
|
+
anonymizeIp?: boolean; // Optional: Anonymize IP addresses (default: true)
|
|
120
|
+
batchSize?: number; // Optional: Event batch size (default: 10)
|
|
121
|
+
batchInterval?: number; // Optional: Batch interval in ms (default: 2000)
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Returns:** `AureaSDK` instance
|
|
126
|
+
|
|
127
|
+
**Example:**
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const aurea = initAurea({
|
|
131
|
+
apiKey: 'ak_1234567890',
|
|
132
|
+
funnelId: 'fn_abcdefgh',
|
|
133
|
+
apiUrl: 'https://analytics.example.com/api',
|
|
134
|
+
debug: process.env.NODE_ENV === 'development',
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### `trackEvent(name, properties?)`
|
|
141
|
+
|
|
142
|
+
Track a custom event.
|
|
143
|
+
|
|
144
|
+
**Parameters:**
|
|
145
|
+
|
|
146
|
+
- `name` (string): Event name
|
|
147
|
+
- `properties` (object, optional): Event properties
|
|
148
|
+
|
|
149
|
+
**Example:**
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
trackEvent('product_viewed', {
|
|
153
|
+
productId: 'prod_123',
|
|
154
|
+
productName: 'Premium Plan',
|
|
155
|
+
price: 99.00,
|
|
156
|
+
category: 'subscription',
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### `trackPage(name?, properties?)`
|
|
163
|
+
|
|
164
|
+
Track a page view.
|
|
165
|
+
|
|
166
|
+
**Parameters:**
|
|
167
|
+
|
|
168
|
+
- `name` (string, optional): Page name
|
|
169
|
+
- `properties` (object, optional): Page properties
|
|
170
|
+
|
|
171
|
+
**Example:**
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
trackPage('Pricing Page', {
|
|
175
|
+
plan: 'premium',
|
|
176
|
+
billingCycle: 'monthly',
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### `trackConversion(data)`
|
|
183
|
+
|
|
184
|
+
Track a conversion event.
|
|
185
|
+
|
|
186
|
+
**Parameters:**
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
interface ConversionData {
|
|
190
|
+
type: string; // Conversion type (e.g., 'purchase', 'signup')
|
|
191
|
+
revenue: number; // Revenue amount
|
|
192
|
+
currency?: string; // Currency code (default: 'USD')
|
|
193
|
+
orderId?: string; // Order/transaction ID
|
|
194
|
+
properties?: object; // Additional properties
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Example:**
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
trackConversion({
|
|
202
|
+
type: 'purchase',
|
|
203
|
+
revenue: 149.99,
|
|
204
|
+
currency: 'USD',
|
|
205
|
+
orderId: 'order_abc123',
|
|
206
|
+
properties: {
|
|
207
|
+
plan: 'annual',
|
|
208
|
+
discount: 'SAVE20',
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
### `identifyUser(userId, traits?)`
|
|
216
|
+
|
|
217
|
+
Identify a user.
|
|
218
|
+
|
|
219
|
+
**Parameters:**
|
|
220
|
+
|
|
221
|
+
- `userId` (string): Unique user identifier
|
|
222
|
+
- `traits` (object, optional): User traits/properties
|
|
223
|
+
|
|
224
|
+
**Example:**
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
identifyUser('user_123', {
|
|
228
|
+
email: 'john@example.com',
|
|
229
|
+
name: 'John Doe',
|
|
230
|
+
plan: 'premium',
|
|
231
|
+
signupDate: '2024-01-15',
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
### `getAurea()`
|
|
238
|
+
|
|
239
|
+
Get the current SDK instance.
|
|
240
|
+
|
|
241
|
+
**Returns:** `AureaSDK | null`
|
|
242
|
+
|
|
243
|
+
**Example:**
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { getAurea } from 'aurea-tracking-sdk';
|
|
247
|
+
|
|
248
|
+
const aurea = getAurea();
|
|
249
|
+
if (aurea) {
|
|
250
|
+
aurea.track('custom_event');
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Framework Integration
|
|
255
|
+
|
|
256
|
+
### Next.js
|
|
257
|
+
|
|
258
|
+
Create a component to initialize the SDK:
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
// components/aurea-tracking.tsx
|
|
262
|
+
'use client';
|
|
263
|
+
|
|
264
|
+
import { useEffect } from 'react';
|
|
265
|
+
import { initAurea } from 'aurea-tracking-sdk';
|
|
266
|
+
|
|
267
|
+
export function AureaTracking() {
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
initAurea({
|
|
270
|
+
apiKey: process.env.NEXT_PUBLIC_AUREA_API_KEY!,
|
|
271
|
+
funnelId: process.env.NEXT_PUBLIC_AUREA_FUNNEL_ID!,
|
|
272
|
+
apiUrl: process.env.NEXT_PUBLIC_AUREA_API_URL,
|
|
273
|
+
debug: process.env.NODE_ENV === 'development',
|
|
274
|
+
});
|
|
275
|
+
}, []);
|
|
276
|
+
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Add to your root layout:
|
|
282
|
+
|
|
283
|
+
```tsx
|
|
284
|
+
// app/layout.tsx
|
|
285
|
+
import { AureaTracking } from '@/components/aurea-tracking';
|
|
286
|
+
|
|
287
|
+
export default function RootLayout({ children }) {
|
|
288
|
+
return (
|
|
289
|
+
<html>
|
|
290
|
+
<body>
|
|
291
|
+
<AureaTracking />
|
|
292
|
+
{children}
|
|
293
|
+
</body>
|
|
294
|
+
</html>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### React
|
|
300
|
+
|
|
301
|
+
```tsx
|
|
302
|
+
import { useEffect } from 'react';
|
|
303
|
+
import { initAurea, trackEvent } from 'aurea-tracking-sdk';
|
|
304
|
+
|
|
305
|
+
function App() {
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
initAurea({
|
|
308
|
+
apiKey: import.meta.env.VITE_AUREA_API_KEY,
|
|
309
|
+
funnelId: import.meta.env.VITE_AUREA_FUNNEL_ID,
|
|
310
|
+
});
|
|
311
|
+
}, []);
|
|
312
|
+
|
|
313
|
+
return <YourApp />;
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Vanilla JavaScript
|
|
318
|
+
|
|
319
|
+
```html
|
|
320
|
+
<script type="module">
|
|
321
|
+
import { initAurea, trackEvent } from 'https://unpkg.com/aurea-tracking-sdk';
|
|
322
|
+
|
|
323
|
+
initAurea({
|
|
324
|
+
apiKey: 'your-api-key',
|
|
325
|
+
funnelId: 'your-funnel-id',
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Track events
|
|
329
|
+
document.querySelector('#cta-button').addEventListener('click', () => {
|
|
330
|
+
trackEvent('cta_clicked');
|
|
331
|
+
});
|
|
332
|
+
</script>
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Advanced Usage
|
|
336
|
+
|
|
337
|
+
### Custom Session Management
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
import { getAurea } from 'aurea-tracking-sdk';
|
|
341
|
+
|
|
342
|
+
const aurea = getAurea();
|
|
343
|
+
|
|
344
|
+
// Get current session ID
|
|
345
|
+
console.log(aurea?.sessionId);
|
|
346
|
+
|
|
347
|
+
// Get current anonymous ID
|
|
348
|
+
console.log(aurea?.anonymousId);
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Event Batching
|
|
352
|
+
|
|
353
|
+
Events are automatically batched and sent in groups for better performance:
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
initAurea({
|
|
357
|
+
apiKey: 'your-api-key',
|
|
358
|
+
funnelId: 'your-funnel-id',
|
|
359
|
+
batchSize: 20, // Send after 20 events
|
|
360
|
+
batchInterval: 5000, // Or after 5 seconds
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Error Handling
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
import { trackEvent } from 'aurea-tracking-sdk';
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
trackEvent('risky_operation', { value: 123 });
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error('Failed to track event:', error);
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## Configuration Examples
|
|
377
|
+
|
|
378
|
+
### Development
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
initAurea({
|
|
382
|
+
apiKey: 'ak_dev_1234567890',
|
|
383
|
+
funnelId: 'fn_dev_abcdefgh',
|
|
384
|
+
apiUrl: 'http://localhost:3000/api',
|
|
385
|
+
debug: true,
|
|
386
|
+
respectDoNotTrack: false, // Track in dev
|
|
387
|
+
});
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Production
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
initAurea({
|
|
394
|
+
apiKey: process.env.AUREA_API_KEY!,
|
|
395
|
+
funnelId: process.env.AUREA_FUNNEL_ID!,
|
|
396
|
+
apiUrl: 'https://analytics.yourdomain.com/api',
|
|
397
|
+
debug: false,
|
|
398
|
+
respectDoNotTrack: true,
|
|
399
|
+
anonymizeIp: true,
|
|
400
|
+
batchSize: 10,
|
|
401
|
+
batchInterval: 2000,
|
|
402
|
+
});
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## Browser Support
|
|
406
|
+
|
|
407
|
+
- Chrome/Edge (last 2 versions)
|
|
408
|
+
- Firefox (last 2 versions)
|
|
409
|
+
- Safari (last 2 versions)
|
|
410
|
+
- Mobile browsers (iOS Safari, Chrome Mobile)
|
|
411
|
+
|
|
412
|
+
## TypeScript
|
|
413
|
+
|
|
414
|
+
This package is written in TypeScript and includes type definitions out of the box.
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
import type { AureaConfig, ConversionData } from 'aurea-tracking-sdk';
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
## License
|
|
421
|
+
|
|
422
|
+
MIT
|
|
423
|
+
|
|
424
|
+
## Support
|
|
425
|
+
|
|
426
|
+
For issues and questions:
|
|
427
|
+
- GitHub: https://github.com/yourusername/aurea-tracking-sdk/issues
|
|
428
|
+
- Documentation: https://docs.aureacrm.com
|
|
429
|
+
- Email: support@aureacrm.com
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aurea Tracking SDK
|
|
3
|
+
* Standalone tracking SDK for external funnels
|
|
4
|
+
*/
|
|
5
|
+
interface AureaConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
funnelId: string;
|
|
8
|
+
apiUrl?: string;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
autoTrack?: {
|
|
11
|
+
pageViews?: boolean;
|
|
12
|
+
forms?: boolean;
|
|
13
|
+
clicks?: boolean;
|
|
14
|
+
scrollDepth?: boolean;
|
|
15
|
+
};
|
|
16
|
+
respectDoNotTrack?: boolean;
|
|
17
|
+
anonymizeIp?: boolean;
|
|
18
|
+
batchSize?: number;
|
|
19
|
+
batchInterval?: number;
|
|
20
|
+
}
|
|
21
|
+
interface ConversionData {
|
|
22
|
+
type: string;
|
|
23
|
+
revenue: number;
|
|
24
|
+
currency?: string;
|
|
25
|
+
orderId?: string;
|
|
26
|
+
properties?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
declare class AureaSDK {
|
|
29
|
+
private config;
|
|
30
|
+
private sessionId;
|
|
31
|
+
private anonymousId;
|
|
32
|
+
private userId?;
|
|
33
|
+
private eventQueue;
|
|
34
|
+
private batchTimer?;
|
|
35
|
+
private initialized;
|
|
36
|
+
constructor(config: AureaConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the SDK
|
|
39
|
+
*/
|
|
40
|
+
init(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Track a custom event
|
|
43
|
+
*/
|
|
44
|
+
track(eventName: string, properties?: Record<string, any>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Identify a user
|
|
47
|
+
*/
|
|
48
|
+
identify(userId: string, traits?: Record<string, any>): void;
|
|
49
|
+
/**
|
|
50
|
+
* Track a page view
|
|
51
|
+
*/
|
|
52
|
+
page(name?: string, properties?: Record<string, any>): void;
|
|
53
|
+
/**
|
|
54
|
+
* Track a conversion event
|
|
55
|
+
*/
|
|
56
|
+
conversion(data: ConversionData): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get or create session ID
|
|
59
|
+
*/
|
|
60
|
+
private getOrCreateSessionId;
|
|
61
|
+
/**
|
|
62
|
+
* Get or create anonymous ID
|
|
63
|
+
*/
|
|
64
|
+
private getOrCreateAnonymousId;
|
|
65
|
+
/**
|
|
66
|
+
* Build event context
|
|
67
|
+
*/
|
|
68
|
+
private buildContext;
|
|
69
|
+
/**
|
|
70
|
+
* Track initial page load
|
|
71
|
+
*/
|
|
72
|
+
private trackPageLoad;
|
|
73
|
+
/**
|
|
74
|
+
* Track page changes (for SPAs)
|
|
75
|
+
*/
|
|
76
|
+
private trackPageChanges;
|
|
77
|
+
/**
|
|
78
|
+
* Track form submissions
|
|
79
|
+
*/
|
|
80
|
+
private trackForms;
|
|
81
|
+
/**
|
|
82
|
+
* Track scroll depth
|
|
83
|
+
*/
|
|
84
|
+
private trackScrollDepth;
|
|
85
|
+
/**
|
|
86
|
+
* Enqueue event for batching
|
|
87
|
+
*/
|
|
88
|
+
private enqueueEvent;
|
|
89
|
+
/**
|
|
90
|
+
* Send events to API
|
|
91
|
+
*/
|
|
92
|
+
private sendEvents;
|
|
93
|
+
/**
|
|
94
|
+
* Flush queued events
|
|
95
|
+
*/
|
|
96
|
+
private flushEvents;
|
|
97
|
+
/**
|
|
98
|
+
* Start batch timer
|
|
99
|
+
*/
|
|
100
|
+
private startBatchTimer;
|
|
101
|
+
/**
|
|
102
|
+
* Poll for purchase completion
|
|
103
|
+
* Checks every 3 seconds if user has made a purchase
|
|
104
|
+
*/
|
|
105
|
+
private startPurchasePolling;
|
|
106
|
+
/**
|
|
107
|
+
* Check if user has completed a purchase
|
|
108
|
+
*/
|
|
109
|
+
private checkForPurchase;
|
|
110
|
+
/**
|
|
111
|
+
* Generate unique ID
|
|
112
|
+
*/
|
|
113
|
+
private generateId;
|
|
114
|
+
/**
|
|
115
|
+
* Generate event ID
|
|
116
|
+
*/
|
|
117
|
+
private generateEventId;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Initialize Aurea SDK
|
|
121
|
+
*/
|
|
122
|
+
declare function initAurea(config: AureaConfig): AureaSDK;
|
|
123
|
+
/**
|
|
124
|
+
* Get SDK instance
|
|
125
|
+
*/
|
|
126
|
+
declare function getAurea(): AureaSDK | null;
|
|
127
|
+
/**
|
|
128
|
+
* Helper: Track custom event
|
|
129
|
+
*/
|
|
130
|
+
declare function trackEvent(name: string, properties?: Record<string, any>): void;
|
|
131
|
+
/**
|
|
132
|
+
* Helper: Identify user
|
|
133
|
+
*/
|
|
134
|
+
declare function identifyUser(userId: string, traits?: Record<string, any>): void;
|
|
135
|
+
/**
|
|
136
|
+
* Helper: Track conversion
|
|
137
|
+
*/
|
|
138
|
+
declare function trackConversion(data: ConversionData): void;
|
|
139
|
+
/**
|
|
140
|
+
* Helper: Track page view
|
|
141
|
+
*/
|
|
142
|
+
declare function trackPage(name?: string, properties?: Record<string, any>): void;
|
|
143
|
+
|
|
144
|
+
export { getAurea, identifyUser, initAurea, trackConversion, trackEvent, trackPage };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aurea Tracking SDK
|
|
3
|
+
* Standalone tracking SDK for external funnels
|
|
4
|
+
*/
|
|
5
|
+
interface AureaConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
funnelId: string;
|
|
8
|
+
apiUrl?: string;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
autoTrack?: {
|
|
11
|
+
pageViews?: boolean;
|
|
12
|
+
forms?: boolean;
|
|
13
|
+
clicks?: boolean;
|
|
14
|
+
scrollDepth?: boolean;
|
|
15
|
+
};
|
|
16
|
+
respectDoNotTrack?: boolean;
|
|
17
|
+
anonymizeIp?: boolean;
|
|
18
|
+
batchSize?: number;
|
|
19
|
+
batchInterval?: number;
|
|
20
|
+
}
|
|
21
|
+
interface ConversionData {
|
|
22
|
+
type: string;
|
|
23
|
+
revenue: number;
|
|
24
|
+
currency?: string;
|
|
25
|
+
orderId?: string;
|
|
26
|
+
properties?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
declare class AureaSDK {
|
|
29
|
+
private config;
|
|
30
|
+
private sessionId;
|
|
31
|
+
private anonymousId;
|
|
32
|
+
private userId?;
|
|
33
|
+
private eventQueue;
|
|
34
|
+
private batchTimer?;
|
|
35
|
+
private initialized;
|
|
36
|
+
constructor(config: AureaConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the SDK
|
|
39
|
+
*/
|
|
40
|
+
init(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Track a custom event
|
|
43
|
+
*/
|
|
44
|
+
track(eventName: string, properties?: Record<string, any>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Identify a user
|
|
47
|
+
*/
|
|
48
|
+
identify(userId: string, traits?: Record<string, any>): void;
|
|
49
|
+
/**
|
|
50
|
+
* Track a page view
|
|
51
|
+
*/
|
|
52
|
+
page(name?: string, properties?: Record<string, any>): void;
|
|
53
|
+
/**
|
|
54
|
+
* Track a conversion event
|
|
55
|
+
*/
|
|
56
|
+
conversion(data: ConversionData): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get or create session ID
|
|
59
|
+
*/
|
|
60
|
+
private getOrCreateSessionId;
|
|
61
|
+
/**
|
|
62
|
+
* Get or create anonymous ID
|
|
63
|
+
*/
|
|
64
|
+
private getOrCreateAnonymousId;
|
|
65
|
+
/**
|
|
66
|
+
* Build event context
|
|
67
|
+
*/
|
|
68
|
+
private buildContext;
|
|
69
|
+
/**
|
|
70
|
+
* Track initial page load
|
|
71
|
+
*/
|
|
72
|
+
private trackPageLoad;
|
|
73
|
+
/**
|
|
74
|
+
* Track page changes (for SPAs)
|
|
75
|
+
*/
|
|
76
|
+
private trackPageChanges;
|
|
77
|
+
/**
|
|
78
|
+
* Track form submissions
|
|
79
|
+
*/
|
|
80
|
+
private trackForms;
|
|
81
|
+
/**
|
|
82
|
+
* Track scroll depth
|
|
83
|
+
*/
|
|
84
|
+
private trackScrollDepth;
|
|
85
|
+
/**
|
|
86
|
+
* Enqueue event for batching
|
|
87
|
+
*/
|
|
88
|
+
private enqueueEvent;
|
|
89
|
+
/**
|
|
90
|
+
* Send events to API
|
|
91
|
+
*/
|
|
92
|
+
private sendEvents;
|
|
93
|
+
/**
|
|
94
|
+
* Flush queued events
|
|
95
|
+
*/
|
|
96
|
+
private flushEvents;
|
|
97
|
+
/**
|
|
98
|
+
* Start batch timer
|
|
99
|
+
*/
|
|
100
|
+
private startBatchTimer;
|
|
101
|
+
/**
|
|
102
|
+
* Poll for purchase completion
|
|
103
|
+
* Checks every 3 seconds if user has made a purchase
|
|
104
|
+
*/
|
|
105
|
+
private startPurchasePolling;
|
|
106
|
+
/**
|
|
107
|
+
* Check if user has completed a purchase
|
|
108
|
+
*/
|
|
109
|
+
private checkForPurchase;
|
|
110
|
+
/**
|
|
111
|
+
* Generate unique ID
|
|
112
|
+
*/
|
|
113
|
+
private generateId;
|
|
114
|
+
/**
|
|
115
|
+
* Generate event ID
|
|
116
|
+
*/
|
|
117
|
+
private generateEventId;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Initialize Aurea SDK
|
|
121
|
+
*/
|
|
122
|
+
declare function initAurea(config: AureaConfig): AureaSDK;
|
|
123
|
+
/**
|
|
124
|
+
* Get SDK instance
|
|
125
|
+
*/
|
|
126
|
+
declare function getAurea(): AureaSDK | null;
|
|
127
|
+
/**
|
|
128
|
+
* Helper: Track custom event
|
|
129
|
+
*/
|
|
130
|
+
declare function trackEvent(name: string, properties?: Record<string, any>): void;
|
|
131
|
+
/**
|
|
132
|
+
* Helper: Identify user
|
|
133
|
+
*/
|
|
134
|
+
declare function identifyUser(userId: string, traits?: Record<string, any>): void;
|
|
135
|
+
/**
|
|
136
|
+
* Helper: Track conversion
|
|
137
|
+
*/
|
|
138
|
+
declare function trackConversion(data: ConversionData): void;
|
|
139
|
+
/**
|
|
140
|
+
* Helper: Track page view
|
|
141
|
+
*/
|
|
142
|
+
declare function trackPage(name?: string, properties?: Record<string, any>): void;
|
|
143
|
+
|
|
144
|
+
export { getAurea, identifyUser, initAurea, trackConversion, trackEvent, trackPage };
|