Skip to content

Commit

Permalink
Merge pull request #263 from Automattic/issue/262-fix-TracksLogging
Browse files Browse the repository at this point in the history
Fix `TracksLogWarn` messages aren't logged with Cocoapods integration
  • Loading branch information
jaclync authored Sep 1, 2023
2 parents aad902b + 5a1d29d commit 6ff2e44
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Automattic-Tracks-iOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Pod::Spec.new do |s|
s.name = 'Automattic-Tracks-iOS'
s.version = '2.3.0'
s.version = '2.4.0'

s.summary = 'Simple way to track events in an iOS app with Automattic Tracks internal service'
s.description = <<-DESC
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ _None._
-->

## 2.4.0

### Breaking Changes

_None._

### New Features

- `TracksService.trackEventName:withCustomProperties:` now returns a boolean that indicates whether the event creation is successful.

### Bug Fixes

- `TracksLogging` now works when the library is integrated with Cocoapods for internal Tracks error/warning messages.

### Internal Changes

- `TracksService.trackEventName:withCustomProperties:` now logs the event name when there is a validation error from creating a Tracks event.

_None._

## 2.3.0

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion Sources/Event Logging/TracksEventService.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (TracksEvent *)createTracksEventWithName:(NSString *)name
NSError *error;
BOOL isValid = [tracksEvent validateObject:&error];
if (!isValid) {
TracksLogWarn(@"Error when validating TracksEvent: %@", error);
TracksLogWarn(@"Error when validating TracksEvent %@: %@", name, error);
return nil;
}

Expand Down
7 changes: 6 additions & 1 deletion Sources/Event Logging/TracksService.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ extern NSString *const TrackServiceDidSendQueuedEventsNotification;
- (void)switchToAnonymousUserWithAnonymousID:(NSString *)anonymousID;

- (void)trackEventName:(NSString *)eventName;
- (void)trackEventName:(NSString *)eventName withCustomProperties:(NSDictionary *)customProperties;

/// Tracks an event with custom properties and returns a boolean that indicates whether the creation is successful.
/// - Parameters:
/// - eventName: Name of the event.
/// - customProperties: Custom event properties whose property name should only have alpha characters and underscores.
- (BOOL)trackEventName:(NSString *)eventName withCustomProperties:(NSDictionary *)customProperties;

- (void)sendQueuedEvents;
- (void)clearQueuedEvents;
Expand Down
21 changes: 11 additions & 10 deletions Sources/Event Logging/TracksService.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,20 @@ - (void)trackEventName:(NSString *)eventName
}


- (void)trackEventName:(NSString *)eventName withCustomProperties:(NSDictionary *)customProperties
- (BOOL)trackEventName:(NSString *)eventName withCustomProperties:(NSDictionary *)customProperties
{
eventName = [NSString stringWithFormat:@"%@_%@", self.eventNamePrefix, eventName];

[self.tracksEventService createTracksEventWithName:eventName
username:self.username
userID:self.userID
userAgent:self.userAgent
userType:self.isAnonymous ? TracksEventUserTypeAnonymous : TracksEventUserTypeAuthenticated
eventDate:[NSDate date]
customProperties:customProperties
deviceProperties:[self mutableDeviceProperties]
userProperties:self.userProperties];
TracksEvent * _Nullable event = [self.tracksEventService createTracksEventWithName:eventName
username:self.username
userID:self.userID
userAgent:self.userAgent
userType:self.isAnonymous ? TracksEventUserTypeAnonymous : TracksEventUserTypeAuthenticated
eventDate:[NSDate date]
customProperties:customProperties
deviceProperties:[self mutableDeviceProperties]
userProperties:self.userProperties];
return event != nil;
}

- (NSUInteger)queuedEventCount
Expand Down
2 changes: 1 addition & 1 deletion Sources/Model/ObjC/Common/TracksLogging.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#if SWIFT_PACKAGE
Class loggingClass = NSClassFromString(@"AutomatticTracksModel.TracksLogging");
#else
Class loggingClass = NSClassFromString(@"TracksLogging");
Class loggingClass = NSClassFromString(@"AutomatticTracks.TracksLogging");
#endif
if ([loggingClass conformsToProtocol: @protocol(TracksLoggingConfiguration)]) {
result = loggingClass;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Model/ObjC/Constants/TracksConstants.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "TracksConstants.h"

NSString *const TracksErrorDomain = @"TracksErrorDomain";
NSString *const TracksLibraryVersion = @"2.3.0";
NSString *const TracksLibraryVersion = @"2.4.0";

0 comments on commit 6ff2e44

Please sign in to comment.