@@ -125,6 +125,7 @@ class CountlyClass {
125125 #lastRequestWasBackoff;
126126 #testModeTime;
127127 #requestTimeoutDuration;
128+ #contentFilterCallback;
128129 constructor ( ob ) {
129130 this . #self = this ;
130131 this . #global = ! Countly . i ;
@@ -196,6 +197,7 @@ class CountlyClass {
196197 this . #SCBackoffRequestAge = 24 ; // 24 hours
197198 this . #SCBackoffDuration = 60 ; // 60 seconds
198199 this . #requestTimeoutDuration = 30000 ; // 30 seconds
200+ this . #contentFilterCallback = null ;
199201 this . app_key = getConfig ( "app_key" , ob , null ) ;
200202 this . url = stripTrailingSlash ( getConfig ( "url" , ob , "" ) ) ;
201203 this . serialize = getConfig ( "serialize" , ob , Countly . serialize ) ;
@@ -3972,8 +3974,8 @@ class CountlyClass {
39723974 }
39733975
39743976 content = {
3975- enterContentZone : ( ) => {
3976- this . #enterContentZoneInternal( ) ;
3977+ enterContentZone : ( filter_callback ) => {
3978+ this . #enterContentZoneInternal( false , filter_callback ) ;
39773979 } ,
39783980 refreshContentZone : ( ) => {
39793981 this . #refreshContentZoneInternal( ) ;
@@ -3983,7 +3985,7 @@ class CountlyClass {
39833985 } ,
39843986 } ;
39853987
3986- #enterContentZoneInternal = ( forced ) => {
3988+ #enterContentZoneInternal = ( forced , filter_callback ) => {
39873989 if ( ! isBrowser ) {
39883990 this . #log( logLevelEnums . WARNING , "content.enterContentZone, window object is not available. Not entering content zone." ) ;
39893991 return ;
@@ -3992,11 +3994,16 @@ class CountlyClass {
39923994 this . #log( logLevelEnums . DEBUG , "content.enterContentZone, Already in content zone" ) ;
39933995 return ;
39943996 }
3997+ if ( filter_callback && typeof filter_callback == "function" ) {
3998+ this . #log( logLevelEnums . DEBUG , "content.enterContentZone, Content filter callback is provided" ) ;
3999+ this . #contentFilterCallback = filter_callback ;
4000+ }
4001+
39954002 if ( ! this . #initTimestamp || ( getMsTimestamp ( ) - this . #initTimestamp) < 4000 ) {
39964003 // settimeout
39974004 this . #log( logLevelEnums . DEBUG , "content.enterContentZone, Not enough time passed since initialization" ) ;
39984005 setTimeout ( ( ) => {
3999- this . #enterContentZoneInternal( ) ;
4006+ this . #enterContentZoneInternal( false ) ;
40004007 } , 4001 ) ;
40014008 return ;
40024009 }
@@ -4020,7 +4027,7 @@ class CountlyClass {
40204027 this . #processAsyncQueue( ) ;
40214028 this . #sendEventsForced( ) ;
40224029 setTimeout ( ( ) => {
4023- this . #enterContentZoneInternal( ) ;
4030+ this . #enterContentZoneInternal( false ) ;
40244031 } , 1000 ) ;
40254032 } ;
40264033
@@ -4087,6 +4094,22 @@ class CountlyClass {
40874094 return ;
40884095 }
40894096
4097+ // Build query params
4098+ const queryParams = { } ;
4099+ const qIndex = response . html . indexOf ( "?" ) ;
4100+ if ( qIndex !== - 1 ) {
4101+ const search = response . html . slice ( qIndex + 1 ) ;
4102+ new URLSearchParams ( search ) . forEach ( ( v , k ) => {
4103+ queryParams [ k ] = v ;
4104+ } ) ;
4105+ }
4106+
4107+ // Filter check
4108+ if ( this . #contentFilterCallback && this . #contentFilterCallback( queryParams ) === false ) {
4109+ this . #log( logLevelEnums . VERBOSE , "sendContentRequest, Content was filtered out by the content filter" ) ;
4110+ return ;
4111+ }
4112+
40904113 this . #displayContent( response ) ;
40914114 clearInterval ( this . #contentZoneTimer) ; // prevent multiple content requests while one is on
40924115 window . addEventListener ( 'message' , ( event ) => {
0 commit comments