diff --git a/make_post_sell/templates/analytics.j2 b/make_post_sell/templates/analytics.j2 index 781725e..78f65cc 100644 --- a/make_post_sell/templates/analytics.j2 +++ b/make_post_sell/templates/analytics.j2 @@ -6,29 +6,43 @@ {% block content -%} -{% macro line_chart(data, max_value, label, color) %} +{# y-axis tick label — `as_pct` formats v as a percentage (0..1 → 0%..100%), + otherwise show v rounded as integer with `unit` suffix appended. #} +{% macro y_tick_label(v, unit, as_pct) -%} +{%- if as_pct -%}{{ (v * 100) | round(0) | int }}%{%- else -%}{{ v | round(0) | int }}{{ unit }}{%- endif -%} +{%- endmacro %} + +{% macro line_chart(data, max_value, label, color, unit="", as_pct=False, axis_label="") %} {% if data and max_value > 0 %}
- - {% for pct in [25, 50, 75] %} - + + {# y-axis label (top-left, above the highest tick) #} + {% if axis_label %} + {{ axis_label }} + {% endif %} + {# gridlines + y-axis tick labels (0/25/50/75/100% of max) #} + {% for pct in [0, 25, 50, 75, 100] %} + {% set y_pos = 140 - (pct / 100 * 130) %} + + {{ y_tick_label((pct / 100) * max_value, unit, as_pct) }} {% endfor %} - - {% for b in data %} - {{ b.label }}: {{ b.tooltip }} {% endfor %} {% for b in data %} {% if loop.index0 % 7 == 0 %} - {{ b.label }} {% endif %} {% endfor %} @@ -73,17 +87,22 @@ {% if daily_views and daily_views_max > 0 %}

Daily Views (last 28 days)

- - {# Gridlines #} - {% for pct in [25, 50, 75] %} - + + {# y-axis label #} + views + {# Gridlines + y-axis tick labels #} + {% for pct in [0, 25, 50, 75, 100] %} + {% set y_pos = 140 - (pct / 100 * 130) %} + + {{ ((pct / 100) * daily_views_max) | round(0) | int }} {% endfor %} - {# Bars #} {% for b in daily_views %} {% set bar_h = (b.count / daily_views_max * 130) if daily_views_max > 0 else 0 %} - {{ b.label }}: {{ b.count }} view{{ 's' if b.count != 1 else '' }} @@ -91,7 +110,7 @@ {# Date labels every 7th bar #} {% for b in daily_views %} {% if loop.index0 % 7 == 0 %} - {{ b.label }} {% endif %} {% endfor %} @@ -103,19 +122,19 @@ {% if daily_session_duration_max > 0 %}

Session Duration Trend (last 28 days)

Average time visitors spend per session.

- {{ line_chart(daily_session_duration, daily_session_duration_max, "Session duration trend", "var(--blue-color, #98b6fa)") }} + {{ line_chart(daily_session_duration, daily_session_duration_max, "Session duration trend", "var(--blue-color, #98b6fa)", unit="s", axis_label="seconds") }} {% endif %} {% if daily_engagement %}

Engagement Trend (last 28 days)

Active interaction time as a fraction of total session time.

- {{ line_chart(daily_engagement, 1.0, "Engagement trend", "var(--green-color, #a3c765)") }} + {{ line_chart(daily_engagement, 1.0, "Engagement trend", "var(--green-color, #a3c765)", as_pct=True, axis_label="%") }} {% endif %} {% if daily_bounce %}

Bounce Rate Trend (last 28 days)

Sessions under 7 seconds visible. Lower is better.

- {{ line_chart(daily_bounce, 1.0, "Bounce rate trend", "var(--red-color, #bc2131)") }} + {{ line_chart(daily_bounce, 1.0, "Bounce rate trend", "var(--red-color, #bc2131)", as_pct=True, axis_label="%") }} {% endif %} {# --- Ring Consumed breakdown --- #} @@ -429,7 +448,7 @@ {% if daily_referrers_max > 0 %}

External Referrer Trend (last 28 days)

Daily count of visits from external referrers (excludes direct and internal traffic).

- {{ line_chart(daily_referrers, daily_referrers_max, "External referrer trend", "var(--orange-color, #e8a838)") }} + {{ line_chart(daily_referrers, daily_referrers_max, "External referrer trend", "var(--orange-color, #e8a838)", axis_label="visits") }} {% endif %} {# --- Top Referrer Domains (21d) --- #}