Runlight.Importers.Visits (runlight v0.1.0)

Copy Markdown View Source

Visit history from Umami or a CSV file: pageviews and custom events with where each visit came from, its place, and its device, written as imported visits so the dashboard's history does not start the day Runlight was installed (the SDK's importers/visits.ts and csvvisits.ts).

The dashboard drives an Umami import a few days at a time, oldest first. It stops where Runlight's own visits begin, so nothing is counted twice, and it remembers how far it got, so running it again carries on from there.

Summary

Functions

At most this many rows in one CSV request.

Which shape a file is, from its header row (lower case, as the dashboard reads it): "umami", "runlight", or nil.

One row as {namespace, hit}, or nil for a row that is not a pageview or a named event, or has no time. Umami rows use the namespace the Umami API import does, so the same visits brought in both ways get the same ids.

One batch of a CSV file, sorted oldest first by the dashboard. Only rows from before Runlight's own first visit, and within what the site keeps, are written. A batch can run again: its time span is cleared first.

One step: read the next few days from Umami and write them as imported visits.

A row's time in milliseconds, or NaN. ISO 8601 with or without a zone (both read as UTC when no zone is given, as Umami writes them), or a Unix time in seconds or milliseconds.

The websites an Umami account can see, to pick which one becomes this site's history.

Functions

csv_batch()

At most this many rows in one CSV request.

csv_format(columns)

@spec csv_format([String.t()]) :: String.t() | nil

Which shape a file is, from its header row (lower case, as the dashboard reads it): "umami", "runlight", or nil.

csv_hit(r, format)

@spec csv_hit(Runlight.JS.Object.t() | map(), String.t()) :: {String.t(), map()} | nil

One row as {namespace, hit}, or nil for a row that is not a pageview or a named event, or has no time. Umami rows use the namespace the Umami API import does, so the same visits brought in both ways get the same ids.

import_csv_visits(rl, site_id, rows)

@spec import_csv_visits(Runlight.t(), String.t(), term()) :: Runlight.JS.Object.t()

One batch of a CSV file, sorted oldest first by the dashboard. Only rows from before Runlight's own first visit, and within what the site keeps, are written. A batch can run again: its time span is cleared first.

import_umami_visits(rl, site_id, credentials, website, cursor)

@spec import_umami_visits(
  Runlight.t(),
  String.t(),
  map(),
  String.t(),
  String.t() | nil
) ::
  Runlight.JS.Object.t()

One step: read the next few days from Umami and write them as imported visits.

row_time(r, format)

@spec row_time(Runlight.JS.Object.t() | map(), String.t()) :: number() | :nan

A row's time in milliseconds, or NaN. ISO 8601 with or without a zone (both read as UTC when no zone is given, as Umami writes them), or a Unix time in seconds or milliseconds.

umami_websites(rl, credentials)

@spec umami_websites(Runlight.t(), map()) :: [Runlight.JS.Object.t()]

The websites an Umami account can see, to pick which one becomes this site's history.