appcenter-sdk-react-native icon indicating copy to clipboard operation
appcenter-sdk-react-native copied to clipboard

Analytics.trackEvent should allow boolean | number | undefined in event property value

Open NullPainter2 opened this issue 5 years ago • 1 comments

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

  1. Which version of the App Center SDK are you using? 3.0.3

NullPainter2 avatar Jul 02 '20 16:07 NullPainter2

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.

vvechkanov avatar Jul 03 '20 07:07 vvechkanov

As we do not have plans to add support for this feature in the next year, I'm closing the issue.

DmitriyKirakosyan avatar Apr 15 '24 04:04 DmitriyKirakosyan