Reputation: 4786
I have a webapp with search functionality.
I want to be able to track a search event with a list of keywords that were looked for (in order to be able to identify most common keywords).
I currently track data as follows:
telemetryClient.TrackEvent(Names.RepositorySearch, new Dictionary<string, string>()
{
{PropertyKeys.OrganizationName, repositoryQueryParameter.OrganizationName},
{PropertyKeys.RepositoryName, repositoryQueryParameter.RepositoryName},
{PropertyKeys.Query, query },
{PropertyKeys.IsRegex, isRegex.ToString()},
{PropertyKeys.ResultsCount, resultsCount.ToString()},
{PropertyKeys.QueryExecutionTime, elapsed.TotalMilliseconds.ToString()},
});
I track a full query, which is a bit different than list of tokens/keywords.
I know I could just post another little event for each keyword in a loop, but that seems nasty...
Upvotes: 1
Views: 2009
Reputation: 1709
If you JSON-encode the search parameters, then you can use the extract_json() function to unpack them in a Kusto query.
Tracking code:
telemetryClient.TrackEvent(
"RepositorySearch",
new Dictionary<string,string> {
// JSON literal used for example purposes.
// Use your favorite JSON serializer in real life.
["SearchTerms"] = "[ \"Term1\", \"Term2\" ]",
}
);
Kusto query:
customEvents
| where name == "RepositorySearch"
| extend searchTerms = parse_json(customDimensions.SearchTerms)
Some of the App Insights data visualizers are smart enough to recognize and render JSON lists/objects nicely automatically. If you just want to visually inspect the data, a custom query might not even be necessary.
Upvotes: 2