13

I'd like to do,

  • Extracting "query" strings where param=1 as follows in "2."
  • Getting pageViews in Analytics with table as "3."

1. Actual urls included in pageView

  • 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

2. Value expected to extract

  • apple
  • lemon+juice
  • tasteful+grape+wine

3. Expected output in AI Analytics

  • Query Parameters | Count
    • apple | 2
    • lemon+juice | 1
    • tasteful+grape+wine | 1

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 
  • url
    • http://aiconnect2.cloudapp.net/FabrikamProd/
  • parsed_url
    • {"Scheme":"http","Host":"aiconnect2.cloudapp.net","Port":"","Path":"/FabrikamProd/","Username":"","Password":"","Query Parameters":{},"Fragment":""}
Brandon McClure
  • 1,329
  • 1
  • 11
  • 32
grantaka36
  • 277
  • 1
  • 2
  • 14

1 Answers1

21

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

Asaf Strassberg
  • 524
  • 4
  • 7
  • 1
    I could get what I'd like to do with your grateful step-by-step guide. Thank you. – grantaka36 Apr 05 '17 at 03:46
  • This answer was specific to URLs, and while it might be helpful to some folks, it does not answer the actual question of how to extract a substring at a specific position. :( -- Not going to downvote, but perhaps the title of the question should be updated, since the OP isn't actually looking for general substring extraction. – BrainSlugs83 Jul 07 '17 at 21:10
  • parseurl now gets underlined in red in app insighs while parse_url doesn't. Both still work. Is one replacing the other? I found no documentation about this change. – Bernard Vander Beken Apr 29 '20 at 09:33
  • @BernardVanderBeken hovering over the underlined element should bring up a tooltip: "The function 'parseurl' is deprecated; use 'parse_url' instead". – Zhaph - Ben Duguid Nov 24 '21 at 12:11