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

feat: forward screen custom attributes #29

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ - (MPKitExecStatus *)logScreen:(MPEvent *)event {
return [self execStatus:MPKitReturnCodeFail];
}

NSString *standardizedFirebaseEventName = [self standardizeNameOrKey:event.name forEvent:YES];
[FIRAnalytics logEventWithName:kFIREventScreenView parameters:@{kFIRParameterScreenName: standardizedFirebaseEventName}];
NSMutableDictionary *screenParameters = [self getParametersForScreen:event];
[FIRAnalytics logEventWithName:kFIREventScreenView parameters:screenParameters];

return [self execStatus:MPKitReturnCodeSuccess];
}
Expand Down Expand Up @@ -260,7 +260,7 @@ - (NSString *)standardizeValue:(id)value forEvent:(BOOL)forEvent {
return finalValue;
}

- (NSDictionary<NSString *, id> *)standardizeValues:(NSDictionary<NSString *, id> *)values forEvent:(BOOL)forEvent {
- (NSMutableDictionary<NSString *, id> *)standardizeValues:(NSDictionary<NSString *, id> *)values forEvent:(BOOL)forEvent {
NSMutableDictionary<NSString *, id> *standardizedValue = [[NSMutableDictionary alloc] init];

for (NSString *key in values.allKeys) {
Expand All @@ -272,6 +272,13 @@ - (NSString *)standardizeValue:(id)value forEvent:(BOOL)forEvent {
return standardizedValue;
}

- (NSMutableDictionary<NSString *, id> *)getParametersForScreen:(MPEvent *)screenEvent {
NSMutableDictionary *standardizedScreenParameters = [self standardizeValues:screenEvent.customAttributes forEvent:YES];
NSString *standardizedFirebaseEventName = [self standardizeNameOrKey:screenEvent.name forEvent:YES];
standardizedScreenParameters[kFIRParameterScreenName] = standardizedFirebaseEventName;
return standardizedScreenParameters;
}

- (MPKitExecStatus *)onLoginComplete:(FilteredMParticleUser *)user request:(FilteredMPIdentityApiRequest *)request {
if (forwardRequestsServerSide) {
return [self execStatus:MPKitReturnCodeUnavailable];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ - (NSString *)standardizeNameOrKey:(NSString *)nameOrKey forEvent:(BOOL)forEvent
- (NSString *)standardizeValue:(id)value forEvent:(BOOL)forEvent;
- (NSString *)getEventNameForCommerceEvent:(MPCommerceEvent *)commerceEvent parameters:(NSDictionary<NSString *, id> *)parameters;
- (NSDictionary<NSString *, id> *)getParameterForCommerceEvent:(MPCommerceEvent *)commerceEvent;
- (NSMutableDictionary<NSString *, id> *)getParametersForScreen:(MPEvent *)screenEvent;
@end

@interface mParticle_Firebase_AnalyticsTests : XCTestCase
Expand Down Expand Up @@ -313,4 +314,28 @@ - (void)testCommerceEventCheckoutOptions {
XCTAssertEqualObjects(kFIREventAddShippingInfo, eventName);
}

- (void)testScreenNameAttributes {
MPKitFirebaseGA4Analytics *exampleKit = [[MPKitFirebaseGA4Analytics alloc] init];
[exampleKit didFinishLaunchingWithConfiguration:@{}];

MPEvent *event = [[MPEvent alloc] initWithName:@"testScreenName" type:MPEventTypeOther];
event.customAttributes = @{@"testScreenAttribute":@"value"};
MPKitExecStatus *execStatus = [exampleKit logScreen:event];

XCTAssertTrue(execStatus.success);

NSMutableDictionary<NSString *, id> *screenParameters = [exampleKit getParametersForScreen:event];

// Even though we only pass one custom attribute, the parameters should include the standardized screen name, so the total expected count is two
XCTAssertEqual(screenParameters.count, 2);

NSString *standardizedScreenName = [exampleKit standardizeNameOrKey:event.name forEvent:YES];
NSString *screenNameParameter = screenParameters[kFIRParameterScreenName];

// Test screen name parameter is not Nil and exists in the screen parameters dictionary
XCTAssertNotNil(screenNameParameter);
// Test screen name parameter value is correct
XCTAssertEqualObjects(screenNameParameter, standardizedScreenName);
}

@end
Loading