1

We are using the client-side javascript SDK (via the snippet-based integration) for Application Insights to track custom events

appInsights.trackEvent({name:"WinGame"});

How can I add custom properties to this? Something like this?!

appInsights.trackEvent({name:"WinGame", customProperties:{gameName:"Game 1", player:"my player 1"}});
silent
  • 14,494
  • 4
  • 46
  • 86
  • No, the property is `properties` not `customProperties`. This is all in the [documentation if you read it](https://github.com/Microsoft/ApplicationInsights-JS#sending-telemetry-to-the-azure-portal) – Liam Mar 11 '21 at 13:09
  • you dont mean "if you read it" but "if you find it"...thanks anyway – silent Mar 11 '21 at 13:15
  • @Liam...Why it is different here: https://learn.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#properties? – Gaurav Mantri Mar 11 '21 at 13:22
  • I don't know @GauravMantri , ask MS, their docs are always sketchy, especially around Azure. They seem to struggle to keep up with their own changes and documentation is often an after thought. A lot of the Azure function docs are still showing v1 screens despite the function SDK now being totally different since that incarnation. It's open source so you can always open a PR if you feel that strongly about it – Liam Mar 11 '21 at 13:38
  • anyway, if you want to create an answer here for people to easily find it, I'll mark it as accepted – silent Mar 11 '21 at 13:47
  • 1
    I've submitted [an issue on that document](https://github.com/MicrosoftDocs/azure-docs/issues/72008) – Liam Mar 11 '21 at 14:10

1 Answers1

4

As seen on the JS Azure appinsights github page:

Custom properties can be included in your telemetry through the properties named argument. This can be done with any of the Track APIs.

appInsights.trackEvent({   
    name: 'some event',  
    properties: { // accepts any type
       prop1: 'string',
       prop2: 123.45,
       prop3: { nested: 'objects are okay too' }   
    } 
}); 
Liam
  • 27,717
  • 28
  • 128
  • 190