xamarin / GoogleApisForiOSComponents

MIT License
225 stars 162 forks source link

Firebase Analytics Measure Ecommerce Items not possible? #500

Closed c-lamont closed 3 years ago

c-lamont commented 3 years ago

I would like to add the ParameterNamesConstants.Items parameter when I log an event.

According to Firebase the documentation this is possible: https://firebase.google.com/docs/analytics/measure-ecommerce#objective-c

My current solution says that the Items parameter is too long.

My Items parameter is Key: NSString "Items" Value: NSArray

{
    coupon = "";
    currency = EUR;
    items =     (
                {
            currency = EUR;
            discount = 0;
            "item_category" = "";
            "item_id" = premium;
            "item_name" = "Premium Kenteken Check";
            price = "3.99";
        }
    );
    value = "3.99";
}

Adding Items works well for Android, but I have tried a lot of things to make this work with iOS and I can not get it to work. Is it possible to do this on iOS? What type does the Items value need to be?

c-lamont commented 3 years ago

Found the solution.

For other people, here is the value for the items parameter. If there is a better solution then please let me know.

        private static NSArray GetProductItemsArray (IEnumerable<ProductItemEventDto> productItemEvents)
        {
            var mutableArray = new NSMutableArray();
            foreach (var productItemEvent in productItemEvents)
            {
                var keys = new []
                {
                    new NSString(ParameterNamesConstants.ItemId),
                    new NSString(ParameterNamesConstants.ItemName),
                    new NSString(ParameterNamesConstants.ItemCategory),
                    new NSString(ParameterNamesConstants.Price),
                    new NSString(ParameterNamesConstants.Currency),
                    new NSString(ParameterNamesConstants.Discount)
                };

                var values = new NSObject[]
                {
                    new NSString(productItemEvent.ProductCode),
                    new NSString(productItemEvent.ProductName),
                    new NSString(string.Empty),
                    new NSDecimalNumber(productItemEvent.Price),
                    new NSString(productItemEvent.Currency),
                    new NSDecimalNumber(productItemEvent.Discount)
                };

                var dict =  new NSDictionary<NSString, NSObject>(keys, values);
                mutableArray.Add(dict);
            }

            return mutableArray;
        }
c-lamont commented 1 year ago

@bhuwancb99 I'm not sure what you are asking for.