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 33dff45 commit 14c306d
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 @@ -62,6 +62,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 @@ -199,6 +208,7 @@ - (NSArray *)allFeatures
{
return
@[
CLYConsentMetrics,
CLYConsentSessions,
CLYConsentEvents,
CLYConsentUserDetails,
Expand All @@ -216,6 +226,19 @@ - (NSArray *)allFeatures

#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 @@ -425,6 +448,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 14c306d

Please sign in to comment.