Skip to content

Commit 14c306d

Browse files
committed
Add new consent category for device metrics data
1 parent 33dff45 commit 14c306d

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CountlyConfig.h

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

6363
//NOTE: Available consents
6464
typedef NSString* CLYConsent NS_EXTENSIBLE_STRING_ENUM;
65+
extern CLYConsent const CLYConsentMetrics;
6566
extern CLYConsent const CLYConsentSessions;
6667
extern CLYConsent const CLYConsentEvents;
6768
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),
@@ -199,6 +208,7 @@ - (NSArray *)allFeatures
199208
{
200209
return
201210
@[
211+
CLYConsentMetrics,
202212
CLYConsentSessions,
203213
CLYConsentEvents,
204214
CLYConsentUserDetails,
@@ -216,6 +226,19 @@ - (NSArray *)allFeatures
216226

217227
#pragma mark -
218228

229+
- (void)setConsentForMetrics:(BOOL)consentForMetrics
230+
{
231+
_consentForMetrics = consentForMetrics;
232+
233+
if (consentForMetrics)
234+
{
235+
CLY_LOG_D(@"Consent for Metrics is given.");
236+
}
237+
else
238+
{
239+
CLY_LOG_D(@"Consent for Metrics is cancelled.");
240+
}
241+
}
219242

220243
- (void)setConsentForSessions:(BOOL)consentForSessions
221244
{
@@ -425,6 +448,14 @@ - (void)setConsentForRemoteConfig:(BOOL)consentForRemoteConfig
425448

426449
#pragma mark -
427450

451+
- (BOOL)consentForMetrics
452+
{
453+
if (!self.requiresConsent)
454+
return YES;
455+
456+
return _consentForMetrics;
457+
}
458+
428459
- (BOOL)consentForSessions
429460
{
430461
if (!self.requiresConsent)

CountlyRemoteConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ - (NSURLRequest *)remoteConfigRequestForKeys:(NSArray *)keys omitKeys:(NSArray *
188188
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyRCKeyOmitKeys, [omitKeys cly_JSONify]];
189189
}
190190

191-
if (CountlyConsentManager.sharedInstance.consentForSessions)
191+
if (CountlyConsentManager.sharedInstance.consentForSessions || CountlyConsentManager.sharedInstance.consentForMetrics)
192192
{
193193
queryString = [queryString stringByAppendingFormat:@"&%@=%@", kCountlyQSKeyMetrics, [CountlyDeviceInfo metrics]];
194194
}

0 commit comments

Comments
 (0)