77 take ,
88 type TakeEffect ,
99} from "redux-saga/effects" ;
10+ import type { SagaIterator } from "redux-saga" ;
1011import type {
1112 ReduxAction ,
1213 ReduxActionWithPromise ,
@@ -88,6 +89,7 @@ import {
8889 segmentInitUncertain ,
8990} from "actions/analyticsActions" ;
9091import { getSegmentState } from "selectors/analyticsSelectors" ;
92+ import { getOrganizationConfig } from "ee/selectors/organizationSelectors" ;
9193
9294export function * getCurrentUserSaga ( action ?: {
9395 payload ?: { userProfile ?: ApiResponse } ;
@@ -150,7 +152,28 @@ function* getSessionRecordingConfig() {
150152 } ;
151153}
152154
153- function * initTrackers ( currentUser : User ) {
155+ function shouldTrackUser (
156+ currentUser : User ,
157+ licenseActive : boolean ,
158+ featureFlag : boolean ,
159+ ) : boolean {
160+ try {
161+ const isAnonymous =
162+ currentUser ?. isAnonymous || currentUser ?. username === "anonymousUser" ;
163+
164+ if ( ! isAnonymous ) {
165+ return true ;
166+ }
167+
168+ const telemetryOn = currentUser ?. enableTelemetry ?? false ;
169+
170+ return isAnonymous && ( licenseActive || ( telemetryOn && ! featureFlag ) ) ;
171+ } catch ( error ) {
172+ return true ;
173+ }
174+ }
175+
176+ function * initTrackers ( currentUser : User ) : SagaIterator {
154177 try {
155178 const isFFFetched : boolean = yield select ( getFeatureFlagsFetched ) ;
156179
@@ -162,7 +185,21 @@ function* initTrackers(currentUser: User) {
162185 getSessionRecordingConfig ,
163186 ) ;
164187
165- yield call ( AnalyticsUtil . initialize , currentUser , sessionRecordingConfig ) ;
188+ const featureFlags : FeatureFlags = yield select ( selectFeatureFlags ) ;
189+ const organizationConfig = yield select ( getOrganizationConfig ) ;
190+
191+ const shouldTrack = shouldTrackUser (
192+ currentUser ,
193+ organizationConfig . license . active ,
194+ featureFlags . configure_block_event_tracking_for_anonymous_users ,
195+ ) ;
196+
197+ yield call (
198+ AnalyticsUtil . initialize ,
199+ currentUser ,
200+ sessionRecordingConfig ,
201+ shouldTrack ,
202+ ) ;
166203 yield put ( segmentInitSuccess ( ) ) ;
167204 } catch ( e ) {
168205 log . error ( e ) ;
0 commit comments