KosmoKrator

analytics

Fathom Analytics Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Fathom Analytics KosmoKrator integration.

6 functions 6 read 0 write Bearer token auth

Lua Namespace

Agents call this integration through app.integrations.fathom.*. Use lua_read_doc("integrations.fathom") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Fathom Analytics — Lua API Reference

list_sites

List all websites tracked in Fathom Analytics.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of sites to return (default: 20)
starting_afterintegernoCursor for pagination — pass the ID of the last site from a previous response

Example

local result = app.integrations.fathom.list_sites({limit = 10})

for _, site in ipairs(result.data) do
  print(site.name .. " (" .. site.domain .. ") — ID: " .. site.id)
end

get_site

Get details for a specific Fathom site by ID.

Parameters

NameTypeRequiredDescription
site_idstringyesThe Fathom site ID (e.g., "CDCLS")

Example

local result = app.integrations.fathom.get_site({site_id = "CDCLS"})
print("Site: " .. result.name .. " — " .. result.domain)

list_pageviews

List pageviews for a site with date filtering and pagination.

Parameters

NameTypeRequiredDescription
site_idstringyesThe Fathom site ID
date_fromstringnoStart date (ISO 8601, e.g., "2025-01-01")
date_tostringnoEnd date (ISO 8601, e.g., "2025-01-31")
limitintegernoMaximum number of pageviews to return (default: 20)
starting_afterintegernoCursor for pagination — pass the ID of the last pageview

Example

local result = app.integrations.fathom.list_pageviews({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  limit = 50
})

for _, pv in ipairs(result.data) do
  print(pv.page_path .. " — " .. pv.created_at)
end

get_aggregate

Get aggregated analytics data for a site. Supports grouping by dimensions.

Parameters

NameTypeRequiredDescription
site_idstringyesThe Fathom site ID
date_fromstringyesStart date (ISO 8601)
date_tostringyesEnd date (ISO 8601)
metricsstringnoComma-separated metrics: pageviews, visits, visitors, bounce_rate, visit_duration
group_bystringnoGroup by dimension: page_hostname, page_path, referrer_hostname, referrer_path, country, browser, device_type, os, query_param
sort_bystringnoSort field and direction, e.g., "pageviews:desc", "visitors:asc"
limitintegernoMaximum number of grouped results

Available Metrics

MetricDescription
pageviewsTotal pageviews
visitsTotal visits (sessions)
visitorsUnique visitors
bounce_rateBounce rate percentage
visit_durationAverage visit duration in seconds

Available Group-By Dimensions

DimensionDescription
page_hostnameDomain name
page_pathURL path (e.g., /blog/post-1)
referrer_hostnameReferrer domain
referrer_pathReferrer path
countryCountry code
browserBrowser name
device_typeDevice type (Desktop, Mobile, Tablet)
osOperating system
query_paramQuery parameter values

Examples

Overall site metrics

local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "pageviews,visits,visitors,bounce_rate"
})

print("Pageviews: " .. result.pageviews)
print("Visitors: " .. result.visitors)
print("Bounce rate: " .. result.bounce_rate .. "%")

Top pages by pageviews

local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "pageviews,visitors",
  group_by = "page_path",
  sort_by = "pageviews:desc",
  limit = 10
})

for _, row in ipairs(result.data) do
  print(row.page_path .. ": " .. row.pageviews .. " pageviews, " .. row.visitors .. " visitors")
end

Traffic by country

local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "visitors,pageviews",
  group_by = "country",
  sort_by = "visitors:desc",
  limit = 10
})

for _, row in ipairs(result.data) do
  print(row.country .. ": " .. row.visitors .. " visitors")
end

Traffic by device type

local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "visits,bounce_rate",
  group_by = "device_type"
})

for _, row in ipairs(result.data) do
  print(row.device_type .. ": " .. row.visits .. " visits, " .. row.bounce_rate .. "% bounce")
end

list_events

List custom events tracked for a site.

Parameters

NameTypeRequiredDescription
site_idstringyesThe Fathom site ID
limitintegernoMaximum number of events to return (default: 20)
starting_afterintegernoCursor for pagination — pass the ID of the last event

Example

local result = app.integrations.fathom.list_events({
  site_id = "CDCLS",
  limit = 50
})

for _, event in ipairs(result.data) do
  print(event.name .. " — ID: " .. event.id)
end

get_current_user

Get the currently authenticated Fathom user profile. Useful for verifying API connectivity.

Parameters

None.

Example

local result = app.integrations.fathom.get_current_user({})
print("Logged in as: " .. result.email)

Multi-Account Usage

If you have multiple Fathom accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.fathom.function_name({...})

-- Explicit default (portable across setups)
app.integrations.fathom.default.function_name({...})

-- Named accounts
app.integrations.fathom.work.function_name({...})
app.integrations.fathom.personal.function_name({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Fathom Analytics — Lua API Reference

## list_sites

List all websites tracked in Fathom Analytics.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of sites to return (default: 20) |
| `starting_after` | integer | no | Cursor for pagination — pass the ID of the last site from a previous response |

### Example

```lua
local result = app.integrations.fathom.list_sites({limit = 10})

for _, site in ipairs(result.data) do
  print(site.name .. " (" .. site.domain .. ") — ID: " .. site.id)
end
```

---

## get_site

Get details for a specific Fathom site by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `site_id` | string | yes | The Fathom site ID (e.g., `"CDCLS"`) |

### Example

```lua
local result = app.integrations.fathom.get_site({site_id = "CDCLS"})
print("Site: " .. result.name .. " — " .. result.domain)
```

---

## list_pageviews

List pageviews for a site with date filtering and pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `site_id` | string | yes | The Fathom site ID |
| `date_from` | string | no | Start date (ISO 8601, e.g., `"2025-01-01"`) |
| `date_to` | string | no | End date (ISO 8601, e.g., `"2025-01-31"`) |
| `limit` | integer | no | Maximum number of pageviews to return (default: 20) |
| `starting_after` | integer | no | Cursor for pagination — pass the ID of the last pageview |

### Example

```lua
local result = app.integrations.fathom.list_pageviews({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  limit = 50
})

for _, pv in ipairs(result.data) do
  print(pv.page_path .. " — " .. pv.created_at)
end
```

---

## get_aggregate

Get aggregated analytics data for a site. Supports grouping by dimensions.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `site_id` | string | yes | The Fathom site ID |
| `date_from` | string | yes | Start date (ISO 8601) |
| `date_to` | string | yes | End date (ISO 8601) |
| `metrics` | string | no | Comma-separated metrics: `pageviews`, `visits`, `visitors`, `bounce_rate`, `visit_duration` |
| `group_by` | string | no | Group by dimension: `page_hostname`, `page_path`, `referrer_hostname`, `referrer_path`, `country`, `browser`, `device_type`, `os`, `query_param` |
| `sort_by` | string | no | Sort field and direction, e.g., `"pageviews:desc"`, `"visitors:asc"` |
| `limit` | integer | no | Maximum number of grouped results |

### Available Metrics

| Metric | Description |
|--------|-------------|
| `pageviews` | Total pageviews |
| `visits` | Total visits (sessions) |
| `visitors` | Unique visitors |
| `bounce_rate` | Bounce rate percentage |
| `visit_duration` | Average visit duration in seconds |

### Available Group-By Dimensions

| Dimension | Description |
|-----------|-------------|
| `page_hostname` | Domain name |
| `page_path` | URL path (e.g., `/blog/post-1`) |
| `referrer_hostname` | Referrer domain |
| `referrer_path` | Referrer path |
| `country` | Country code |
| `browser` | Browser name |
| `device_type` | Device type (Desktop, Mobile, Tablet) |
| `os` | Operating system |
| `query_param` | Query parameter values |

### Examples

#### Overall site metrics

```lua
local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "pageviews,visits,visitors,bounce_rate"
})

print("Pageviews: " .. result.pageviews)
print("Visitors: " .. result.visitors)
print("Bounce rate: " .. result.bounce_rate .. "%")
```

#### Top pages by pageviews

```lua
local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "pageviews,visitors",
  group_by = "page_path",
  sort_by = "pageviews:desc",
  limit = 10
})

for _, row in ipairs(result.data) do
  print(row.page_path .. ": " .. row.pageviews .. " pageviews, " .. row.visitors .. " visitors")
end
```

#### Traffic by country

```lua
local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "visitors,pageviews",
  group_by = "country",
  sort_by = "visitors:desc",
  limit = 10
})

for _, row in ipairs(result.data) do
  print(row.country .. ": " .. row.visitors .. " visitors")
end
```

#### Traffic by device type

```lua
local result = app.integrations.fathom.get_aggregate({
  site_id = "CDCLS",
  date_from = "2025-01-01",
  date_to = "2025-01-31",
  metrics = "visits,bounce_rate",
  group_by = "device_type"
})

for _, row in ipairs(result.data) do
  print(row.device_type .. ": " .. row.visits .. " visits, " .. row.bounce_rate .. "% bounce")
end
```

---

## list_events

List custom events tracked for a site.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `site_id` | string | yes | The Fathom site ID |
| `limit` | integer | no | Maximum number of events to return (default: 20) |
| `starting_after` | integer | no | Cursor for pagination — pass the ID of the last event |

### Example

```lua
local result = app.integrations.fathom.list_events({
  site_id = "CDCLS",
  limit = 50
})

for _, event in ipairs(result.data) do
  print(event.name .. " — ID: " .. event.id)
end
```

---

## get_current_user

Get the currently authenticated Fathom user profile. Useful for verifying API connectivity.

### Parameters

None.

### Example

```lua
local result = app.integrations.fathom.get_current_user({})
print("Logged in as: " .. result.email)
```

---

## Multi-Account Usage

If you have multiple Fathom accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.fathom.function_name({...})

-- Explicit default (portable across setups)
app.integrations.fathom.default.function_name({...})

-- Named accounts
app.integrations.fathom.work.function_name({...})
app.integrations.fathom.personal.function_name({...})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.fathom.fathom_list_sites({
  limit = 1,
  starting_after = 1
})
print(result)

Functions

fathom_list_sites

List all websites tracked in Fathom Analytics. Returns site IDs, names, and domains you can query for analytics data.

Operation
Read read
Full name
fathom.fathom_list_sites
ParameterTypeRequiredDescription
limit integer no Maximum number of sites to return (default: 20).
starting_after integer no Cursor for pagination — pass the ID of the last site from a previous response to get the next page.

fathom_get_site

Get details for a specific Fathom Analytics site by ID. Returns site name, domain, tracking code, and other configuration.

Operation
Read read
Full name
fathom.fathom_get_site
ParameterTypeRequiredDescription
site_id string yes The Fathom site ID (e.g., "CDCLS").

fathom_list_pageviews

List pageviews for a Fathom Analytics site with date filtering and pagination. Returns individual pageview records including URL, referrer, and device info.

Operation
Read read
Full name
fathom.fathom_list_pageviews
ParameterTypeRequiredDescription
site_id string yes The Fathom site ID (e.g., "CDCLS").
date_from string no Start date for filtering (ISO 8601, e.g., "2025-01-01").
date_to string no End date for filtering (ISO 8601, e.g., "2025-01-31").
limit integer no Maximum number of pageviews to return (default: 20).
starting_after integer no Cursor for pagination — pass the ID of the last pageview from a previous response.

fathom_get_aggregate

Get aggregated analytics data from Fathom. Supports pageviews, visits, visitors, bounce rate, and more. Can group results by page, country, browser, device type, etc.

Operation
Read read
Full name
fathom.fathom_get_aggregate
ParameterTypeRequiredDescription
site_id string yes The Fathom site ID (e.g., "CDCLS").
date_from string yes Start date (ISO 8601, e.g., "2025-01-01").
date_to string yes End date (ISO 8601, e.g., "2025-01-31").
metrics string no Comma-separated metrics to retrieve. Available: pageviews, visits, visitors, bounce_rate, visit_duration. Default: all metrics.
group_by string no Group results by a dimension: page_hostname, page_path, referrer_hostname, referrer_path, country, browser, device_type, os, query_param.
sort_by string no Sort field and direction (e.g., "pageviews:desc", "visitors:asc").
limit integer no Maximum number of grouped results to return.

fathom_list_events

List custom events tracked in Fathom Analytics for a site. Returns event names, event IDs, and configuration details.

Operation
Read read
Full name
fathom.fathom_list_events
ParameterTypeRequiredDescription
site_id string yes The Fathom site ID (e.g., "CDCLS").
limit integer no Maximum number of events to return (default: 20).
starting_after integer no Cursor for pagination — pass the ID of the last event from a previous response.

fathom_get_current_user

Get the currently authenticated Fathom user profile. Returns user name, email, and account details. Useful for verifying API connectivity.

Operation
Read read
Full name
fathom.fathom_get_current_user
ParameterTypeRequiredDescription
No parameters.