Module: TrackRelay::PageViewTracking

Extended by:
ActiveSupport::Concern
Includes:
ControllerTracking
Defined in:
lib/track_relay/page_view_tracking.rb

Overview

Opt-in automatic server-side page_view emission.

Hosts that deliver GA4 purely via the Measurement Protocol (no client-side gtag) still need standard page_view events for GA4's page and engagement reports. Include this concern and call the macro:

class ApplicationController < ActionController::Base
include TrackRelay::PageViewTracking
track_page_views
end

Events go through the normal track path, so the host's track_gate, subscribers, and GA4 page-context enrichment apply unchanged.

The builtin page_view catalog entry

page_view sits in GA4_RESERVED_NAMES, which guards custom catalog events from shadowing gtag's auto-collected ones. A server-side host has no auto-collection — the MP-standard page_view is exactly what it must send — so the concern registers the definition directly with the catalog, bypassing the DSL's reserved-name validation on purpose.

Class Method Summary collapse

Methods included from ControllerTracking

#track

Class Method Details

.register_builtin_event!void

This method returns an undefined value.

Register the builtin page_view EventDefinition (no params — page context is attached by GA4 enrichment at delivery time). Idempotent so it can be re-run after test-suite Catalog.clear!.



40
41
42
43
44
# File 'lib/track_relay/page_view_tracking.rb', line 40

def self.register_builtin_event!
  return if Catalog.defined?(:page_view)

  Catalog.register(EventDefinition.new(name: :page_view))
end