I don’t understand how to log event with array items in parameters.
For example, if I need to log something like EventNamesConstants.Login I can to do
var parameters = new Dictionary<object, object> {
ParameterNamesConstants.Method, "Google" }
};
Analytics.LogEvent(EventNamesConstants.Login, parameters);
But now I need to log EventNamesConstants.ViewItem
And one of parameters is array of items where item has a name.
When I try to do something like that
var items = new[]{
new Dictionary<object, object> {
ParameterNamesConstants.ItemName, title }
}
};
var parameters = new Dictionary<object, object> {
ParameterNamesConstants.Currency, currencyCode },
ParameterNamesConstants.Value, value },
ParameterNamesConstants.Items, items }
};
I got an error.
I tried to find examples, but they didn’t have an array.
I am so sorry.
An error is:
Do not know how to marshal object of type
'System.Collections.Generic.Dictionary`2[System.Object,System.Object][]'
to an NSObject
And func Analytics.LogEvent of Firebase is:
public static void LogEvent (string name, Dictionary<object, object>? parameters)
{
LogEvent (name, (parameters == null) ? null :
((parameters!.Keys.Count == 0) ? new NSDictionary<NSString, NSObject>
() : NSDictionary<NSString, NSObject>.FromObjectsAndKeys
(parameters!.Values.ToArray (), parameters!.Keys.ToArray (),
nint.op_Implicit (parameters!.Keys.Count))));
}
Help me please.
2
Answers
As a workaround, you could try the following way to create your parameters,
I use also Firebase Analytics in my apps.
Here is a suitable extension method on
IDictionary<string, string>
that anyone can use to convert easily C#IDictionary
to iOSNSDictionary
If you need, here is another one on
IDictionary<string, object>
FYI: I use
ArgumentNullException.ThrowIfNull
=> Only available since C#10, use classic way if you are under C#10.