APM Tips

KQL · usage

Page views by page name and country

The most viewed pages over the last 7 days split by the visitor's country or region, with distinct users, sampling-adjusted.

Updated

pageViews usage

let lookback = 7d;
pageViews
| where timestamp > ago(lookback)
| summarize
    page_views = sum(itemCount),
    users = dcount(user_Id)
    by name, client_CountryOrRegion
| top 50 by page_views desc

Returns: Up to 50 rows, one per page name and country or region, with the sampling-adjusted page view count and the number of distinct users, most viewed first.

Pitfalls

  • Country comes from a geolocation lookup on the client IP at ingestion. VPNs, corporate proxies and mobile carriers can put visitors in the wrong place.
  • In a single-page app, route changes only produce page views when automatic route tracking (enableAutoRouteTracking) is on; otherwise one page view covers the whole visit.
  • name is whatever the page view was recorded with. Pages that share a title collapse into one row; pass explicit names when you track page views by hand.
  • Views use sum(itemCount), so the counts stay right if sampling is applied to browser telemetry.

How it works

The pageViews table holds one row per page load (or route change, in a single-page app) that the JavaScript SDK recorded in visitors’ browsers. Grouping it by page and country gives the shape of your audience: which pages matter, and where the people reading them are.

Line by line

  • let lookback = 7d; covers a week, which smooths out weekday and weekend differences.
  • page_views = sum(itemCount) counts page views the sampling-aware way. The column is not called views, because views is a KQL keyword and would need brackets (['views']) to work as a name.
  • users = dcount(user_Id) counts distinct anonymous user IDs, the cookie-based IDs the browser SDK assigns. It is a trend measure, not a head count.
  • by name, client_CountryOrRegion groups by page name and country or region. Microsoft documents that the client IP is used for a geolocation lookup when telemetry arrives, which fills client_City, client_StateOrProvince and client_CountryOrRegion; by default the address itself is then discarded and stored as 0.0.0.0.
  • top 50 by views desc keeps the 50 largest page and country pairs.

Reading the result

The same page appearing for many countries is a global page; a page that only one country reads may be a regional campaign or a sign of a bot. An empty country means no location was recorded for those views. If you see your own office’s country at the top of internal tools, that is your staff, not your customers; filter it out before drawing conclusions.

For server-side traffic by country, with latency, see requests by client country. The client IP and geolocation guide explains how the lookup works and when it gets the place wrong, and the JavaScript snippet guide covers how page views are recorded and named.

Variations

  • Pages only: drop client_CountryOrRegion from the by clause for a plain top-pages list.
  • Slowest pages: add p95_ms = percentilew(duration, itemCount, 95); the data model takes page view duration from the browser’s navigation timing.
  • Workspace tables: use AppPageViews, TimeGenerated, Name, ClientCountryOrRegion, UserId and ItemCount.

Sources, checked

  1. Application Insights geolocation and IP address handlinglearn.microsoft.com · checked
  2. Application Insights telemetry data model (page views)learn.microsoft.com · checked
  3. Investigate failures, performance, and transactions (route tracking in single-page apps)learn.microsoft.com · checked
  4. top operator (Kusto)learn.microsoft.com · checked
  5. Migrate an Application Insights classic resource to a workspace-based resource (table schemas)learn.microsoft.com · checked