shopkit-analytics 1.0.2 → 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.
Files changed (53) hide show
  1. package/README.md +35 -100
  2. package/dist/adapters/index.d.mts +2 -1
  3. package/dist/adapters/index.d.ts +2 -1
  4. package/dist/adapters/index.js +230 -64
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/adapters/index.mjs +3 -1
  7. package/dist/chunk-4RDPDMGW.mjs +68 -0
  8. package/dist/chunk-4RDPDMGW.mjs.map +1 -0
  9. package/dist/chunk-NC25KOAF.mjs +156 -0
  10. package/dist/chunk-NC25KOAF.mjs.map +1 -0
  11. package/dist/chunk-NGPUKV7E.mjs +46 -0
  12. package/dist/chunk-NGPUKV7E.mjs.map +1 -0
  13. package/dist/{chunk-U3UOXFS4.mjs → chunk-NJQ2MOM2.mjs} +206 -116
  14. package/dist/chunk-NJQ2MOM2.mjs.map +1 -0
  15. package/dist/chunk-NKDB4KX2.mjs +2 -0
  16. package/dist/chunk-NKDB4KX2.mjs.map +1 -0
  17. package/dist/{chunk-BNV3EVHH.mjs → chunk-QCS5UARA.mjs} +2 -2
  18. package/dist/events/index.js +218 -54
  19. package/dist/events/index.js.map +1 -1
  20. package/dist/events/index.mjs +9 -7
  21. package/dist/experiment/index.d.mts +25 -0
  22. package/dist/experiment/index.d.ts +25 -0
  23. package/dist/experiment/index.js +74 -0
  24. package/dist/experiment/index.js.map +1 -0
  25. package/dist/experiment/index.mjs +15 -0
  26. package/dist/experiment/index.mjs.map +1 -0
  27. package/dist/{index-DS9OI5Mz.d.ts → index-D_8w5bL_.d.ts} +13 -0
  28. package/dist/{index-Bym1_EAp.d.mts → index-th6sBtE3.d.mts} +13 -0
  29. package/dist/index.d.mts +6 -2
  30. package/dist/index.d.ts +6 -2
  31. package/dist/index.js +400 -64
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +30 -7
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/services/index.d.mts +51 -0
  36. package/dist/services/index.d.ts +51 -0
  37. package/dist/services/index.js +180 -0
  38. package/dist/services/index.js.map +1 -0
  39. package/dist/services/index.mjs +11 -0
  40. package/dist/services/index.mjs.map +1 -0
  41. package/dist/types-C__2IBCj.d.mts +7 -0
  42. package/dist/types-C__2IBCj.d.ts +7 -0
  43. package/dist/utils/index.d.mts +19 -0
  44. package/dist/utils/index.d.ts +19 -0
  45. package/dist/utils/index.js +93 -0
  46. package/dist/utils/index.js.map +1 -0
  47. package/dist/utils/index.mjs +12 -0
  48. package/dist/utils/index.mjs.map +1 -0
  49. package/package.json +19 -1
  50. package/templates/nextjs/README.md +206 -0
  51. package/templates/nextjs/api-events-route.ts +62 -0
  52. package/dist/chunk-U3UOXFS4.mjs.map +0 -1
  53. /package/dist/{chunk-BNV3EVHH.mjs.map → chunk-QCS5UARA.mjs.map} +0 -0
package/README.md CHANGED
@@ -203,7 +203,7 @@ Track conversions and optimize Facebook ad campaigns with both client-side and s
203
203
  config={{
204
204
  facebookPixel: {
205
205
  pixelId: "123456789",
206
- enableCAPI: true, // Enable server-side CAPI backup
206
+ enableCAPI: true, // Server-side CAPI backup (enabled by default)
207
207
  enableDebugLogs: true,
208
208
  enableAdvancedMatching: true,
209
209
  },
@@ -217,11 +217,12 @@ Track conversions and optimize Facebook ad campaigns with both client-side and s
217
217
  - Custom conversions
218
218
 
219
219
  **Server-Side Tracking (CAPI):**
220
- - Automatic server-side backup for improved data reliability
221
- - Event deduplication using unique event IDs
220
+ - **Enabled by default** for improved data reliability
221
+ - Automatic server-side backup with event deduplication
222
222
  - Enhanced browser fingerprinting for better user matching
223
223
  - Fallback mechanism when client-side tracking fails
224
224
  - Requires `/api/events` endpoint for server-side processing
225
+ - Set `enableCAPI: false` to disable if not needed
225
226
 
226
227
  ### 3. MoEngage
227
228
 
@@ -405,6 +406,33 @@ NEXT_PUBLIC_STORE_ID="your-store-id"
405
406
 
406
407
  The Facebook Pixel adapter supports server-side tracking through the Conversions API (CAPI) for improved data reliability and privacy compliance.
407
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
+
408
436
  ### Features
409
437
 
410
438
  - **Automatic Fallback**: Server-side tracking runs as a backup to client-side tracking
@@ -413,88 +441,14 @@ The Facebook Pixel adapter supports server-side tracking through the Conversions
413
441
  - **Privacy Compliant**: Respects user privacy while improving data quality
414
442
  - **Built-in CAPI Service**: Uses the integrated `FacebookCAPIService` for server-side processing
415
443
 
416
- ### Environment Variables
417
-
418
- Set up the required environment variables for CAPI:
419
-
420
- ```bash
421
- # Facebook CAPI Configuration
422
- FACEBOOK_CAPI_ACCESS_TOKEN="your_facebook_access_token"
423
- NEXT_PUBLIC_PIXEL_ID="123456789"
424
- FACEBOOK_TEST_EVENT_CODE="TEST12345" # Optional: for testing
425
- ```
426
-
427
- ### Server-Side Endpoint Implementation
444
+ ### Detailed Setup Guide
428
445
 
429
- Create an `/api/events` endpoint to handle server-side tracking:
430
-
431
- ```tsx
432
- // app/api/events/route.ts
433
- import { createFacebookCAPIService } from "@shopkit/analytics/services/facebook-capi";
434
- import { TEvent } from "@shopkit/analytics/types";
435
-
436
- /**
437
- * Get client IP address from request headers
438
- */
439
- function getClientIpAddress(request: Request): string | undefined {
440
- // Try different headers for IP address
441
- const forwarded = request.headers.get("x-forwarded-for");
442
- const realIp = request.headers.get("x-real-ip");
443
- const cfConnectingIp = request.headers.get("cf-connecting-ip");
444
-
445
- return forwarded?.split(",")[0] || realIp || cfConnectingIp || undefined;
446
- }
447
-
448
- export async function POST(request: Request) {
449
- try {
450
- const { events, userInfo } = await request.json();
451
-
452
- // Validate events array
453
- if (!Array.isArray(events) || events.length === 0) {
454
- return Response.json({ error: "Invalid events data" }, { status: 400 });
455
- }
456
-
457
- // Create CAPI service with explicit configuration
458
- const capiService = createFacebookCAPIService({
459
- accessToken: process.env.FACEBOOK_CAPI_ACCESS_TOKEN!,
460
- pixelId: process.env.NEXT_PUBLIC_PIXEL_ID!,
461
- testEventCode: process.env.FACEBOOK_TEST_EVENT_CODE,
462
- });
463
-
464
- if (!capiService) {
465
- console.warn("Facebook CAPI service not available - missing configuration");
466
- return Response.json(
467
- { error: "CAPI service not configured" },
468
- { status: 500 }
469
- );
470
- }
471
-
472
- // Enhance user info with server-side data
473
- const enhancedUserInfo = {
474
- ...userInfo,
475
- clientIpAddress: getClientIpAddress(request),
476
- };
477
-
478
- // Send events to Facebook CAPI
479
- await capiService.sendEvents(events as TEvent[], enhancedUserInfo);
480
-
481
- return Response.json({
482
- success: true,
483
- message: `Successfully sent ${events.length} events to Facebook CAPI`,
484
- });
485
- } catch (error) {
486
- console.error("API Events Error:", error);
487
- return Response.json(
488
- { error: "Failed to process events" },
489
- { status: 500 }
490
- );
491
- }
492
- }
493
- ```
446
+ For complete setup instructions, including troubleshooting and testing, see:
447
+ `node_modules/@shopkit/analytics/templates/nextjs/README.md`
494
448
 
495
449
  ### Supported Events
496
450
 
497
- The CAPI service currently supports these events (matching the PixelAdapter implementation):
451
+ The CAPI service currently supports these events:
498
452
 
499
453
  - `PAGE_VIEW` → Facebook `PageView`
500
454
  - `PRODUCT_VIEW` → Facebook `ViewContent`
@@ -521,25 +475,6 @@ publishEvent({
521
475
  });
522
476
  ```
523
477
 
524
- ### Browser Information Collection
525
-
526
- The system automatically collects browser information for enhanced server-side matching:
527
-
528
- - Client user agent
529
- - Facebook click ID (fbc) from URL parameters or cookies
530
- - Facebook browser ID (fbp) from cookies
531
- - Client IP address (server-side)
532
-
533
- ### Testing
534
-
535
- Use the test event code for development:
536
-
537
- ```bash
538
- FACEBOOK_TEST_EVENT_CODE="TEST12345"
539
- ```
540
-
541
- This allows you to test CAPI events without affecting production data.
542
-
543
478
  ## Professional Logging System
544
479
 
545
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.
@@ -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-Bym1_EAp.mjs';
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
3
  import '../subscriber-BoyOlh9t.mjs';
4
+ import '../types-C__2IBCj.mjs';
4
5
  import '@shopify/hydrogen-react';
@@ -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-DS9OI5Mz.js';
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
3
  import '../subscriber-BDAm_BAi.js';
4
+ import '../types-C__2IBCj.js';
4
5
  import '@shopify/hydrogen-react';