@@ -493,6 +493,14 @@ function alias(
493
493
] ;
494
494
}
495
495
496
+ function isAnonymous ( ctx : FullContext , event : AnalyticsServerEvent ) {
497
+ if ( ctx . props . simplifiedIdMerge ) {
498
+ return ! event . userId ;
499
+ } else {
500
+ return ! event . userId && ! event . traits ?. email && ! event . context ?. traits ?. email ;
501
+ }
502
+ }
503
+
496
504
function getDistinctId ( ctx : FullContext , event : AnalyticsServerEvent , deviceId : string ) {
497
505
if ( ctx . props . simplifiedIdMerge ) {
498
506
return event . userId ? `${ event . userId } ` : `$device:${ deviceId } ` ;
@@ -536,6 +544,12 @@ const MixpanelDestination: JitsuFunction<AnalyticsServerEvent, MixpanelCredentia
536
544
return ;
537
545
}
538
546
}
547
+ // no userId or email
548
+ const anonymous = isAnonymous ( ctx , event ) ;
549
+ if ( anonymous && ! ctx . props . enableAnonymousUserProfiles ) {
550
+ return ;
551
+ }
552
+
539
553
const trackPageView = typeof ctx . props . sendPageEvents === "undefined" || ctx . props . sendPageEvents ;
540
554
const deviceId = getDeviceId ( ctx , event ) ;
541
555
if ( ! deviceId ) {
@@ -548,18 +562,15 @@ const MixpanelDestination: JitsuFunction<AnalyticsServerEvent, MixpanelCredentia
548
562
if ( invalidDistinctIds . has ( distinctId ) ) {
549
563
throw new Error ( `Invalid distinctId '${ distinctId } '. Skipping event: ${ JSON . stringify ( event ) } ` ) ;
550
564
}
551
- // no userId or email
552
- const isAnonymous = event . anonymousId && distinctId . endsWith ( event . anonymousId ) ;
553
- if ( isAnonymous && ! ctx . props . enableAnonymousUserProfiles ) {
554
- return ;
555
- }
565
+
556
566
try {
557
567
const messages : MixpanelRequest [ ] = [ ] ;
558
568
if ( event . type === "identify" ) {
559
569
if ( event . userId ) {
560
570
messages . push ( ...setProfileMessage ( ctx , distinctId , event ) ) ;
561
571
}
562
- if ( ! ctx . props . simplifiedIdMerge && ! isAnonymous ) {
572
+ if ( ! ctx . props . simplifiedIdMerge && ! anonymous && ctx . props . enableAnonymousUserProfiles ) {
573
+ // we merge distinctId with anonymousId. It makes sense only when enableAnonymousUserProfiles is enabled
563
574
if ( event . userId ) {
564
575
messages . push ( ...merge ( ctx , event . messageId , distinctId , `${ event . anonymousId } ` ) ) ;
565
576
} else {
0 commit comments