Skip to content

Commit

Permalink
Add new consent category for device metrics data
Browse files Browse the repository at this point in the history
  • Loading branch information
angelix committed Jul 18, 2023
1 parent 0c8889b commit 209510e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions CountlyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions CountlyConsentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions CountlyConsentManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#import "CountlyCommon.h"

CLYConsent const CLYConsentMetrics = @"metrics";
CLYConsent const CLYConsentSessions = @"sessions";
CLYConsent const CLYConsentEvents = @"events";
CLYConsent const CLYConsentUserDetails = @"users";
Expand All @@ -21,6 +22,7 @@

@implementation CountlyConsentManager

@synthesize consentForMetrics = _consentForMetrics;
@synthesize consentForSessions = _consentForSessions;
@synthesize consentForEvents = _consentForEvents;
@synthesize consentForUserDetails = _consentForUserDetails;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -179,6 +187,7 @@ - (void)sendConsents
{
NSDictionary * consents =
@{
CLYConsentMetrics: @(self.consentForMetrics),
CLYConsentSessions: @(self.consentForSessions),
CLYConsentEvents: @(self.consentForEvents),
CLYConsentUserDetails: @(self.consentForUserDetails),
Expand All @@ -200,6 +209,7 @@ - (NSArray *)allFeatures
{
return
@[
CLYConsentMetrics,
CLYConsentSessions,
CLYConsentEvents,
CLYConsentUserDetails,
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -444,6 +467,14 @@ - (void)setConsentForRemoteConfig:(BOOL)consentForRemoteConfig

#pragma mark -

- (BOOL)consentForMetrics
{
if (!self.requiresConsent)
return YES;

return _consentForMetrics;
}

- (BOOL)consentForSessions
{
if (!self.requiresConsent)
Expand Down
8 changes: 4 additions & 4 deletions CountlyRemoteConfigInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
Expand Down Expand Up @@ -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]];
}
Expand Down Expand Up @@ -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]];
}
Expand Down Expand Up @@ -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]];
}
Expand Down

0 comments on commit 209510e

Please sign in to comment.