Skip to content

Commit ca9e1db

Browse files
Merge pull request #217 from erkanyildiz/dev_23.02.0
For 23.02.0
2 parents 54ac22f + 2c7f347 commit ca9e1db

12 files changed

+90
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 23.02.0
2+
- Added event IDs
3+
- Added current and previous view IDs to events
4+
- Added sending pending events before sending user details on `save` call.
5+
6+
7+
18
## 22.09.0
29
- Deleted previously deprecated `userLoggedIn:` and `userLoggedOut` methods
310
- Added new exception recording methods: `recordException:`, `recordException:isFatal:`, `recordException:isFatal:stackTrace:segmentation:`

Countly-PL.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Countly-PL'
3-
s.version = '22.09.0'
3+
s.version = '23.02.0'
44
s.license = { :type => 'MIT', :file => 'LICENSE.md' }
55
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
66
s.homepage = 'https://github.com/Countly/countly-sdk-ios'

Countly.m

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,30 +633,50 @@ - (void)recordEvent:(NSString *)key segmentation:(NSDictionary *)segmentation co
633633
return;
634634
}
635635

636-
[self recordEvent:key segmentation:segmentation count:count sum:sum duration:duration timestamp:CountlyCommon.sharedInstance.uniqueTimestamp];
636+
[self recordEvent:key segmentation:segmentation count:count sum:sum duration:duration ID:nil timestamp:CountlyCommon.sharedInstance.uniqueTimestamp];
637637
}
638638

639639
#pragma mark -
640640

641641
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation
642642
{
643-
[self recordEvent:key segmentation:segmentation count:1 sum:0 duration:0 timestamp:CountlyCommon.sharedInstance.uniqueTimestamp];
643+
[self recordEvent:key segmentation:segmentation count:1 sum:0 duration:0 ID:nil timestamp:CountlyCommon.sharedInstance.uniqueTimestamp];
644644
}
645645

646-
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation count:(NSUInteger)count sum:(double)sum duration:(NSTimeInterval)duration timestamp:(NSTimeInterval)timestamp
646+
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation ID:(NSString *)ID
647647
{
648-
[self recordEvent:key segmentation:segmentation count:count sum:sum duration:duration timestamp:timestamp];
648+
[self recordEvent:key segmentation:segmentation count:1 sum:0 duration:0 ID:ID timestamp:CountlyCommon.sharedInstance.uniqueTimestamp];
649+
}
650+
651+
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation count:(NSUInteger)count sum:(double)sum duration:(NSTimeInterval)duration ID:(NSString *)ID timestamp:(NSTimeInterval)timestamp
652+
{
653+
[self recordEvent:key segmentation:segmentation count:count sum:sum duration:duration ID:ID timestamp:timestamp];
649654
}
650655

651656
#pragma mark -
652657

653-
- (void)recordEvent:(NSString *)key segmentation:(NSDictionary *)segmentation count:(NSUInteger)count sum:(double)sum duration:(NSTimeInterval)duration timestamp:(NSTimeInterval)timestamp
658+
- (void)recordEvent:(NSString *)key segmentation:(NSDictionary *)segmentation count:(NSUInteger)count sum:(double)sum duration:(NSTimeInterval)duration ID:(NSString *)ID timestamp:(NSTimeInterval)timestamp
654659
{
655660
if (key.length == 0)
656661
return;
657662

658663
CountlyEvent *event = CountlyEvent.new;
659664
event.key = key;
665+
event.ID = ID;
666+
if (!event.ID.length)
667+
{
668+
event.ID = CountlyCommon.sharedInstance.randomEventID;
669+
}
670+
671+
if ([key isEqualToString:kCountlyReservedEventView])
672+
{
673+
event.PVID = CountlyViewTracking.sharedInstance.previousViewID ?: @"";
674+
}
675+
else
676+
{
677+
event.CVID = CountlyViewTracking.sharedInstance.currentViewID ?: @"";
678+
}
679+
660680
event.segmentation = segmentation;
661681
event.count = MAX(count, 1);
662682
event.sum = sum;

Countly.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Countly'
3-
s.version = '22.09.0'
3+
s.version = '23.02.0'
44
s.license = { :type => 'MIT', :file => 'LICENSE.md' }
55
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
66
s.homepage = 'https://github.com/Countly/countly-sdk-ios'

Countly.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@
410410
"@loader_path/Frameworks",
411411
);
412412
MACOSX_DEPLOYMENT_TARGET = 10.14;
413-
MARKETING_VERSION = 22.09.0;
413+
MARKETING_VERSION = 23.02.0;
414414
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
415415
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
416416
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -439,7 +439,7 @@
439439
"@loader_path/Frameworks",
440440
);
441441
MACOSX_DEPLOYMENT_TARGET = 10.14;
442-
MARKETING_VERSION = 22.06.3;
442+
MARKETING_VERSION = 23.02.0;
443443
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
444444
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
445445
PROVISIONING_PROFILE_SPECIFIER = "";

CountlyCommon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void CountlyPrint(NSString *stringToPrint);
8787
- (NSInteger)timeZone;
8888
- (NSInteger)timeSinceLaunch;
8989
- (NSTimeInterval)uniqueTimestamp;
90+
- (NSString *)randomEventID;
9091

9192
- (void)startBackgroundTask;
9293
- (void)finishBackgroundTask;
@@ -145,7 +146,8 @@ void CountlyPrint(NSString *stringToPrint);
145146

146147
@interface Countly (RecordReservedEvent)
147148
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation;
148-
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation count:(NSUInteger)count sum:(double)sum duration:(NSTimeInterval)duration timestamp:(NSTimeInterval)timestamp;
149+
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation ID:(NSString *)ID;
150+
- (void)recordReservedEvent:(NSString *)key segmentation:(NSDictionary *)segmentation count:(NSUInteger)count sum:(double)sum duration:(NSTimeInterval)duration ID:(NSString *)ID timestamp:(NSTimeInterval)timestamp;
149151
@end
150152

151153
@interface CountlyUserDetails (ClearUserDetails)

CountlyCommon.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ @interface CountlyCommon ()
2626
#endif
2727
@end
2828

29-
NSString* const kCountlySDKVersion = @"22.09.0";
29+
NSString* const kCountlySDKVersion = @"23.02.0";
3030
NSString* const kCountlySDKName = @"objc-native-ios";
3131

3232
NSString* const kCountlyErrorDomain = @"ly.count.ErrorDomain";
@@ -152,6 +152,17 @@ - (NSTimeInterval)uniqueTimestamp
152152
return (NSTimeInterval)(self.lastTimestamp / 1000.0);
153153
}
154154

155+
- (NSString *)randomEventID
156+
{
157+
const int size = 6;
158+
void *randomBuffer = malloc(size);
159+
arc4random_buf(randomBuffer, size);
160+
NSData* randomData = [NSData dataWithBytesNoCopy:randomBuffer length:size freeWhenDone:YES];
161+
NSString* randomBase64 = [randomData base64EncodedStringWithOptions:0];
162+
NSTimeInterval timestamp = self.uniqueTimestamp;
163+
NSString* randomEventID = [NSString stringWithFormat:@"%@%lld", randomBase64, (long long)(timestamp * 1000)];
164+
return randomEventID;
165+
}
155166

156167
#pragma mark - Orientation
157168

CountlyEvent.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
@interface CountlyEvent : NSObject <NSCoding>
1010

1111
@property (nonatomic, copy) NSString* key;
12+
@property (nonatomic, copy) NSString* ID;
13+
@property (nonatomic, copy) NSString* CVID;
14+
@property (nonatomic, copy) NSString* PVID;
1215
@property (nonatomic, copy) NSDictionary* segmentation;
1316
@property (nonatomic) NSUInteger count;
1417
@property (nonatomic) double sum;

CountlyEvent.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
@implementation CountlyEvent
1010

1111
NSString* const kCountlyEventKeyKey = @"key";
12+
NSString* const kCountlyEventKeyID = @"id";
13+
NSString* const kCountlyEventKeyCVID = @"cvid";
14+
NSString* const kCountlyEventKeyPVID = @"pvid";
1215
NSString* const kCountlyEventKeySegmentation = @"segmentation";
1316
NSString* const kCountlyEventKeyCount = @"count";
1417
NSString* const kCountlyEventKeySum = @"sum";
@@ -25,6 +28,9 @@ - (NSDictionary *)dictionaryRepresentation
2528
{
2629
eventData[kCountlyEventKeySegmentation] = self.segmentation;
2730
}
31+
eventData[kCountlyEventKeyID] = self.ID;
32+
eventData[kCountlyEventKeyCVID] = self.CVID;
33+
eventData[kCountlyEventKeyPVID] = self.PVID;
2834
eventData[kCountlyEventKeyCount] = @(self.count);
2935
eventData[kCountlyEventKeySum] = @(self.sum);
3036
eventData[kCountlyEventKeyTimestamp] = @((long long)(self.timestamp * 1000));
@@ -39,6 +45,9 @@ - (instancetype)initWithCoder:(NSCoder *)decoder
3945
if (self = [super init])
4046
{
4147
self.key = [decoder decodeObjectForKey:NSStringFromSelector(@selector(key))];
48+
self.ID = [decoder decodeObjectForKey:NSStringFromSelector(@selector(ID))];
49+
self.CVID = [decoder decodeObjectForKey:NSStringFromSelector(@selector(CVID))];
50+
self.PVID = [decoder decodeObjectForKey:NSStringFromSelector(@selector(PVID))];
4251
self.segmentation = [decoder decodeObjectForKey:NSStringFromSelector(@selector(segmentation))];
4352
self.count = [decoder decodeIntegerForKey:NSStringFromSelector(@selector(count))];
4453
self.sum = [decoder decodeDoubleForKey:NSStringFromSelector(@selector(sum))];
@@ -54,6 +63,9 @@ - (instancetype)initWithCoder:(NSCoder *)decoder
5463
- (void)encodeWithCoder:(NSCoder *)encoder
5564
{
5665
[encoder encodeObject:self.key forKey:NSStringFromSelector(@selector(key))];
66+
[encoder encodeObject:self.ID forKey:NSStringFromSelector(@selector(ID))];
67+
[encoder encodeObject:self.CVID forKey:NSStringFromSelector(@selector(CVID))];
68+
[encoder encodeObject:self.PVID forKey:NSStringFromSelector(@selector(PVID))];
5769
[encoder encodeObject:self.segmentation forKey:NSStringFromSelector(@selector(segmentation))];
5870
[encoder encodeInteger:self.count forKey:NSStringFromSelector(@selector(count))];
5971
[encoder encodeDouble:self.sum forKey:NSStringFromSelector(@selector(sum))];

CountlyUserDetails.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ - (void)save
386386
if (!CountlyConsentManager.sharedInstance.consentForUserDetails)
387387
return;
388388

389+
[CountlyConnectionManager.sharedInstance sendEvents];
390+
389391
NSString* userDetails = [self serializedUserDetails];
390392
if (userDetails)
391393
[CountlyConnectionManager.sharedInstance sendUserDetails:userDetails];

CountlyViewTracking.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ extern NSString* const kCountlyReservedEventView;
1010

1111
@interface CountlyViewTracking : NSObject
1212
@property (nonatomic) BOOL isEnabledOnInitialConfig;
13+
@property (nonatomic) NSString* currentViewID;
14+
@property (nonatomic) NSString* previousViewID;
1315

1416
+ (instancetype)sharedInstance;
1517

CountlyViewTracking.m

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#import "CountlyCommon.h"
88

99
@interface CountlyViewTracking ()
10-
@property (nonatomic) NSString* lastView;
11-
@property (nonatomic) NSTimeInterval lastViewStartTime;
10+
@property (nonatomic) NSString* currentView;
11+
@property (nonatomic) NSTimeInterval currentViewStartTime;
1212
@property (nonatomic) NSTimeInterval accumulatedTime;
1313
@property (nonatomic) NSMutableArray* exceptionViewControllers;
1414
@end
@@ -124,7 +124,7 @@ - (void)startView:(NSString *)viewName customSegmentation:(NSDictionary *)custom
124124
segmentation[kCountlyVTKeySegment] = CountlyDeviceInfo.osName;
125125
segmentation[kCountlyVTKeyVisit] = @1;
126126

127-
if (!self.lastView)
127+
if (!self.currentView)
128128
segmentation[kCountlyVTKeyStart] = @1;
129129

130130
if (customSegmentation)
@@ -134,40 +134,42 @@ - (void)startView:(NSString *)viewName customSegmentation:(NSDictionary *)custom
134134
[segmentation addEntriesFromDictionary:mutableCustomSegmentation];
135135
}
136136

137-
[Countly.sharedInstance recordReservedEvent:kCountlyReservedEventView segmentation:segmentation];
137+
self.currentView = viewName;
138+
self.previousViewID = self.currentViewID;
139+
self.currentViewID = CountlyCommon.sharedInstance.randomEventID;
140+
self.currentViewStartTime = CountlyCommon.sharedInstance.uniqueTimestamp;
138141

139-
self.lastView = viewName;
140-
self.lastViewStartTime = CountlyCommon.sharedInstance.uniqueTimestamp;
142+
[Countly.sharedInstance recordReservedEvent:kCountlyReservedEventView segmentation:segmentation ID:self.currentViewID];
141143
}
142144

143145
- (void)endView
144146
{
145147
if (!CountlyConsentManager.sharedInstance.consentForViewTracking)
146148
return;
147149

148-
if (self.lastView)
150+
if (self.currentView)
149151
{
150152
NSMutableDictionary* segmentation = NSMutableDictionary.new;
151-
segmentation[kCountlyVTKeyName] = self.lastView;
153+
segmentation[kCountlyVTKeyName] = self.currentView;
152154
segmentation[kCountlyVTKeySegment] = CountlyDeviceInfo.osName;
153155

154-
NSTimeInterval duration = NSDate.date.timeIntervalSince1970 - self.lastViewStartTime + self.accumulatedTime;
156+
NSTimeInterval duration = NSDate.date.timeIntervalSince1970 - self.currentViewStartTime + self.accumulatedTime;
155157
self.accumulatedTime = 0;
156-
[Countly.sharedInstance recordReservedEvent:kCountlyReservedEventView segmentation:segmentation count:1 sum:0 duration:duration timestamp:self.lastViewStartTime];
158+
[Countly.sharedInstance recordReservedEvent:kCountlyReservedEventView segmentation:segmentation count:1 sum:0 duration:duration ID:self.currentViewID timestamp:self.currentViewStartTime];
157159

158-
CLY_LOG_D(@"View tracking ended: %@ duration: %.17g", self.lastView, duration);
160+
CLY_LOG_D(@"View tracking ended: %@ duration: %.17g", self.currentView, duration);
159161
}
160162
}
161163

162164
- (void)pauseView
163165
{
164-
if (self.lastViewStartTime)
165-
self.accumulatedTime = NSDate.date.timeIntervalSince1970 - self.lastViewStartTime;
166+
if (self.currentViewStartTime)
167+
self.accumulatedTime = NSDate.date.timeIntervalSince1970 - self.currentViewStartTime;
166168
}
167169

168170
- (void)resumeView
169171
{
170-
self.lastViewStartTime = CountlyCommon.sharedInstance.uniqueTimestamp;
172+
self.currentViewStartTime = CountlyCommon.sharedInstance.uniqueTimestamp;
171173
}
172174

173175
#pragma mark -
@@ -210,8 +212,9 @@ - (void)stopAutoViewTracking
210212
{
211213
self.isAutoViewTrackingActive = NO;
212214

213-
self.lastView = nil;
214-
self.lastViewStartTime = 0;
215+
self.currentView = nil;
216+
self.currentViewID = nil;
217+
self.currentViewStartTime = 0;
215218
self.accumulatedTime = 0;
216219
}
217220

@@ -225,7 +228,7 @@ - (void)performAutoViewTrackingForViewController:(UIViewController *)viewControl
225228

226229
NSString* viewTitle = [self titleForViewController:viewController];
227230

228-
if ([self.lastView isEqualToString:viewTitle])
231+
if ([self.currentView isEqualToString:viewTitle])
229232
return;
230233

231234
BOOL isException = NO;

0 commit comments

Comments
 (0)