Skip to content

Commit

Permalink
feat: event add timezoneOffset property
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Aug 23, 2023
1 parent b3c3329 commit 1b4ceba
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ + (NSArray *)context {
@"platform", @"platformVersion", @"deviceId", @"sessionId", @"eventType",
@"timestamp", @"domain", @"urlScheme", @"appState", @"eventSequenceId",
@"networkState", @"screenHeight", @"screenWidth", @"deviceBrand", @"deviceModel",
@"deviceType", @"appVersion", @"appName", @"language", @"sdkVersion"
@"deviceType", @"appVersion", @"appName", @"language", @"sdkVersion",
@"timezoneOffset"
];
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ - (void)testDatabaseEventIO {
.setSdkVersion(@"3.3.3")
.setUserKey(@"iPhone")
.setDataSourceId(@"1234567890")
.setTimezoneOffset(-480)
.build);
NSString *uuid = [NSUUID UUID].UUIDString;
GrowingEventProtobufPersistence *persistenceIn = [GrowingEventProtobufPersistence persistenceEventWithEvent:event
Expand Down Expand Up @@ -203,6 +204,8 @@ - (void)testDatabaseEventIO {
XCTAssertEqual(GrowingPBEventType_Custom, protobuf.eventType);
XCTAssertEqualObjects(event.eventName ?: @"", protobuf.eventName);
XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes);
// 4.0.0
XCTAssertEqual(event.timezoneOffset, protobuf.timezoneOffset);
}

- (GrowingEventProtobufPersistence *)customEventPersistence {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ - (void)contrastOfDefaultParamter:(GrowingBaseEvent *)event protobuf:(GrowingPBE
XCTAssertEqualObjects(event.sdkVersion ?: @"", protobuf.sdkVersion);
// 3.3.0
XCTAssertEqualObjects(event.userKey ?: @"", protobuf.userKey);
// 4.0.0
XCTAssertEqual(event.timezoneOffset, protobuf.timezoneOffset);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ - (void)setUp {
.setUserId(@"zhangsan")
.setUserKey(@"phone")
.setDeviceId(@"testdeviceID")
.setTimezoneOffset(-480)
.build.toDictionary;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ - (void)testDatabaseEventIO {
.setSdkVersion(@"3.3.3")
.setUserKey(@"iPhone")
.setDataSourceId(@"1234567890")
.setTimezoneOffset(-480)
.build);
NSString *uuid = [NSUUID UUID].UUIDString;
GrowingEventJSONPersistence *persistenceIn = [GrowingEventJSONPersistence persistenceEventWithEvent:event
Expand Down Expand Up @@ -196,6 +197,8 @@ - (void)testDatabaseEventIO {
// CUSTOM
XCTAssertEqualObjects(event.eventName ?: @"", jsonObject[@"eventName"]);
XCTAssertEqualObjects(event.attributes ?: @{}, jsonObject[@"attributes"]);
// 4.0.0
XCTAssertEqual(event.timezoneOffset, ((NSNumber *)(jsonObject[@"timezoneOffset"])).intValue);
}

- (GrowingEventJSONPersistence *)customEventPersistence {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ - (void)setUp {
.setUserId(@"zhangsan")
.setUserKey(@"phone")
.setDeviceId(@"testdeviceID")
.setTimezoneOffset(-480)
.build.toDictionary;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ - (void)setUp {
.setUserId(@"zhangsan")
.setUserKey(@"phone")
.setDeviceId(@"testdeviceID")
.setTimezoneOffset(-480)
.build;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ - (void)testGrowingVisitEvent {
.setTimestamp(12345678)
.setUserId(@"zhangsan")
.setUserKey(@"phone")
.setDeviceId(@"testdeviceID");
.setDeviceId(@"testdeviceID")
.setTimezoneOffset(-480);

GrowingBaseBuilder *builder = GrowingVisitEvent.builder;
[GrowingEventManager.sharedInstance postEventBuilder:builder];
Expand Down
10 changes: 10 additions & 0 deletions GrowingTrackerCore/Event/Base/GrowingBaseEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder {
_longitude = builder.longitude;
_sdkVersion = builder.sdkVersion;
_userKey = builder.userKey;
_timezoneOffset = builder.timezoneOffset;
}
return self;
}
Expand Down Expand Up @@ -100,6 +101,7 @@ - (NSDictionary *)toDictionary {
dataDict[@"longitude"] = ABS(self.longitude) > 0 ? @(self.longitude) : nil;
dataDict[@"sdkVersion"] = self.sdkVersion;
dataDict[@"userKey"] = self.userKey.length > 0 ? self.userKey : nil;
dataDict[@"timezoneOffset"] = @(self.timezoneOffset);
return [dataDict copy];
}

Expand Down Expand Up @@ -148,6 +150,7 @@ - (void)readPropertyInTrackThread {
_appName = deviceInfo.displayName;
_appVersion = deviceInfo.appVersion;
_language = deviceInfo.language;
_timezoneOffset = -([[NSTimeZone defaultTimeZone] secondsFromGMT] / 60);
}

- (GrowingBaseBuilder * (^)(NSString *value))setDataSourceId {
Expand Down Expand Up @@ -332,6 +335,13 @@ - (void)readPropertyInTrackThread {
};
}

- (GrowingBaseBuilder * (^)(NSInteger value))setTimezoneOffset {
return ^(NSInteger value) {
self->_timezoneOffset = value;
return self;
};
}

- (GrowingBaseEvent *)build {
@throw [NSException
exceptionWithName:NSInternalInconsistencyException
Expand Down
3 changes: 3 additions & 0 deletions GrowingTrackerCore/Public/GrowingBaseEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) {
@property (nonatomic, assign, readonly) double longitude;
@property (nonatomic, copy, readonly) NSString *sdkVersion;
@property (nonatomic, copy, readonly, nullable) NSString *userKey;
@property (nonatomic, assign, readonly) NSInteger timezoneOffset;
@property (nonatomic, assign) GrowingEventSendPolicy sendPolicy;

- (NSDictionary *_Nonnull)toDictionary;
Expand Down Expand Up @@ -102,6 +103,7 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) {
@property (nonatomic, assign, readonly) double longitude;
@property (nonatomic, copy, readonly) NSString *sdkVersion;
@property (nonatomic, copy, readonly, nullable) NSString *userKey;
@property (nonatomic, assign, readonly) NSInteger timezoneOffset;

// 赋值属性,eg:deviceId,userId,sessionId,eventSequenceId
- (void)readPropertyInTrackThread;
Expand Down Expand Up @@ -132,6 +134,7 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) {
- (GrowingBaseBuilder * (^)(NSString *value))setSdkVersion;
- (GrowingBaseBuilder * (^)(NSString *value))setUserKey;
- (GrowingBaseBuilder * (^)(NSString *value))setEventType;
- (GrowingBaseBuilder * (^)(NSInteger value))setTimezoneOffset;
- (GrowingBaseEvent *)build;

@end
Expand Down
1 change: 1 addition & 0 deletions Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (GrowingPBEventV3Dto *)toProtobuf {
dto.longitude = self.longitude;
dto.sdkVersion = self.sdkVersion;
dto.userKey = self.userKey;
dto.timezoneOffset = (int)self.timezoneOffset;

__weak typeof(self) weakSelf = self;
NSString * (^stringBlock)(NSString *) = ^(NSString *selectorString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ - (id)growingHelper_jsonObject {
if (self.userKey.length > 0) {
[dic setObject:self.userKey forKey:@"userKey"];
}
[dic setObject:@(self.timezoneOffset) forKey:@"timezoneOffset"];

return dic;
}
Expand Down Expand Up @@ -227,7 +228,8 @@ + (nullable instancetype)growingHelper_parseFromJsonObject:(NSDictionary *)jsonO
dto.referralPage = jsonObject[@"referralPage"];
dto.protocolType = jsonObject[@"protocolType"];
dto.eventName = jsonObject[@"eventName"];

dto.timezoneOffset = ((NSNumber *)jsonObject[@"timezoneOffset"]).intValue;

return dto;
}

Expand Down
3 changes: 3 additions & 0 deletions Services/Protobuf/Proto/GrowingEvent.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Services/Protobuf/Proto/GrowingEvent.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Services/Protobuf/Proto/event_v3.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ message EventV3Dto {
int64 send_time = 54;
string user_key = 55;
string xcontent = 56;
int32 timezone_offset = 57;
}

message ResourceItem {
Expand Down
2 changes: 2 additions & 0 deletions Services/SwiftProtobuf/SwiftProtobuf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class SwiftProtobufWrapper: NSObject {
dto.referralPage = jsonObject["referralPage"] as? String ?? ""
dto.protocolType = jsonObject["protocolType"] as? String ?? ""
dto.eventName = jsonObject["eventName"] as? String ?? ""
dto.timezoneOffset = (jsonObject["timezoneOffset"] as? NSNumber)?.int32Value ?? 0

return SwiftProtobufWrapper(dto)
}
Expand Down Expand Up @@ -200,6 +201,7 @@ extension GrowingBaseEvent {
dto.longitude = self.longitude
dto.sdkVersion = self.sdkVersion
dto.userKey = self.userKey ?? ""
dto.timezoneOffset = Int32(self.timezoneOffset)

dto.eventType = SwiftProtobufWrapper.eventType(self.eventType)
dto.idfa = idfa()
Expand Down
13 changes: 13 additions & 0 deletions Services/SwiftProtobuf/event_v3.pb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ struct Io_Growing_Tunnel_Protocol_EventV3Dto {
set {_uniqueStorage()._xcontent = newValue}
}

var timezoneOffset: Int32 {
get {return _storage._timezoneOffset}
set {_uniqueStorage()._timezoneOffset = newValue}
}

var unknownFields = SwiftProtobuf.UnknownStorage()

init() {}
Expand Down Expand Up @@ -482,6 +487,7 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro
54: .standard(proto: "send_time"),
55: .standard(proto: "user_key"),
56: .same(proto: "xcontent"),
57: .standard(proto: "timezone_offset"),
]

fileprivate class _StorageClass {
Expand Down Expand Up @@ -536,6 +542,7 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro
var _sendTime: Int64 = 0
var _userKey: String = String()
var _xcontent: String = String()
var _timezoneOffset: Int32 = 0

static let defaultInstance = _StorageClass()

Expand Down Expand Up @@ -593,6 +600,7 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro
_sendTime = source._sendTime
_userKey = source._userKey
_xcontent = source._xcontent
_timezoneOffset = source._timezoneOffset
}
}

Expand Down Expand Up @@ -662,6 +670,7 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro
case 54: try { try decoder.decodeSingularInt64Field(value: &_storage._sendTime) }()
case 55: try { try decoder.decodeSingularStringField(value: &_storage._userKey) }()
case 56: try { try decoder.decodeSingularStringField(value: &_storage._xcontent) }()
case 57: try { try decoder.decodeSingularInt32Field(value: &_storage._timezoneOffset) }()
default: break
}
}
Expand Down Expand Up @@ -827,6 +836,9 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro
if !_storage._xcontent.isEmpty {
try visitor.visitSingularStringField(value: _storage._xcontent, fieldNumber: 56)
}
if _storage._timezoneOffset != 0 {
try visitor.visitSingularInt32Field(value: _storage._timezoneOffset, fieldNumber: 57)
}
}
try unknownFields.traverse(visitor: &visitor)
}
Expand Down Expand Up @@ -887,6 +899,7 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro
if _storage._sendTime != rhs_storage._sendTime {return false}
if _storage._userKey != rhs_storage._userKey {return false}
if _storage._xcontent != rhs_storage._xcontent {return false}
if _storage._timezoneOffset != rhs_storage._timezoneOffset {return false}
return true
}
if !storagesAreEqual {return false}
Expand Down

0 comments on commit 1b4ceba

Please sign in to comment.