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 Aug 29, 2022
1 parent 51a22dc commit 0775944
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CountlyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 @@ -23,6 +24,7 @@

@implementation CountlyConsentManager

@synthesize consentForMetrics = _consentForMetrics;
@synthesize consentForSessions = _consentForSessions;
@synthesize consentForEvents = _consentForEvents;
@synthesize consentForUserDetails = _consentForUserDetails;
Expand Down Expand Up @@ -82,6 +84,9 @@ - (void)giveConsentForFeatures:(NSArray *)features
if ([features containsObject:CLYConsentLocation] && !self.consentForLocation)
self.consentForLocation = YES;

if ([features containsObject:CLYConsentMetrics] && !self.consentForMetrics)
self.consentForMetrics = YES;

if ([features containsObject:CLYConsentSessions] && !self.consentForSessions)
self.consentForSessions = YES;

Expand Down Expand Up @@ -139,6 +144,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 @@ -181,6 +189,7 @@ - (void)sendConsents
{
NSDictionary * consents =
@{
CLYConsentMetrics: @(self.consentForMetrics),
CLYConsentSessions: @(self.consentForSessions),
CLYConsentEvents: @(self.consentForEvents),
CLYConsentUserDetails: @(self.consentForUserDetails),
Expand All @@ -201,6 +210,7 @@ - (NSArray *)allFeatures
{
return
@[
CLYConsentMetrics,
CLYConsentSessions,
CLYConsentEvents,
CLYConsentUserDetails,
Expand All @@ -225,6 +235,19 @@ - (BOOL)containsFeedbackOrStarRating:(NSArray *)features

#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 @@ -433,6 +456,14 @@ - (void)setConsentForRemoteConfig:(BOOL)consentForRemoteConfig

#pragma mark -

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

return _consentForMetrics;
}

- (BOOL)consentForSessions
{
if (!self.requiresConsent)
Expand Down
2 changes: 1 addition & 1 deletion CountlyRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,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

0 comments on commit 0775944

Please sign in to comment.