Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TracksLogWarn messages aren't logged with Cocoapods integration #263

Merged
merged 7 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";