azureazure-application-insightsazure-data-explorerms-app-analytics

Application Insights: Analytics - how to extract string at specific position


I'd like to do,

1. Actual urls included in pageView

2. Value expected to extract

3. Expected output in AI Analytics

image

Tried to do

https://learn.microsoft.com/en-us/azure/application-insights/app-insights-analytics-reference#parseurl

https://aka.ms/AIAnalyticsDemo

I think extract or parseurl(url) should be useful. I tried the latter parseurl(url) but don't know how to extract "Query Parameters" as one column.

pageViews
| where timestamp > ago(1d)
| extend parsed_url=parseurl(url)
| summarize count() by tostring(parsed_url)
| render barchart 

Solution

  • Yes, parseurl is the way to do it. It results in a dynamic value which you can use as a json. To get the "query" value of the query parameters:

    pageViews
    | where timestamp > ago(1d)
    | extend parsed_url=parseurl(url)
    | extend query = tostring(parsed_url["Query Parameters"]["query"])
    

    and to summarize by the param value:

    pageViews
    | where timestamp > ago(1d)
    | extend parsed_url=parseurl(url)
    | extend query = tostring(parsed_url["Query Parameters"]["query"])
    | extend param = toint(parsed["Query Parameters"]["param"])
    | summarize sum(param) by query
    

    You can see how it works on your example values in the demo portal:

    let vals = datatable(url:string)["https://example.com/dir01/?
    query=apple&param=1", "https://example.com/dir01/?query=apple&param=1", 
    "https://example.com/dir01/?query=lemon+juice&param=1", 
    "https://example.com/dir01/?query=lemon+juice&param=0", 
    "https://example.com/dir01/?query=tasteful+grape+wine&param=1"];
    vals
    | extend parsed = parseurl(url)
    | extend query = tostring(parsed["Query Parameters"]["query"])
    | extend param = toint(parsed["Query Parameters"]["param"])
    | summarize sum(param) by query
    

    Hope this helps,

    Asaf