shopkit-analytics 1.0.1 → 1.0.3
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 +193 -3
- package/dist/adapters/index.d.mts +3 -2
- package/dist/adapters/index.d.ts +3 -2
- package/dist/adapters/index.js +1220 -615
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +4 -2
- package/dist/{chunk-3TQR5DOP.mjs → chunk-3NR2AKE4.mjs} +1 -31
- package/dist/chunk-3NR2AKE4.mjs.map +1 -0
- package/dist/chunk-4RDPDMGW.mjs +68 -0
- package/dist/chunk-4RDPDMGW.mjs.map +1 -0
- package/dist/{chunk-JVEGG6JV.mjs → chunk-HCA4E2RA.mjs} +19 -13
- package/dist/chunk-HCA4E2RA.mjs.map +1 -0
- package/dist/chunk-NC25KOAF.mjs +156 -0
- package/dist/chunk-NC25KOAF.mjs.map +1 -0
- package/dist/chunk-NGPUKV7E.mjs +46 -0
- package/dist/chunk-NGPUKV7E.mjs.map +1 -0
- package/dist/{chunk-4MZH5OLR.mjs → chunk-NJQ2MOM2.mjs} +1145 -618
- package/dist/chunk-NJQ2MOM2.mjs.map +1 -0
- package/dist/chunk-NKDB4KX2.mjs +2 -0
- package/dist/{chunk-P4OJDCEZ.mjs → chunk-QCS5UARA.mjs} +3 -3
- package/dist/events/index.d.mts +9 -41
- package/dist/events/index.d.ts +9 -41
- package/dist/events/index.js +973 -498
- package/dist/events/index.js.map +1 -1
- package/dist/events/index.mjs +11 -11
- package/dist/experiment/index.d.mts +25 -0
- package/dist/experiment/index.d.ts +25 -0
- package/dist/experiment/index.js +74 -0
- package/dist/experiment/index.js.map +1 -0
- package/dist/experiment/index.mjs +15 -0
- package/dist/experiment/index.mjs.map +1 -0
- package/dist/{index-BnNRgdUv.d.ts → index-D_8w5bL_.d.ts} +87 -17
- package/dist/{index-GODWc1s6.d.mts → index-th6sBtE3.d.mts} +87 -17
- package/dist/index.d.mts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.js +1408 -660
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -10
- package/dist/index.mjs.map +1 -1
- package/dist/services/index.d.mts +51 -0
- package/dist/services/index.d.ts +51 -0
- package/dist/services/index.js +180 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/index.mjs +11 -0
- package/dist/services/index.mjs.map +1 -0
- package/dist/{subscriber-43gnCKWe.d.ts → subscriber-BDAm_BAi.d.ts} +38 -2
- package/dist/{subscriber-sWesj_5p.d.mts → subscriber-BoyOlh9t.d.mts} +38 -2
- package/dist/subscriber-VF3IYUCU.mjs +8 -0
- package/dist/subscriber-VF3IYUCU.mjs.map +1 -0
- package/dist/types-C__2IBCj.d.mts +7 -0
- package/dist/types-C__2IBCj.d.ts +7 -0
- package/dist/types.d.mts +4 -340
- package/dist/types.d.ts +4 -340
- package/dist/types.js +0 -30
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/utils/index.d.mts +19 -0
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.js +93 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +12 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +21 -8
- package/templates/nextjs/README.md +206 -0
- package/templates/nextjs/api-events-route.ts +62 -0
- package/dist/chunk-3TQR5DOP.mjs.map +0 -1
- package/dist/chunk-4MZH5OLR.mjs.map +0 -1
- package/dist/chunk-JVEGG6JV.mjs.map +0 -1
- package/dist/subscriber-IFZJU57V.mjs +0 -8
- /package/dist/{subscriber-IFZJU57V.mjs.map → chunk-NKDB4KX2.mjs.map} +0 -0
- /package/dist/{chunk-P4OJDCEZ.mjs.map → chunk-QCS5UARA.mjs.map} +0 -0
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ A comprehensive analytics package for e-commerce applications with support for m
|
|
|
7
7
|
- **Multiple Analytics Platforms**: Support for 7+ analytics adapters
|
|
8
8
|
- **Event-Driven Architecture**: Publisher-subscriber pattern for flexible event handling
|
|
9
9
|
- **TypeScript Support**: Full type safety and IntelliSense
|
|
10
|
+
- **Adapter-Specific Parameters**: Customize event names and parameters per adapter
|
|
11
|
+
- **Server-Side Tracking**: Facebook CAPI integration with event deduplication
|
|
10
12
|
- **Affiliate Tracking**: Built-in UTM parameter and attribution tracking
|
|
11
13
|
- **React Integration**: Easy-to-use React components
|
|
12
14
|
- **Selective Adapter Routing**: Route events to specific adapters
|
|
@@ -77,6 +79,95 @@ publishEvent({
|
|
|
77
79
|
});
|
|
78
80
|
```
|
|
79
81
|
|
|
82
|
+
## 🎯 Adapter-Specific Parameters
|
|
83
|
+
|
|
84
|
+
All 7 adapters now support adapter-specific parameter customization, allowing you to override event names and add custom parameters per adapter while maintaining a single event call.
|
|
85
|
+
|
|
86
|
+
### Basic Usage
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { publishEvent, EventType } from "@shopkit/analytics";
|
|
90
|
+
|
|
91
|
+
// Standard event (works with all adapters)
|
|
92
|
+
publishEvent({
|
|
93
|
+
type: EventType.ADD_TO_CART,
|
|
94
|
+
productId: "123",
|
|
95
|
+
productName: "Cool Product",
|
|
96
|
+
price: 29.99,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Advanced usage with adapter-specific parameters
|
|
100
|
+
publishEvent({
|
|
101
|
+
type: EventType.ADD_TO_CART,
|
|
102
|
+
productId: "123",
|
|
103
|
+
productName: "Cool Product",
|
|
104
|
+
price: 29.99,
|
|
105
|
+
}, {
|
|
106
|
+
// Customize for each adapter
|
|
107
|
+
GoogleAnalytics: {
|
|
108
|
+
event_name: "custom_add_to_cart",
|
|
109
|
+
custom_dimension_1: "premium_user",
|
|
110
|
+
campaign_id: "summer_campaign"
|
|
111
|
+
},
|
|
112
|
+
FacebookPixel: {
|
|
113
|
+
event_name: "CustomAddToCart",
|
|
114
|
+
custom_parameter: "special_value",
|
|
115
|
+
pixel_specific_data: { campaign: "summer2024" }
|
|
116
|
+
},
|
|
117
|
+
PostHog: {
|
|
118
|
+
event_name: "add_to_cart_premium",
|
|
119
|
+
feature_flag: "new_checkout_flow"
|
|
120
|
+
},
|
|
121
|
+
MoEngage: {
|
|
122
|
+
event_name: "cart_item_added",
|
|
123
|
+
user_segment: "premium_customers"
|
|
124
|
+
},
|
|
125
|
+
KwikCheckout: {
|
|
126
|
+
event_name: "gokwik_add_to_cart",
|
|
127
|
+
checkout_flow: "express"
|
|
128
|
+
},
|
|
129
|
+
KwikPass: {
|
|
130
|
+
event_name: "kwikpass_cart_add",
|
|
131
|
+
pass_type: "premium"
|
|
132
|
+
},
|
|
133
|
+
ShopifyAnalytics: {
|
|
134
|
+
event_name: "shopify_add_to_cart",
|
|
135
|
+
pageType: "product",
|
|
136
|
+
custom_shopify_param: "value"
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### TypeScript Support
|
|
142
|
+
|
|
143
|
+
Full TypeScript support with IntelliSense for all adapter names:
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import type { IAdapterParams } from "@shopkit/analytics";
|
|
147
|
+
|
|
148
|
+
const customParams: IAdapterParams = {
|
|
149
|
+
GoogleAnalytics: {
|
|
150
|
+
event_name: "custom_event",
|
|
151
|
+
// Full type safety for parameters
|
|
152
|
+
},
|
|
153
|
+
FacebookPixel: {
|
|
154
|
+
event_name: "CustomEvent",
|
|
155
|
+
// Adapter-specific parameters
|
|
156
|
+
},
|
|
157
|
+
// ... other adapters
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
publishEvent(eventData, customParams);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Key Benefits
|
|
164
|
+
|
|
165
|
+
- **🎯 Flexibility**: Customize event names and parameters per adapter
|
|
166
|
+
- **🔄 Backward Compatibility**: Optional parameters maintain existing API
|
|
167
|
+
- **🛡️ Type Safety**: Full TypeScript support with proper interfaces
|
|
168
|
+
- **⚡ Performance**: No overhead when not using custom parameters
|
|
169
|
+
- **🧹 Clean API**: Single event call handles all adapters
|
|
170
|
+
|
|
80
171
|
## 🔧 Analytics Adapters
|
|
81
172
|
|
|
82
173
|
### 1. Google Analytics 4
|
|
@@ -105,13 +196,14 @@ Track events to Google Analytics 4 with enhanced e-commerce support.
|
|
|
105
196
|
|
|
106
197
|
### 2. Facebook Pixel
|
|
107
198
|
|
|
108
|
-
Track conversions and optimize Facebook ad campaigns.
|
|
199
|
+
Track conversions and optimize Facebook ad campaigns with both client-side and server-side tracking support.
|
|
109
200
|
|
|
110
201
|
```tsx
|
|
111
202
|
<ShopkitAnalytics
|
|
112
203
|
config={{
|
|
113
204
|
facebookPixel: {
|
|
114
205
|
pixelId: "123456789",
|
|
206
|
+
enableCAPI: true, // Server-side CAPI backup (enabled by default)
|
|
115
207
|
enableDebugLogs: true,
|
|
116
208
|
enableAdvancedMatching: true,
|
|
117
209
|
},
|
|
@@ -124,6 +216,14 @@ Track conversions and optimize Facebook ad campaigns.
|
|
|
124
216
|
- InitiateCheckout, Search
|
|
125
217
|
- Custom conversions
|
|
126
218
|
|
|
219
|
+
**Server-Side Tracking (CAPI):**
|
|
220
|
+
- **Enabled by default** for improved data reliability
|
|
221
|
+
- Automatic server-side backup with event deduplication
|
|
222
|
+
- Enhanced browser fingerprinting for better user matching
|
|
223
|
+
- Fallback mechanism when client-side tracking fails
|
|
224
|
+
- Requires `/api/events` endpoint for server-side processing
|
|
225
|
+
- Set `enableCAPI: false` to disable if not needed
|
|
226
|
+
|
|
127
227
|
### 3. MoEngage
|
|
128
228
|
|
|
129
229
|
Engage users with personalized campaigns and analytics.
|
|
@@ -196,7 +296,7 @@ NEXT_PUBLIC_POSTHOG_KEY="phc_xxxxxxxxxx"
|
|
|
196
296
|
|
|
197
297
|
### 5. Shopify Analytics
|
|
198
298
|
|
|
199
|
-
Native Shopify Admin Analytics integration.
|
|
299
|
+
Native Shopify Admin Analytics integration with full adapter parameter support.
|
|
200
300
|
|
|
201
301
|
```tsx
|
|
202
302
|
<ShopkitAnalytics
|
|
@@ -222,6 +322,23 @@ NEXT_PUBLIC_SHOPIFY_CURRENCY="USD"
|
|
|
222
322
|
- Add to cart, checkout events
|
|
223
323
|
- Session tracking with Shopify cookies
|
|
224
324
|
|
|
325
|
+
**Adapter Parameter Support:**
|
|
326
|
+
```tsx
|
|
327
|
+
publishEvent({
|
|
328
|
+
type: EventType.ADD_TO_CART,
|
|
329
|
+
productId: "123",
|
|
330
|
+
productName: "Product",
|
|
331
|
+
price: 29.99,
|
|
332
|
+
}, {
|
|
333
|
+
ShopifyAnalytics: {
|
|
334
|
+
event_name: "custom_shopify_event",
|
|
335
|
+
pageType: "product",
|
|
336
|
+
collectionHandle: "featured-products",
|
|
337
|
+
custom_shopify_param: "value"
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
```
|
|
341
|
+
|
|
225
342
|
### 6. KwikPass Analytics
|
|
226
343
|
|
|
227
344
|
Custom analytics adapter for KwikPass platform integration.
|
|
@@ -285,7 +402,80 @@ NEXT_PUBLIC_STORE_ID="your-store-id"
|
|
|
285
402
|
- `ORDER_SUCCESS` - Order success confirmation
|
|
286
403
|
- `ORDER_COMPLETED` - Order fulfillment
|
|
287
404
|
|
|
288
|
-
##
|
|
405
|
+
## 🔄 Server-Side Tracking (CAPI)
|
|
406
|
+
|
|
407
|
+
The Facebook Pixel adapter supports server-side tracking through the Conversions API (CAPI) for improved data reliability and privacy compliance.
|
|
408
|
+
|
|
409
|
+
### Quick Setup
|
|
410
|
+
|
|
411
|
+
1. **Set Environment Variables**:
|
|
412
|
+
```bash
|
|
413
|
+
FACEBOOK_CAPI_ACCESS_TOKEN="your_facebook_access_token"
|
|
414
|
+
NEXT_PUBLIC_PIXEL_ID="123456789"
|
|
415
|
+
FACEBOOK_TEST_EVENT_CODE="TEST12345" # Optional: for testing
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
2. **Copy API Route Template**:
|
|
419
|
+
- Find the template in `node_modules/@shopkit/analytics/templates/nextjs/`
|
|
420
|
+
- Copy `api-events-route.ts` to your `app/api/events/route.ts` (App Router)
|
|
421
|
+
- Or follow the Pages Router example in the template README
|
|
422
|
+
|
|
423
|
+
3. **CAPI Configuration** (enabled by default):
|
|
424
|
+
```tsx
|
|
425
|
+
<ShopkitAnalytics
|
|
426
|
+
config={{
|
|
427
|
+
facebookPixel: {
|
|
428
|
+
pixelId: process.env.NEXT_PUBLIC_PIXEL_ID!,
|
|
429
|
+
// enableCAPI: true, // Default: enabled for better data reliability
|
|
430
|
+
// enableCAPI: false, // Uncomment to disable server-side tracking
|
|
431
|
+
},
|
|
432
|
+
}}
|
|
433
|
+
/>
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Features
|
|
437
|
+
|
|
438
|
+
- **Automatic Fallback**: Server-side tracking runs as a backup to client-side tracking
|
|
439
|
+
- **Event Deduplication**: Unique event IDs prevent duplicate tracking across client/server
|
|
440
|
+
- **Enhanced Matching**: Browser fingerprinting for better user matching
|
|
441
|
+
- **Privacy Compliant**: Respects user privacy while improving data quality
|
|
442
|
+
- **Built-in CAPI Service**: Uses the integrated `FacebookCAPIService` for server-side processing
|
|
443
|
+
|
|
444
|
+
### Detailed Setup Guide
|
|
445
|
+
|
|
446
|
+
For complete setup instructions, including troubleshooting and testing, see:
|
|
447
|
+
`node_modules/@shopkit/analytics/templates/nextjs/README.md`
|
|
448
|
+
|
|
449
|
+
### Supported Events
|
|
450
|
+
|
|
451
|
+
The CAPI service currently supports these events:
|
|
452
|
+
|
|
453
|
+
- `PAGE_VIEW` → Facebook `PageView`
|
|
454
|
+
- `PRODUCT_VIEW` → Facebook `ViewContent`
|
|
455
|
+
- `ADD_TO_CART` → Facebook `AddToCart`
|
|
456
|
+
- `SEARCH` → Facebook `Search`
|
|
457
|
+
|
|
458
|
+
### Event ID Generation
|
|
459
|
+
|
|
460
|
+
Events automatically receive unique IDs for deduplication:
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
// Automatic ID generation
|
|
464
|
+
publishEvent({
|
|
465
|
+
type: EventType.ADD_TO_CART,
|
|
466
|
+
productId: "123",
|
|
467
|
+
// eventId is automatically generated if not provided
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Manual ID specification
|
|
471
|
+
publishEvent({
|
|
472
|
+
type: EventType.ADD_TO_CART,
|
|
473
|
+
productId: "123",
|
|
474
|
+
eventId: "custom_event_id_123", // Custom event ID
|
|
475
|
+
});
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
## Professional Logging System
|
|
289
479
|
|
|
290
480
|
The analytics package includes a comprehensive logging system built on [Pino](https://github.com/pinojs/pino), a high-performance JSON logger for Node.js and browsers.
|
|
291
481
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { B as BaseAdapter, d as GoogleAdapter, G as GoogleAdapterConfig, i as KwikCheckoutAdapter, b as KwikCheckoutConfig, h as KwikPassAdapter, K as KwikPassConfig, e as MoengageAdapter, M as MoengageAdapterConfig, c as PixelAdapter, P as PixelAdapterConfig, f as PostHogAdapter, a as PostHogAdapterConfig, g as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-
|
|
1
|
+
export { B as BaseAdapter, d as GoogleAdapter, G as GoogleAdapterConfig, i as KwikCheckoutAdapter, b as KwikCheckoutConfig, h as KwikPassAdapter, K as KwikPassConfig, e as MoengageAdapter, M as MoengageAdapterConfig, c as PixelAdapter, P as PixelAdapterConfig, f as PostHogAdapter, a as PostHogAdapterConfig, g as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-th6sBtE3.mjs';
|
|
2
2
|
import '../types.mjs';
|
|
3
|
-
import '../subscriber-
|
|
3
|
+
import '../subscriber-BoyOlh9t.mjs';
|
|
4
|
+
import '../types-C__2IBCj.mjs';
|
|
4
5
|
import '@shopify/hydrogen-react';
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { B as BaseAdapter, d as GoogleAdapter, G as GoogleAdapterConfig, i as KwikCheckoutAdapter, b as KwikCheckoutConfig, h as KwikPassAdapter, K as KwikPassConfig, e as MoengageAdapter, M as MoengageAdapterConfig, c as PixelAdapter, P as PixelAdapterConfig, f as PostHogAdapter, a as PostHogAdapterConfig, g as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-
|
|
1
|
+
export { B as BaseAdapter, d as GoogleAdapter, G as GoogleAdapterConfig, i as KwikCheckoutAdapter, b as KwikCheckoutConfig, h as KwikPassAdapter, K as KwikPassConfig, e as MoengageAdapter, M as MoengageAdapterConfig, c as PixelAdapter, P as PixelAdapterConfig, f as PostHogAdapter, a as PostHogAdapterConfig, g as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-D_8w5bL_.js';
|
|
2
2
|
import '../types.js';
|
|
3
|
-
import '../subscriber-
|
|
3
|
+
import '../subscriber-BDAm_BAi.js';
|
|
4
|
+
import '../types-C__2IBCj.js';
|
|
4
5
|
import '@shopify/hydrogen-react';
|