Analytics.trackEvent should allow boolean | number | undefined in event property value
Hi,
This is Analytics.trackEvent type
export function trackEvent(
eventName: string,
properties?: {[p: string]: string} | undefined): Promise<void>
Internally Azure allows numbers, booleans and undefined values to be there and I have to work around this typing with extra code on my side.
They are converted to string, so why not allow them? :)
function sanitizeProperties(props = null) {
// Only string:string mappings are supported currently.
const result = {};
if (props === null) {
return result;
}
Object.keys(props).filter((key) => props[key] !== null).forEach((key) => {
switch (typeof props[key]) {
case 'string':
case 'number':
case 'boolean':
result[key] = `${props[key]}`;
break;
case 'undefined':
break;
default:
throw new Error('Properties cannot be serialized. Object must only contain strings');
}
});
return result;
}
Details
- Which version of the App Center SDK are you using? 3.0.3
Hi, @xchmelmilos! Thanks for getting in touch with us.
For now portal supports only string values properties. So the lines you quote, are here because JS is not strongly typed language, so we need to transform input to a string. So ideally only string:string mappings should come into this function.
So this should be changed on SDK and on a portal. We will take a look at this feature request with a team, but I could not give you any ETA for now.
As we do not have plans to add support for this feature in the next year, I'm closing the issue.