028: Analytics ecommerce

A small e-commerce site wired to the built-in stdout and GA4 analytics collectors. Piko tracks every pageview automatically. Add-to-cart and checkout events attach revenue data and custom properties.

What this demonstrates

  • WithBackendAnalytics wiring the built-in stdout and GA4 collectors.
  • piko.SetAnalyticsRevenue to attach monetary values to pageviews.
  • piko.AddAnalyticsProperty for per-event custom properties.
  • piko.SetAnalyticsEventName to promote a pageview to a named custom event.
  • piko.analytics.track(...) (frontend) for fully custom events emitted client-side from the pp-cart component (add_to_cart and purchase), while the backend promotes the automatic pageview to a named purchase event via SetAnalyticsEventName.

Project structure

src/
  cmd/main/main.go      Bootstrap wiring the frontend analytics module and backend collectors.
  pages/
    index.pk            A single shop page with products and an add-to-cart action.
  actions/
    cart/
      purchase.go       Records a purchase and emits the analytics event.
  partials/             Shared layout and product-card partials.
  components/           Client components that drive the analytics events.

How to run this example

From the Piko repository root:

cd examples/scenarios/028_analytics_ecommerce/src/
go mod tidy
air

The configured backend collectors receive every event. Swap them for a real collector (GA4, Plausible, Mixpanel) in production.

See also