diff --git a/CountlyConfig.h b/CountlyConfig.h index 2bcc2098..d88429f7 100644 --- a/CountlyConfig.h +++ b/CountlyConfig.h @@ -63,6 +63,7 @@ extern CLYDeviceIDType const CLYDeviceIDTypeNSUUID; //NOTE: Available consents typedef NSString* CLYConsent NS_EXTENSIBLE_STRING_ENUM; +extern CLYConsent const CLYConsentMetrics; extern CLYConsent const CLYConsentSessions; extern CLYConsent const CLYConsentEvents; extern CLYConsent const CLYConsentUserDetails; diff --git a/CountlyConsentManager.h b/CountlyConsentManager.h index 9e7dd0ce..09687cc7 100644 --- a/CountlyConsentManager.h +++ b/CountlyConsentManager.h @@ -10,6 +10,7 @@ @property (nonatomic) BOOL requiresConsent; +@property (nonatomic, readonly) BOOL consentForMetrics; @property (nonatomic, readonly) BOOL consentForSessions; @property (nonatomic, readonly) BOOL consentForEvents; @property (nonatomic, readonly) BOOL consentForUserDetails; diff --git a/CountlyConsentManager.m b/CountlyConsentManager.m index f4c918db..df4f7d44 100644 --- a/CountlyConsentManager.m +++ b/CountlyConsentManager.m @@ -6,6 +6,7 @@ #import "CountlyCommon.h" +CLYConsent const CLYConsentMetrics = @"metrics"; CLYConsent const CLYConsentSessions = @"sessions"; CLYConsent const CLYConsentEvents = @"events"; CLYConsent const CLYConsentUserDetails = @"users"; @@ -21,6 +22,7 @@ @implementation CountlyConsentManager +@synthesize consentForMetrics = _consentForMetrics; @synthesize consentForSessions = _consentForSessions; @synthesize consentForEvents = _consentForEvents; @synthesize consentForUserDetails = _consentForUserDetails; @@ -83,6 +85,9 @@ - (void)giveConsentForFeatures:(NSArray *)features if ([features containsObject:CLYConsentUserDetails] && !self.consentForUserDetails) self.consentForUserDetails = YES; + if ([features containsObject:CLYConsentMetrics] && !self.consentForMetrics) + self.consentForMetrics = YES; + if ([features containsObject:CLYConsentSessions] && !self.consentForSessions) self.consentForSessions = YES; @@ -137,6 +142,9 @@ - (void)cancelConsentForFeatures:(NSArray *)features shouldSkipSendingConsentsRe if (!self.requiresConsent) return; + if ([features containsObject:CLYConsentMetrics] && self.consentForMetrics) + self.consentForMetrics = NO; + if ([features containsObject:CLYConsentSessions] && self.consentForSessions) self.consentForSessions = NO; @@ -179,6 +187,7 @@ - (void)sendConsents { NSDictionary * consents = @{ + CLYConsentMetrics: @(self.consentForMetrics), CLYConsentSessions: @(self.consentForSessions), CLYConsentEvents: @(self.consentForEvents), CLYConsentUserDetails: @(self.consentForUserDetails), @@ -200,6 +209,7 @@ - (NSArray *)allFeatures { return @[ + CLYConsentMetrics, CLYConsentSessions, CLYConsentEvents, CLYConsentUserDetails, @@ -234,6 +244,19 @@ - (BOOL)hasAnyConsent #pragma mark - +- (void)setConsentForMetrics:(BOOL)consentForMetrics +{ + _consentForMetrics = consentForMetrics; + + if (consentForMetrics) + { + CLY_LOG_D(@"Consent for Metrics is given."); + } + else + { + CLY_LOG_D(@"Consent for Metrics is cancelled."); + } +} - (void)setConsentForSessions:(BOOL)consentForSessions { @@ -444,6 +467,14 @@ - (void)setConsentForRemoteConfig:(BOOL)consentForRemoteConfig #pragma mark - +- (BOOL)consentForMetrics +{ + if (!self.requiresConsent) + return YES; + + return _consentForMetrics; +} + - (BOOL)consentForSessions { if (!self.requiresConsent) diff --git a/CountlyRemoteConfigInternal.m b/CountlyRemoteConfigInternal.m index 7727f841..a36ecdd4 100644 --- a/CountlyRemoteConfigInternal.m +++ b/CountlyRemoteConfigInternal.m @@ -242,7 +242,7 @@ - (NSURLRequest *)remoteConfigRequestForKeys:(NSArray *)keys omitKeys:(NSArray * queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyRCKeyOmitKeys, [omitKeys cly_JSONify]]; } - if (CountlyConsentManager.sharedInstance.consentForSessions) + if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics) { queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]]; } @@ -609,7 +609,7 @@ - (NSURLRequest *)downloadVariantsRequest queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMethod, kCountlyRCKeyFetchVariant]; - if (CountlyConsentManager.sharedInstance.consentForSessions) + if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics) { queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]]; } @@ -646,7 +646,7 @@ - (NSURLRequest *)enrollInVarianRequestForKey:(NSString *)key variantName:(NSStr queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyRCKeyVariant, variantName.cly_URLEscaped]; } - if (CountlyConsentManager.sharedInstance.consentForSessions) + if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics) { queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]]; } @@ -720,7 +720,7 @@ - (NSURLRequest *)aBRequestForMethod:(NSString*)method keys:(NSArray*)keys queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyRCKeyKeys, [keys cly_JSONify]]; } - if (CountlyConsentManager.sharedInstance.consentForSessions) + if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics) { queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]]; }