Skip to content

Commit 209510e

Browse files
committed
Add new consent category for device metrics data
1 parent 0c8889b commit 209510e

4 files changed

+37
-4
lines changed

CountlyConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern CLYDeviceIDType const CLYDeviceIDTypeNSUUID;
6363

6464
//NOTE: Available consents
6565
typedef NSString* CLYConsent NS_EXTENSIBLE_STRING_ENUM;
66+
extern CLYConsent const CLYConsentMetrics;
6667
extern CLYConsent const CLYConsentSessions;
6768
extern CLYConsent const CLYConsentEvents;
6869
extern CLYConsent const CLYConsentUserDetails;

CountlyConsentManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@property (nonatomic) BOOL requiresConsent;
1212

13+
@property (nonatomic, readonly) BOOL consentForMetrics;
1314
@property (nonatomic, readonly) BOOL consentForSessions;
1415
@property (nonatomic, readonly) BOOL consentForEvents;
1516
@property (nonatomic, readonly) BOOL consentForUserDetails;

CountlyConsentManager.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#import "CountlyCommon.h"
88

9+
CLYConsent const CLYConsentMetrics = @"metrics";
910
CLYConsent const CLYConsentSessions = @"sessions";
1011
CLYConsent const CLYConsentEvents = @"events";
1112
CLYConsent const CLYConsentUserDetails = @"users";
@@ -21,6 +22,7 @@
2122

2223
@implementation CountlyConsentManager
2324

25+
@synthesize consentForMetrics = _consentForMetrics;
2426
@synthesize consentForSessions = _consentForSessions;
2527
@synthesize consentForEvents = _consentForEvents;
2628
@synthesize consentForUserDetails = _consentForUserDetails;
@@ -83,6 +85,9 @@ - (void)giveConsentForFeatures:(NSArray *)features
8385
if ([features containsObject:CLYConsentUserDetails] && !self.consentForUserDetails)
8486
self.consentForUserDetails = YES;
8587

88+
if ([features containsObject:CLYConsentMetrics] && !self.consentForMetrics)
89+
self.consentForMetrics = YES;
90+
8691
if ([features containsObject:CLYConsentSessions] && !self.consentForSessions)
8792
self.consentForSessions = YES;
8893

@@ -137,6 +142,9 @@ - (void)cancelConsentForFeatures:(NSArray *)features shouldSkipSendingConsentsRe
137142
if (!self.requiresConsent)
138143
return;
139144

145+
if ([features containsObject:CLYConsentMetrics] && self.consentForMetrics)
146+
self.consentForMetrics = NO;
147+
140148
if ([features containsObject:CLYConsentSessions] && self.consentForSessions)
141149
self.consentForSessions = NO;
142150

@@ -179,6 +187,7 @@ - (void)sendConsents
179187
{
180188
NSDictionary * consents =
181189
@{
190+
CLYConsentMetrics: @(self.consentForMetrics),
182191
CLYConsentSessions: @(self.consentForSessions),
183192
CLYConsentEvents: @(self.consentForEvents),
184193
CLYConsentUserDetails: @(self.consentForUserDetails),
@@ -200,6 +209,7 @@ - (NSArray *)allFeatures
200209
{
201210
return
202211
@[
212+
CLYConsentMetrics,
203213
CLYConsentSessions,
204214
CLYConsentEvents,
205215
CLYConsentUserDetails,
@@ -234,6 +244,19 @@ - (BOOL)hasAnyConsent
234244

235245
#pragma mark -
236246

247+
- (void)setConsentForMetrics:(BOOL)consentForMetrics
248+
{
249+
_consentForMetrics = consentForMetrics;
250+
251+
if (consentForMetrics)
252+
{
253+
CLY_LOG_D(@"Consent for Metrics is given.");
254+
}
255+
else
256+
{
257+
CLY_LOG_D(@"Consent for Metrics is cancelled.");
258+
}
259+
}
237260

238261
- (void)setConsentForSessions:(BOOL)consentForSessions
239262
{
@@ -444,6 +467,14 @@ - (void)setConsentForRemoteConfig:(BOOL)consentForRemoteConfig
444467

445468
#pragma mark -
446469

470+
- (BOOL)consentForMetrics
471+
{
472+
if (!self.requiresConsent)
473+
return YES;
474+
475+
return _consentForMetrics;
476+
}
477+
447478
- (BOOL)consentForSessions
448479
{
449480
if (!self.requiresConsent)

CountlyRemoteConfigInternal.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ - (NSURLRequest *)remoteConfigRequestForKeys:(NSArray *)keys omitKeys:(NSArray *
242242
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyRCKeyOmitKeys, [omitKeys cly_JSONify]];
243243
}
244244

245-
if (CountlyConsentManager.sharedInstance.consentForSessions)
245+
if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics)
246246
{
247247
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]];
248248
}
@@ -609,7 +609,7 @@ - (NSURLRequest *)downloadVariantsRequest
609609

610610
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMethod, kCountlyRCKeyFetchVariant];
611611

612-
if (CountlyConsentManager.sharedInstance.consentForSessions)
612+
if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics)
613613
{
614614
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]];
615615
}
@@ -646,7 +646,7 @@ - (NSURLRequest *)enrollInVarianRequestForKey:(NSString *)key variantName:(NSStr
646646
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyRCKeyVariant, variantName.cly_URLEscaped];
647647
}
648648

649-
if (CountlyConsentManager.sharedInstance.consentForSessions)
649+
if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics)
650650
{
651651
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]];
652652
}
@@ -720,7 +720,7 @@ - (NSURLRequest *)aBRequestForMethod:(NSString*)method keys:(NSArray*)keys
720720
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyRCKeyKeys, [keys cly_JSONify]];
721721
}
722722

723-
if (CountlyConsentManager.sharedInstance.consentForSessions)
723+
if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics)
724724
{
725725
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]];
726726
}

0 commit comments

Comments
 (0)