Below is a copy of the post I wrote for the wonderful Dartistics website, which is maintained by Tim Wilson and Mark Edmondson.
This example creates a Sankey chart to show how traffic flows from the homepage, split by device category.
Steps to achieve this are:
Call google_analytics_4 to get unique pageviews, split by the secondPagePath dimension. We apply a dimension filter to limit the results only to users landing on our website homepage.