Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert undefined to blank in customDimensions? #1471

Closed
coreyroth opened this issue Feb 9, 2021 · 12 comments
Closed

Convert undefined to blank in customDimensions? #1471

coreyroth opened this issue Feb 9, 2021 · 12 comments

Comments

@coreyroth
Copy link

Is your feature request related to a problem? Please describe.
I have a number of customDimensions in trackPageView, trackEvent, etc. Given this SDK is JavaScript based, dealing with undefined is a common thing. When we send a value of undefined, it shows up in our data model as undefined as well. I'm then reading the data through the API or Power BI and undefined. That doesn't look good on reports and we have to do comparisons to both '' and undefined.

I can work around this easily enough, but it's a bit of a mess when I am sending 50+ properties in an event. Does it make sense for the SDK to strip undefined and send '' instead of undefined?

Describe the solution you'd like
I would like the SDK or the API to convert undefined to a blank ('') value so it doesn't show up in the data model. This could be an option on the SDK perhaps in case people don't want this behavior.

Describe alternatives you've considered
I can work around this of course by wrapping the values I am sending with a function to detect undefined. I could also use a telemetryInitializer to work around it as well.

@MSNev
Copy link
Collaborator

MSNev commented Sep 13, 2021

v2.7.0 is not fully deployed to NPM and all CDN endpoints

@MSNev MSNev closed this as completed Sep 13, 2021
@coreyroth
Copy link
Author

Thanks for including this!

@MSNev
Copy link
Collaborator

MSNev commented Sep 13, 2021

It may take up to around 30 minutes for all CDN endpoints to pick up the new bits (depending where you are located)

@coreyroth
Copy link
Author

coreyroth commented Dec 20, 2021

I finally have had a chance to test this with 2.7.2 and I'm still seeing values listed as "undefined" in customDimensions. Is there a trick to making this work?

I found the parameter in the config where I set { convertUndefined: '' }. I added this and have several parameters that wrote undefined properties into the customDimensions of a pageView. However, it still shows 'undefined' in customDimensions in Application Insights.

@MSNev MSNev reopened this Dec 20, 2021
@MSNev
Copy link
Collaborator

MSNev commented Dec 20, 2021

Reopened so we can investigate further @Karlie-777 do you have some cycles to investigate this see the PR #1630 to see what was changed

@Karlie-777
Copy link
Contributor

Hi @coreyroth
The current npm version only works with undefined value but not value equal to string "undefined".
so for example,
appInsights.trackEvent({ name: "Custom event" , properties:{"prop1": undefined, "prop2": "undefined"}});

prop1 will be replaced but not prop2.

@coreyroth
Copy link
Author

Hi @Karlie-777, perfect. That's my understanding as well. Using v2.7.2.

I initialize my instance with something like:

this.appInsights = new ApplicationInsights({ config: { instrumentationKey: instrumentationKey, autoTrackPageVisitTime: true, disableAjaxTracking: true, convertUndefined: '' } });

Then I am writing undefined versus 'undefined' into my objects. Here's the browser output of some of my object before I call trackPageView().

this.appInsights.trackPageView({ properties: this.trackedProperties });

Screen Shot 2022-01-17 at 2 09 37 PM

Here's what I am seeing in Application Insights:

Screen Shot 2022-01-17 at 2 13 47 PM

@Karlie-777
Copy link
Contributor

Hi @coreyroth
Do you mind trying convertUndefined: 'test' and convertUndefined: ' ' (Note: use a space instead of empty string)
Do the two configs replace undefined?

@coreyroth
Copy link
Author

Hi @Karlie-777. I just validated and neither of those are working for me. Does it work for all of the various methods in the SDK? In this case, I was testing trackPageView().

@Karlie-777
Copy link
Contributor

Hi @coreyroth
I tried both npm and snippet 2.7.2 multiple times and both work for my local apps. Do you mind checking network "track" payloads? is the undefined in trackPageViewData replaced?

@coreyroth
Copy link
Author

Hi @Karlie-777,

Interesting. So the track network requests are showing as "undefined" in the Payload using quotes.

Screen Shot 2022-01-18 at 2 43 51 PM

That's definitely not how I am writing the values in though as I showed in the screenshot earlier. I definitely could be doing something wrong but I'm not sure what.

@Karlie-777
Copy link
Contributor

Hi @coreyroth,
here is my test code.

code

payload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants