Skip to content

Commit b3bdfb5

Browse files
authored
feat: Map product position to Firebase item index (#33)
1 parent fe3014d commit b3bdfb5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mParticle-Google-Analytics-Firebase-GA4/MPKitFirebaseGA4Analytics.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ - (NSMutableArray *)getParametersForProducts:(id)products {
536536
if (product.price) {
537537
[productParameters setObject:product.price forKey:kFIRParameterPrice];
538538
}
539+
if (product.position) {
540+
id indexParameter = @(product.position);
541+
[productParameters setObject:indexParameter forKey:kFIRParameterIndex];
542+
}
539543
if (product.userDefinedAttributes) {
540544
for (NSString *productCustomAttribute in product.userDefinedAttributes) {
541545
[productParameters setObject:product.userDefinedAttributes[productCustomAttribute] forKey:productCustomAttribute];

mParticle-Google-Analytics-Firebase-GA4Tests/MPKitFirebaseGA4AnalyticsTests.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ - (NSString *)standardizeValue:(id)value forEvent:(BOOL)forEvent;
1313
- (NSString *)getEventNameForCommerceEvent:(MPCommerceEvent *)commerceEvent parameters:(NSDictionary<NSString *, id> *)parameters;
1414
- (NSDictionary<NSString *, id> *)getParameterForCommerceEvent:(MPCommerceEvent *)commerceEvent;
1515
- (NSMutableDictionary<NSString *, id> *)getParametersForScreen:(MPEvent *)screenEvent;
16+
- (NSMutableArray *)getParametersForProducts:(id)products;
1617
@end
1718

1819
@interface mParticle_Firebase_AnalyticsTests : XCTestCase
@@ -298,6 +299,7 @@ - (void)testProductParameters {
298299
NSMutableDictionary<NSString *, id> *testProductCustomAttributes = [[@{@"productCustomAttribute": @"potato", @"store": @"Target"} mutableCopy] mutableCopy];
299300
product.brand = @"LV";
300301
product.category = @"vegetable";
302+
product.position = 4;
301303
product.userDefinedAttributes = testProductCustomAttributes;
302304

303305
MPCommerceEvent *event = [[MPCommerceEvent alloc] initWithImpressionName:@"suggested products list" product:product];
@@ -306,8 +308,8 @@ - (void)testProductParameters {
306308
NSArray *itemsArray = [exampleKit getParametersForProducts:impressionProducts];
307309
id item = itemsArray[0];
308310

309-
// The item inside itemsArray should include 8 parameters in total including the 2 product custom attributes
310-
XCTAssertEqual([item count], 8);
311+
// The item inside itemsArray should include 9 parameters in total including the 2 product custom attributes
312+
XCTAssertEqual([item count], 9);
311313
}
312314

313315
- (void)testCommerceEventCheckoutOptions {

0 commit comments

Comments
 (0)