Generates the self-contained HTML/JS installed once per page: the GA4 gtag
loader, the client-side event queue that beacons to the usage-log Sheet, the
Shiny.addCustomMessageHandler() handlers that cc_track() and
cc_track_session() depend on, and a window.ccTrack(event, params, metrics)
helper for page JS.
Usage
cc_ga_js(
app,
content_group = app,
app_version = "",
ip = "",
measurement_id = .CC_GA_ID,
log_url = Sys.getenv("CALCOFI_LOG_URL", "")
)Arguments
- app
short app id recorded on every event, e.g.
"db-viz-hex"- content_group
GA4 content group for reporting; defaults to
app- app_version
version string recorded on every event, e.g. a git SHA
- ip
client IP stamped on every logged row. Behind shiny-server this is the only way to record a real one: the websocket handshake the R session sees is a fresh localhost connection with no
X-Forwarded-For, so make the app'suiafunction(req)and passcc_client_ip(req)here. Left empty, theipcolumn falls back to whatevercc_track_session()reports (127.0.0.1behind a proxy).- measurement_id
GA4 measurement ID; defaults to the CalCOFI apps property
- log_url
Apps Script
/execendpoint for the Sheet log. Defaults to theCALCOFI_LOG_URLenvironment variable; empty means the Sheet leg is a silent no-op (GA4 still receives events).
Details
The same snippet serves every CalCOFI app; content_group (and the app
column of the Sheet) is what separates them in reporting, so no app needs its
own measurement ID.
Examples
substr(cc_ga_js(app = "db-viz-hex"), 1, 60)
#> <!-- Google tag (gtag.js) + CalCOFI usage log -->
#> <script as