@deriv-com/analytics 1.38.7 → 1.38.9
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 +38 -8
- package/dist/browser/analytics.bundle.global.js +12 -12
- package/dist/browser/analytics.bundle.global.js.map +1 -1
- package/dist/browser/analytics.esm.mjs +1 -7
- package/dist/browser/analytics.esm.mjs.map +1 -1
- package/dist/chunk-7CT4XR74.mjs +3 -0
- package/dist/chunk-7CT4XR74.mjs.map +1 -0
- package/dist/chunk-BVGYK54Z.js +4 -0
- package/dist/chunk-BVGYK54Z.js.map +1 -0
- package/dist/chunk-D2MKQCJB.mjs +3 -0
- package/dist/chunk-D2MKQCJB.mjs.map +1 -0
- package/dist/chunk-FE5YWK6A.js +3 -0
- package/dist/chunk-FE5YWK6A.js.map +1 -0
- package/dist/chunk-ID2GN2PS.mjs +4 -0
- package/dist/chunk-ID2GN2PS.mjs.map +1 -0
- package/dist/chunk-ILN7DKKL.js +3 -0
- package/dist/chunk-ILN7DKKL.js.map +1 -0
- package/dist/chunk-OB6HH25Z.mjs +9 -0
- package/dist/chunk-OB6HH25Z.mjs.map +1 -0
- package/dist/chunk-YGU4ZMIH.mjs +14 -0
- package/dist/chunk-YGU4ZMIH.mjs.map +1 -0
- package/dist/growthbook-3K6VUME4.mjs +3 -0
- package/dist/growthbook-3K6VUME4.mjs.map +1 -0
- package/dist/index.d.mts +9 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/metafile-iife.json +1 -1
- package/dist/posthog-ANAV4RFJ.mjs +6 -0
- package/dist/posthog-ANAV4RFJ.mjs.map +1 -0
- package/dist/{posthog-lAeI7PhD.d.mts → posthog-Ds4g1sJf.d.mts} +21 -6
- package/dist/{posthog-DV6iayrn.d.ts → posthog-DvDj4azD.d.ts} +21 -6
- package/dist/providers/growthbook/index.d.mts +5 -3
- package/dist/providers/growthbook/index.d.ts +5 -3
- package/dist/providers/growthbook/index.js +2 -2
- package/dist/providers/growthbook/index.js.map +1 -1
- package/dist/providers/growthbook/index.mjs +2 -2
- package/dist/providers/growthbook/index.mjs.map +1 -1
- package/dist/providers/posthog/index.d.mts +1 -1
- package/dist/providers/posthog/index.d.ts +1 -1
- package/dist/providers/posthog/index.js +2 -2
- package/dist/providers/posthog/index.js.map +1 -1
- package/dist/providers/posthog/index.mjs +2 -2
- package/dist/providers/posthog/index.mjs.map +1 -1
- package/dist/providers/rudderstack/index.d.mts +5 -2
- package/dist/providers/rudderstack/index.d.ts +5 -2
- package/dist/providers/rudderstack/index.js +1 -1
- package/dist/providers/rudderstack/index.mjs +1 -1
- package/dist/utils/analytics-cache/index.d.mts +14 -5
- package/dist/utils/analytics-cache/index.d.ts +14 -5
- package/dist/utils/analytics-cache/index.js +1 -1
- package/dist/utils/analytics-cache/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-3LFZFQL4.mjs +0 -3
- package/dist/chunk-3LFZFQL4.mjs.map +0 -1
- package/dist/chunk-CAKVOFLO.js +0 -3
- package/dist/chunk-CAKVOFLO.js.map +0 -1
- package/dist/chunk-DNCZM4KN.mjs +0 -4
- package/dist/chunk-DNCZM4KN.mjs.map +0 -1
- package/dist/chunk-EMF3RT6E.mjs +0 -14
- package/dist/chunk-EMF3RT6E.mjs.map +0 -1
- package/dist/chunk-HQX3Z7PF.mjs +0 -3
- package/dist/chunk-HQX3Z7PF.mjs.map +0 -1
- package/dist/chunk-LKLVBL24.js +0 -3
- package/dist/chunk-LKLVBL24.js.map +0 -1
- package/dist/chunk-NOEKD4DT.js +0 -4
- package/dist/chunk-NOEKD4DT.js.map +0 -1
- package/dist/chunk-UDVSKE3Y.mjs +0 -3
- package/dist/chunk-UDVSKE3Y.mjs.map +0 -1
- package/dist/growthbook-NJGOOJH4.mjs +0 -3
- package/dist/growthbook-NJGOOJH4.mjs.map +0 -1
- package/dist/posthog-ZJSIYY5Q.mjs +0 -6
- package/dist/posthog-ZJSIYY5Q.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ A modern, tree-shakeable analytics library for tracking user events with RudderS
|
|
|
36
36
|
- [Page Views](#page-views)
|
|
37
37
|
- [User Attributes](#user-attributes)
|
|
38
38
|
- [Caching & Offline Support](#caching--offline-support)
|
|
39
|
+
- [Debug Mode](#debug-mode)
|
|
39
40
|
- [Advanced Usage](#advanced-usage)
|
|
40
41
|
- [API Reference](#api-reference)
|
|
41
42
|
- [Performance](#performance)
|
|
@@ -141,9 +142,10 @@ Analytics.trackEvent('ce_login_form', {
|
|
|
141
142
|
})
|
|
142
143
|
|
|
143
144
|
// User identification syncs with both providers
|
|
145
|
+
// When using PostHog, pass email via provider-specific traits (see User Identification section)
|
|
144
146
|
Analytics.identifyEvent('CR123456', {
|
|
145
|
-
language: 'en',
|
|
146
|
-
country_of_residence: 'US',
|
|
147
|
+
rudderstack: { language: 'en', country_of_residence: 'US' },
|
|
148
|
+
posthog: { email: 'user@example.com', language: 'en', country_of_residence: 'US' },
|
|
147
149
|
})
|
|
148
150
|
```
|
|
149
151
|
|
|
@@ -438,6 +440,7 @@ await Analytics.initialise({
|
|
|
438
440
|
autocapture: true,
|
|
439
441
|
},
|
|
440
442
|
},
|
|
443
|
+
debug: false, // Enable to log all analytics calls to the console
|
|
441
444
|
})
|
|
442
445
|
```
|
|
443
446
|
|
|
@@ -486,23 +489,24 @@ Analytics.identifyEvent('CR123456')
|
|
|
486
489
|
#### Identification with Custom Traits
|
|
487
490
|
|
|
488
491
|
```typescript
|
|
489
|
-
// Send same traits to both RudderStack and PostHog
|
|
492
|
+
// Send same traits to both RudderStack and PostHog (no PostHog-specific fields)
|
|
490
493
|
Analytics.identifyEvent('CR123456', {
|
|
491
494
|
language: 'en',
|
|
492
495
|
country_of_residence: 'US',
|
|
493
496
|
account_type: 'real',
|
|
494
497
|
})
|
|
495
498
|
|
|
496
|
-
// Send
|
|
499
|
+
// Send provider-specific traits (recommended when using PostHog)
|
|
500
|
+
// PostHog requires `email` to automatically compute the `is_internal` flag
|
|
497
501
|
Analytics.identifyEvent('CR123456', {
|
|
498
502
|
rudderstack: {
|
|
499
503
|
language: 'en',
|
|
500
504
|
custom_field: 'value',
|
|
501
505
|
},
|
|
502
506
|
posthog: {
|
|
507
|
+
email: 'user@example.com', // Required for PostHog — used to set is_internal flag
|
|
503
508
|
language: 'en',
|
|
504
509
|
country_of_residence: 'US',
|
|
505
|
-
subscription_tier: 'premium',
|
|
506
510
|
},
|
|
507
511
|
})
|
|
508
512
|
```
|
|
@@ -513,6 +517,7 @@ Analytics.identifyEvent('CR123456', {
|
|
|
513
517
|
- If you pass an object with `rudderstack` or `posthog` keys, provider-specific traits are used
|
|
514
518
|
- Queues identify calls if provider not yet initialized
|
|
515
519
|
- PostHog automatically handles aliasing between anonymous and identified users
|
|
520
|
+
- When `email` is provided in PostHog traits, the `is_internal` flag is automatically computed and set as a person property — `email` itself is **not** forwarded to PostHog
|
|
516
521
|
|
|
517
522
|
### Page Views
|
|
518
523
|
|
|
@@ -653,6 +658,20 @@ cacheTrackEvents.pageLoadEvent([
|
|
|
653
658
|
cacheTrackEvents.pageView()
|
|
654
659
|
```
|
|
655
660
|
|
|
661
|
+
## Debug Mode
|
|
662
|
+
|
|
663
|
+
Enable verbose logging to trace every analytics call in the browser console:
|
|
664
|
+
|
|
665
|
+
```typescript
|
|
666
|
+
await Analytics.initialise({
|
|
667
|
+
rudderstackKey: 'YOUR_KEY',
|
|
668
|
+
posthogOptions: { apiKey: 'phc_YOUR_KEY' },
|
|
669
|
+
debug: true,
|
|
670
|
+
})
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
All logs are prefixed with `[ANALYTIC]` (e.g., `[ANALYTIC][RudderStack] trackEvent | ...`). Useful during development and QA to verify events are firing correctly without opening the network tab.
|
|
674
|
+
|
|
656
675
|
## Advanced Usage
|
|
657
676
|
|
|
658
677
|
### Independent Package Usage
|
|
@@ -678,8 +697,8 @@ const posthog = Posthog.getPosthogInstance({
|
|
|
678
697
|
// Track events
|
|
679
698
|
posthog.capture('button_clicked', { button_name: 'signup' })
|
|
680
699
|
|
|
681
|
-
// Identify users
|
|
682
|
-
posthog.identifyEvent('CR123', { language: 'en' })
|
|
700
|
+
// Identify users — email is required and used to compute is_internal
|
|
701
|
+
posthog.identifyEvent('CR123', { email: 'user@example.com', language: 'en' })
|
|
683
702
|
|
|
684
703
|
// Check feature flags
|
|
685
704
|
const isEnabled = posthog.isFeatureEnabled('new-feature')
|
|
@@ -743,6 +762,8 @@ interface Options {
|
|
|
743
762
|
allowedDomains?: string[]
|
|
744
763
|
config?: PostHogConfig
|
|
745
764
|
}
|
|
765
|
+
/** Enable verbose debug logging — all analytics calls are logged prefixed with [ANALYTIC] */
|
|
766
|
+
debug?: boolean
|
|
746
767
|
}
|
|
747
768
|
```
|
|
748
769
|
|
|
@@ -756,7 +777,16 @@ Track page navigation.
|
|
|
756
777
|
|
|
757
778
|
### `identifyEvent(userId?: string, traits?: Record<string, any>): void`
|
|
758
779
|
|
|
759
|
-
Link anonymous session to a user ID with optional traits.
|
|
780
|
+
Link anonymous session to a user ID with optional traits. When PostHog is active and traits include an `email` field (via provider-specific `posthog` key), `is_internal` is automatically computed and set as a person property — the email itself is not stored in PostHog.
|
|
781
|
+
|
|
782
|
+
### `backfillPersonProperties(user_id: string, email: string): void`
|
|
783
|
+
|
|
784
|
+
Backfills PostHog person properties for users identified in previous sessions. Sets `client_id` and `is_internal` if they are not already present. No-op if PostHog is not initialized or `user_id` is empty.
|
|
785
|
+
|
|
786
|
+
```typescript
|
|
787
|
+
// Call after PostHog has loaded and user ID is available
|
|
788
|
+
Analytics.backfillPersonProperties('CR123456', 'user@example.com')
|
|
789
|
+
```
|
|
760
790
|
|
|
761
791
|
### `setAttributes(attributes: TCoreAttributes): void`
|
|
762
792
|
|