Create Data Compatible With Sankey Diagram Widget - Example 2

Create data compatible with sankey diagram widget using the sankey() function to show flow relationship

Query

flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[/Filter/] 1{{Aggregate}} result{{Result Set}} repo --> 0 0 --> 1 1 --> result
logscale
Type=accesslog referrer!="-"
| sankey(source=referrer, target=url)

Introduction

A sankey diagram widget is a visualization used to depict a flow from one set of values to another.

In this example, the sankey() function is used to produce sankey compatible data for a webserver log showing the URL address (the referrer) of the website that sends users to another website using a link.

Typetimestampmethodurlreferrer
accesslog2025-05-02 11:45:23GET/api/users-
accesslog2025-05-02 11:45:30POST/api/users-
accesslog2025-05-02 11:46:12GET/api/products-
accesslog2025-05-02 11:46:45PUT/api/users-
accesslog2025-05-02 11:47:01DELETE/api/usershttps://example.com/user
accesslog2025-05-02 11:47:33GET/api/orders-
accesslog2025-05-02 11:48:02POST/api/orders-
accesslog2025-05-02 11:48:15GET/api/carthttps://example.com/user
accesslog2025-05-02 11:48:45POST/api/login-
accesslog2025-05-02 11:49:01GET/api/logouthttps://example.com/login
accesslog2025-05-02 11:49:30GET/api/users-
accesslog2025-05-02 11:50:00POST/api/products-
accesslog2025-05-02 11:50:23PUT/api/products-
accesslog2025-05-02 11:50:45GET/api/users-
accesslog2025-05-02 11:51:12POST/api/carthttps://example.com/user
accesslog2025-05-02 11:51:33GET/api/users-
accesslog2025-05-02 11:52:01GET/api/products-
accesslog2025-05-02 11:52:30POST/api/orders-
accesslog2025-05-02 11:53:00DELETE/api/productshttps://example.com/products
accesslog2025-05-02 11:53:15GET/api/dashboardhttps://example.com/products

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[/Filter/] 1{{Aggregate}} result{{Result Set}} repo --> 0 0 --> 1 1 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    Type=accesslog referrer!="-"

    Filters for all webserver logs where the referrer is not equal to -. It returns all results where the value is not -.

    The value - is often used by analytics to define an empty value. In this example, we therefore filter for webserver logs where there is referrer information.

  3. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[/Filter/] 1{{Aggregate}} result{{Result Set}} repo --> 0 0 --> 1 1 --> result style 1 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    | sankey(source=referrer, target=url)

    Produces sankey compatible data for a webserver log showing wich target URLs matches the referrer URL. If one URL links to the same website twice, the count of referring pages for that website will be one and the count of backlinks will be two.

    Note that source and target are required fields to be able to produce a Sankey Diagram.

  4. Event Result set.

Summary and Results

The query is used to produce data compatible with sankey diagram widgets, showing the referrer URL. The query is useful to get an overview of the webpage that a user was on right before they landed on your page, the target (it shows how users navigate to different URLs on your site).

Showing Relationship with sankey()