prokodo (GA4) icon

prokodo (GA4)

Query Google Analytics 4 (Data API) with a Service Account. Includes helpers for best post times and quick lists (landing pages, referrers).

Channel Hours TopK (Helper)

AI-generated

Summary

Retrieve the top K hourly time slots aggregated by weekday for a specified GA4 default channel group based on historical session or traffic data, mapped to upcoming datetimes within a horizon.

Inputs

  • Property ID (required) — Numeric GA4 Property ID to use for report queries.
  • Default Channel Group (required) — The GA4 Default Channel Group to filter sessions by (e.g., Organic Social).
  • Metric for Timing (required) — The metric aggregated by hour and weekday when computing the best time buckets, options are Page Views (auto-switched to sessions for this operation), Sessions, or Engaged Sessions.
  • Lookback (days) (required) — Number of past days to aggregate data from to find top time buckets (between 7 and 365).
  • Top K Buckets (required) — How many top weekday-hour buckets to return as best time slots.
  • Horizon (days ahead) (required) — Number of upcoming days over which to map the top buckets into actual ISO datetimes.
  • Label Time Zone (IANA) (required) — Time zone used to label the suggested upcoming slots in a human-readable format.
  • Occurrence Mode (required) — Whether to return only the first occurrence per top bucket or expand occurrences weekly within the horizon.
  • Max Occurrences per Bucket (required) — Maximum number of weekly repeated occurrences per time bucket when expanding occurrences.
  • Return Property Quota — Optionally include GA4 property quota information to monitor remaining API tokens.

Output shape

a single JSON object containing top time slot ISO datetimes in the specified time zone, their human-readable labels, the analyzed buckets with ranking and scores, the metric used for scoring, the lookback and horizon parameters, occurrence mode, and optionally GA4 property quota info

The output includes the underlying GA4 report response under the key 'raw' for inspection. Time buckets are ranked by the selected metric aggregated over the lookback period and mapped to upcoming exact datetimes over the horizon. Page Views metric is auto-switched to Sessions for this operation due to GA4 constraints.

Examples

Example 1: Find the 3 best hourly time slots per weekday for the 'Organic Social' channel group over the past 60 days, projecting them over the next 14 days in Europe/Berlin timezone using Sessions metric, returning only the next occurrence per bucket.

Input Property ID, select 'Organic Social' channel, use 'Sessions' as timing metric, lookbackDays=60, topK=3, horizonDays=14, timeZone='Europe/Berlin', occurrenceMode='first', maxOccurrences=9, returnQuota=true.

Discussion