@@ -220,40 +220,72 @@ Countly.Bulk = Bulk;
220220 *
221221 * Resets Countly to its initial state (used mainly to wipe the queues in memory).
222222 * Calling this will result in a loss of data
223+ * @param {boolean } preventRequestProcessing - if true request queues wont be processed, for testing purposes
223224 */
224- Countly . halt = function name ( ) {
225+ Countly . halt = function ( preventRequestProcessing ) {
225226 cc . log ( cc . logLevelEnums . WARNING , "halt, Resetting Countly" ) ;
226227 inited = false ;
227228 sessionStarted = false ;
228- beatInterval = 500 ,
229- queueSize = 1000 ,
230- requestQueue = [ ] ,
231- eventQueue = [ ] ,
232- remoteConfigs = { } ,
233- crashLogs = [ ] ,
234- timedEvents = { } ,
235- crashSegments = null ,
236- autoExtend = true ,
237- storedDuration = 0 ,
238- lastView = null ,
239- lastViewTime = 0 ,
240- lastMsTs = 0 ,
241- lastViewStoredDuration = 0 ,
242- failTimeout = 0 ,
243- failTimeoutAmount = 60 ,
244- sessionUpdate = 60 ,
245- maxEventBatch = 100 ,
246- readyToProcess = true ,
247- trackTime = true ,
248- metrics = { } ,
249- lastParams = { } ,
250- maxKeyLength = 128 ,
251- maxValueSize = 256 ,
252- maxSegmentationValues = 30 ,
253- maxBreadcrumbCount = 100 ,
254- maxStackTraceLinesPerThread = 30 ,
255- maxStackTraceLineLength = 200 ,
229+ beatInterval = 500 ;
230+ queueSize = 1000 ;
231+ requestQueue = [ ] ;
232+ eventQueue = [ ] ;
233+ remoteConfigs = { } ;
234+ crashLogs = [ ] ;
235+ timedEvents = { } ;
236+ crashSegments = null ;
237+ autoExtend = true ;
238+ storedDuration = 0 ;
239+ lastView = null ;
240+ lastViewTime = 0 ;
241+ lastMsTs = 0 ;
242+ lastViewStoredDuration = 0 ;
243+ failTimeout = 0 ;
244+ failTimeoutAmount = 60 ;
245+ sessionUpdate = 60 ;
246+ maxEventBatch = 100 ;
247+ readyToProcess = ! preventRequestProcessing ;
248+ trackTime = true ;
249+ metrics = { } ;
250+ lastParams = { } ;
251+ maxKeyLength = 128 ;
252+ maxValueSize = 256 ;
253+ maxSegmentationValues = 30 ;
254+ maxBreadcrumbCount = 100 ;
255+ maxStackTraceLinesPerThread = 30 ;
256+ maxStackTraceLineLength = 200 ;
256257 __data = { } ;
258+
259+ //cc DEBUG
260+ cc . debug = false ;
261+ cc . debugBulk = false ;
262+ cc . debugBulkUser = false ;
263+
264+ //CONSENTS
265+ consents = { } ;
266+ for ( var a = 0 ; a < Countly . features . length ; a ++ ) {
267+ consents [ Countly . features [ a ] ] = { } ;
268+ }
269+
270+ //device_id
271+ Countly . device_id = undefined ;
272+ Countly . remote_config = undefined ;
273+ Countly . require_consent = false ;
274+ Countly . debug = undefined ;
275+ Countly . app_key = undefined ;
276+ Countly . url = undefined ;
277+ Countly . app_version = undefined ;
278+ Countly . country_code = undefined ;
279+ Countly . city = undefined ;
280+ Countly . ip_address = undefined ;
281+ Countly . force_post = undefined ;
282+ Countly . storage_path = undefined ;
283+ Countly . require_consent = undefined ;
284+ Countly . http_options = undefined ;
285+
286+ asyncWriteLock = false ;
287+ asyncWriteQueue = [ ] ;
288+
257289 } ;
258290
259291 /**
@@ -304,10 +336,16 @@ Countly.Bulk = Bulk;
304336 Countly . check_consent = function ( feature ) {
305337 if ( ! Countly . require_consent ) {
306338 //we don't need to have specific consents
339+ cc . log ( cc . logLevelEnums . INFO , "check_consent, Require consent is off. Giving consent for : [ " + feature + " ] feature." ) ;
340+ return true ;
341+ }
342+ if ( consents [ feature ] && consents [ feature ] . optin ) {
343+ cc . log ( cc . logLevelEnums . INFO , "check_consent, Giving consent for : [ " + feature + " ] feature." ) ;
307344 return true ;
308345 }
309- if ( consents [ feature ] ) {
310- return ( consents [ feature ] && consents [ feature ] . optin ) ? true : false ;
346+ if ( consents [ feature ] && ! consents [ feature ] . optin ) {
347+ cc . log ( cc . logLevelEnums . ERROR , "check_consent, User is not optin. Consent refused for : [ " + feature + " ] feature." ) ;
348+ return false ;
311349 }
312350 else {
313351 cc . log ( cc . logLevelEnums . ERROR , "check_consent, No feature available for " + feature ) ;
@@ -427,7 +465,7 @@ Countly.Bulk = Bulk;
427465 updateConsent ( ) ;
428466 }
429467 }
430- cc . log ( " Consent removal triggered.") ;
468+ cc . log ( cc . logLevelEnums . DEBUG , "remove_consent, Consent removal triggered.") ;
431469
432470 }
433471 else {
@@ -453,7 +491,7 @@ Countly.Bulk = Bulk;
453491 }
454492 }
455493 toRequestQueue ( { consent : JSON . stringify ( consentMessage ) } ) ;
456- cc . log ( "Consent update request has been sent to the queue." ) ;
494+ cc . log ( cc . logLevelEnums . DEBUG , "Consent update request has been sent to the queue." ) ;
457495 } , 1000 ) ;
458496 } ;
459497
@@ -573,11 +611,41 @@ Countly.Bulk = Bulk;
573611 * @param {Object= } event.segmentation - object with segments key /values
574612 **/
575613 Countly . add_event = function ( event ) {
576- if ( Countly . check_consent ( "events" ) ) {
614+ cc . log ( 'Trying to add the event: [ ' + event . key + ' ]' ) ;
615+ //initially no consent is given
616+ var respectiveConsent = false ;
617+ //to match the internal events and their respective required consents. Sets respectiveConsent to true if the consent is given
618+ switch ( event . key ) {
619+ case cc . internalEventKeyEnums . NPS :
620+ respectiveConsent = Countly . check_consent ( 'feedback' ) ;
621+ break ;
622+ case cc . internalEventKeyEnums . SURVEY :
623+ respectiveConsent = Countly . check_consent ( 'feedback' ) ;
624+ break ;
625+ case cc . internalEventKeyEnums . STAR_RATING :
626+ respectiveConsent = Countly . check_consent ( 'star-rating' ) ;
627+ break ;
628+ case cc . internalEventKeyEnums . VIEW :
629+ respectiveConsent = Countly . check_consent ( 'views' ) ;
630+ break ;
631+ case cc . internalEventKeyEnums . ORIENTATION :
632+ respectiveConsent = Countly . check_consent ( 'users' ) ;
633+ break ;
634+ case cc . internalEventKeyEnums . PUSH_ACTION :
635+ respectiveConsent = Countly . check_consent ( 'push' ) ;
636+ break ;
637+ case cc . internalEventKeyEnums . ACTION :
638+ respectiveConsent = Countly . check_consent ( 'clicks' ) || Countly . check_consent ( 'scroll' ) ;
639+ break ;
640+ default :
641+ respectiveConsent = Countly . check_consent ( 'events' ) ;
642+
643+ }
644+ //if consent is given adds event to the queue
645+ if ( respectiveConsent ) {
577646 add_cly_events ( event ) ;
578647 }
579648 } ;
580-
581649 /**
582650 * Add events to event queue
583651 * @memberof Countly._internals
@@ -894,7 +962,7 @@ Countly.Bulk = Bulk;
894962 if ( Countly . check_consent ( "events" ) ) {
895963 var props = [ "widget_id" , "contactMe" , "platform" , "app_version" , "rating" , "email" , "comment" ] ;
896964 var event = {
897- key : "[CLY]_star_rating" ,
965+ key : cc . internalEventKeyEnums . STAR_RATING ,
898966 count : 1 ,
899967 segmentation : { }
900968 } ;
@@ -1113,7 +1181,7 @@ Countly.Bulk = Bulk;
11131181 //track pageview
11141182 if ( Countly . check_consent ( "views" ) ) {
11151183 add_cly_events ( {
1116- "key" : "[CLY]_view" ,
1184+ "key" : cc . internalEventKeyEnums . VIEW ,
11171185 "segmentation" : segments
11181186 } ) ;
11191187 }
@@ -1229,7 +1297,7 @@ Countly.Bulk = Bulk;
12291297 //track pageview
12301298 if ( Countly . check_consent ( "views" ) ) {
12311299 add_cly_events ( {
1232- "key" : "[CLY]_view" ,
1300+ "key" : cc . internalEventKeyEnums . VIEW ,
12331301 "dur" : cc . getTimestamp ( ) - lastViewTime ,
12341302 "segmentation" : segments
12351303 } ) ;
@@ -1328,7 +1396,7 @@ Countly.Bulk = Bulk;
13281396 if ( err ) {
13291397 requestQueue . unshift ( res ) ;
13301398 failTimeout = cc . getTimestamp ( ) + failTimeoutAmount ;
1331- cc . log ( " Encountered a problem while making the request.") ;
1399+ cc . log ( cc . logLevelEnums . ERROR , "makeRequest, Encountered a problem while making the request.") ;
13321400 }
13331401 storeSet ( "cly_queue" , requestQueue ) ;
13341402 readyToProcess = true ;
0 commit comments