Van_Van
(Van Van)
1
I have a sample code from Firebase. But there is no way to convert this to MOE(kotlin).
// Define product with relevant parameters.
NSDictionary *product1 = @{
kFIRParameterItemID : @“sku1234”, // ITEM_ID or ITEM_NAME is required.
kFIRParameterItemName : @“Android Jogger Sweatpants”,
kFIRParameterItemCategory : @“Apparel/Men/Pants”,
kFIRParameterItemVariant : @“Blue”,
kFIRParameterItemBrand : @“Google”,
kFIRParameterPrice : @39.99,
kFIRParameterCurrency : @“USD”, // Item-level currency unused today.
kFIRParameterIndex : @1 // Position of the item in the list.
};
NSDictionary *product2 = @{
kFIRParameterItemID : @“sku5678”, // ITEM_ID or ITEM_NAME is required.
kFIRParameterItemName : @“Android Capri”,
kFIRParameterItemCategory : @“Apparel/Women/Pants”,
kFIRParameterItemVariant : @“Black”,
kFIRParameterItemBrand : @“Google”,
kFIRParameterPrice : @35.99,
kFIRParameterCurrency : @“USD”, // Item-level currency unused today.
kFIRParameterIndex : @2 // Position of the item in the list.
};
// Prepare ecommerce dictionary.
NSArray *items = @[product1, product2];
NSDictionary *ecommerce = @{
@“items” : items,
kFIRParameterItemList : @“Search Results” // List name.
};
// Log select_content event with ecommerce dictionary.
[FIRAnalytics logEventWithName:kFIREventViewSearchResults
parameters:ecommerce];
I did try a lot but, it doesn’t work.
Has anybody could help me on this stuff?
Thank you so much!
ekuleshov
(Eugene)
2
(NSDictionary<String, ?>) NSDictionary.dictionaryWithObjectsForKeys( //
NSArray.arrayWithObjects(“value1”, “value2”, null), // values
NSArray.arrayWithObjects(“ke1”, “ke2”, null))); // keys
Or use a mutable implementation of NSDictionary to add key/values one by one
Hoang_Nh_t
(Hoàng Nhật)
4
Hi @ekuleshov
Can you help me try this codes?
val data: NSDictionary<String, NSDictionary<String, String>> = NSDictionary.alloc().init()
val value: NSDictionary<String, String> = NSDictionary.alloc().init()
value[“kFIRParameterItemID”] = “sku5678”
value[“kFIRParameterItemName”] = “Android Capri”
value[“kFIRParameterItemCategory”] = “Apparel/Women/Pants”
value[“kFIRParameterItemVariant”] = “Black”
value[“kFIRParameterItemBrand”] = “Google”
value[“kFIRParameterPrice”] = “35.99”
value[“kFIRParameterCurrency”] = “USD”
value[“kFIRParameterIndex”] = “2”
data[“items”] = value
FIRAnalytics.logEventWithNameParameters(“report_item”, data)
I cannot use NSDictionary.alloc().init() to init a NSDictionary<String, NSDictionary<String, String>>
ekuleshov
(Eugene)
5
I don’t want to write all your code. Read my example again. The kFIRParameterItemID is a key, sku5678 is value for that key and so on.
AdamN
(Adam Nicholas)
6
Were you able to figure this out? I am having issues with this in Kotlin as well.
Any help would be greatly appreciated!