Skip to main content
Version: v1 (Current)

GxP Analytics Plugin

The GxP Analytics Plugin provides declarative click tracking and a custom event API for reporting analytics from your plugin. The toolkit installs a development implementation so you can wire up and inspect tracking before deploying. The installed platform runtime owns production transport, authorization and persistence; see platform analytics and reporting for those separate contracts.

Overview​

The plugin provides three ways to track events:

APIUse for
gxp-track attributeDeclarative click tracking on any element
window.gxp.track()Custom events from any JS context
inject("gxpTrack")Custom events from inside Vue components

Dev vs. Production Behavior​

The three authoring APIs are intended for the same tracking use cases, but local inspection does not verify the installed production runtime:

EnvironmentWhat happens on a tracked event
ProductionVerify the installed runtime’s transport, endpoint, authorization and persistence; local logging does not exercise them
Dev serverPayload is broadcast on window as a gxp:track CustomEvent and logged to the console as JSON

The reviewed development analytics transport only dispatches a window event; it does not send analytics requests. This does not make the rest of your preview offline: store API calls, proxies, extensions and other application code can still reach configured services. Use synthetic event properties; the development logger exposes them in the browser console.

Declarative Click Tracking (gxp-track)​

Add the gxp-track attribute to any element. Clicks send an interaction event named by the attribute value:

<button gxp-track="registration.submit" gxp-string="btn_submit">Submit</button>

<a gxp-track="sponsor.banner.clicked" href="/sponsor">Visit our sponsor</a>

A click on the button above produces:

{
"event_type": "interaction",
"event_name": "registration.submit",
"project_id": 42,
"properties": {
"element_tag": "button",
"element_text": "Submit"
}
}

element_text is the element's trimmed text content, capped at 100 characters. It can include names or other sensitive text shown in the UI: choose tracked elements deliberately and avoid recording personal data. A click records an interaction, not confirmation that registration, payment or another business operation completed.

Extra Properties (gxp-track-props)​

Attach additional properties as a JSON attribute. They are merged into properties after the element metadata, so a supplied element_tag or element_text replaces that default. Use a JSON object with intentional property names:

<button
gxp-track="cta.clicked"
gxp-track-props='{"placement": "hero", "variant": "primary"}'
>
Get Started
</button>

Invalid JSON in gxp-track-props is silently ignored (the event still fires with the default properties).

For dynamic values, bind the attribute with Vue:

<button
gxp-track="session.join"
:gxp-track-props="JSON.stringify({ session_id: session.id })"
gxp-string="btn_join"
>
Join Session
</button>

Directive vs. Attribute Syntax​

Like gxp-string, both forms work:

<!-- Attribute syntax (recommended) -->
<button gxp-track="cta.clicked">Go</button>

<!-- Vue directive syntax -->
<button v-gxp-track="'cta.clicked'">Go</button>

The raw attribute is handled by a delegated document listener. It finds the nearest ancestor with [gxp-track], so clicking a nested icon uses its nearest tracked element rather than sending a separate event for every tracked ancestor. Elements with an installed directive handler are skipped by that delegated listener. This prevents that particular double-send; it does not deduplicate separate programmatic calls, repeated clicks or application listeners.

The Vue directive resolves its identifier from the binding value, then its argument. It replaces its handler when that identifier changes and removes its handler on unmount. Properties are read from the attribute at click time. Keep event names nonempty and stable; use dynamic IDs in properties instead of creating a different event name for each record.

Custom Events​

window.gxp.track()​

Available from any JS context once the plugin is installed:

window.gxp.track("registration.started", { form_id: 123 })

Produces:

{
"event_type": "custom",
"event_name": "registration.started",
"project_id": 42,
"properties": { "form_id": 123 }
}

Vue Injection​

Inside components, prefer the injected function:

<script setup>
import { inject } from "vue"

const track = inject("gxpTrack", null)

function onCheckinComplete(attendee) {
// Call only after your application has confirmed the real operation.
if (track) track("checkin.completed", { attendee_id: attendee.id })
}
</script>

Observing Events in Development​

Console​

Every development event is logged to the browser console as pretty-printed JSON:

[GxP Analytics] track event:
{
"event_type": "interaction",
"event_name": "cta.clicked",
"project_id": null,
"properties": { ... }
}

If the injection is absent, check whether the host installed the analytics plugin (including DISABLE_ANALYTICS). A missing tracker should not prevent the business operation. Do not manually install the dev logger into a production bundle to work around missing platform configuration.

Window Event​

Subscribe programmatically (e.g. in tests or custom dev tooling):

const onTrack = (event) => {
console.log("tracked:", event.detail) // synthetic development payloads only
}
window.addEventListener("gxp:track", onTrack)
// On teardown of your test/tool/component:
window.removeEventListener("gxp:track", onTrack)

The event name is exported as a constant:

import { GXP_TRACK_WINDOW_EVENT } from "@gx-runtime/gxpAnalyticsPlugin.js"

Event Payload Reference​

FieldTypeDescription
event_typestring"interaction" for gxp-track clicks, "custom" for gxp.track()
event_namestringThe gxp-track value or the first argument to track()
project_idnumber|string|nullGXP project ID (from API_PROJECT_ID in .env on the dev server)
propertiesobjectElement metadata (interactions) merged with custom props

Declaring Events in the App Manifest​

Every tracked event should be declared in app-manifest.json under the track-events key so the platform can build reporting around it. Keys are event identifiers; values describe the root keys of the event's gxp-track-props (or track() properties):

{
"track-events": {
"cta.clicked": {
"placement": "string",
"variant": ["primary", "secondary"]
},
"session.join": {
"session_id": { "type": "session", "value": "id" }
}
}
}

Each prop value is "string" (free-form), an array of allowed values, or a { "type": ..., "value": ... } relationship object pointing at a platform model field (e.g. { "type": "attendee", "value": "id" }).

You don't need to write this by hand: gxdev extract-config (or the config_extract_strings MCP tool, or /extract-config in the TUI) scans src/ for gxp-track attributes and gxp.track()/gxpTrack() calls and seeds track-events automatically. Every extracted prop defaults to "string" — refine to allowed-value lists or relationship objects by hand; re-extraction preserves existing property definitions even with --overwrite. Preview with gxdev extract-config --dry-run and inspect the result before applying it. Extraction recognizes supported literal declarations; an injected function named track, computed event names, spread properties and arbitrary expressions are not comprehensively discovered. Add/refine those declarations manually. The manifest is a reporting declaration, not runtime validation of the event properties. See the App Manifest docs for the full reference.

Configuration​

The dev harness installs the plugin automatically. Environment variables (.env):

VariableEffect
API_PROJECT_IDUsed as project_id on every event
DISABLE_ANALYTICSSet to true to skip installing the analytics plugin in dev

Best Practices​

1. Use Namespaced Event Names​

<!-- Good: feature.action naming -->
<button gxp-track="checkin.submit">Check In</button>
<button gxp-track="checkin.cancel">Cancel</button>

<!-- Avoid: generic names -->
<button gxp-track="click1">Check In</button>

2. Track Intent, Not Implementation​

Name events after what the user did, not which element they hit — the event name survives redesigns:

<!-- Good -->
<a gxp-track="schedule.session.opened">View Session</a>

<!-- Avoid -->
<a gxp-track="blue_link_row_3">View Session</a>

3. Put IDs in Props, Not Names​

Keep event names low-cardinality so they aggregate cleanly:

<!-- Good -->
<button
gxp-track="session.join"
:gxp-track-props="JSON.stringify({ session_id: session.id })"
>
Join
</button>

<!-- Avoid -->
<button :gxp-track="`session.join.${session.id}`">Join</button>

4. Combine Freely with Other GxP Directives​

gxp-track composes with gxp-string / gxp-src on the same element:

<button gxp-track="cta.clicked" gxp-string="btn_cta">Get Started</button>
<img
gxp-track="sponsor.logo.clicked"
gxp-src="sponsor_logo"
src="/dev-assets/images/logo.png"
/>

Troubleshooting​

Restart the development server after changing .env. Installation captures the project ID; reinstalling the plugin repeatedly in the same window is not a supported way to switch projects because the delegated listener/logger are guarded globally. Reload the page when changing project context. API_PROJECT_ID is metadata, not an authentication credential.

Events not appearing in console​

  1. Verify the plugin is installed — DISABLE_ANALYTICS must not be true
  2. Check the element actually has a non-empty gxp-track value
  3. Confirm window.gxp.track exists in the console

Events double-firing​

Use one intentional tracking mechanism per interaction. The delegated listener skips an element with an installed directive handler; it does not compare payloads or deduplicate your programmatic calls and repeated clicks.

gxp-track-props ignored​

The attribute must be valid JSON — single-quoted HTML attribute wrapping double-quoted JSON keys. Invalid JSON is silently dropped.

Verify a complete tracking path​

  1. Start a scaffold using Getting Started, with analytics enabled and synthetic project/event data.
  2. Add one raw attribute event, one Vue directive event and one confirmed-success custom event. Observe gxp:track and console output.
  3. Check names, event types, project metadata, nested click behavior, dynamic properties, malformed JSON fallback and directive unmount/rebinding. Ensure your own handlers do not send the same intended event twice.
  4. Run extraction in dry-run mode, apply it deliberately, refine track-events, and review the diff. Restart/reload after configuration changes.
  5. Deploy through the build and publish workflow. Verify the installed runtime's request, accepted response, stored event and authorized reporting separately. A local console entry, beacon enqueue result or successful UI action does not prove durable analytics storage.

Keep custom event names stable and low-cardinality. Avoid tokens, email addresses, full form contents and free-text comments in properties or tracked element text. This analytics API is distinct from the documentation site's Google Analytics tag and does not enable documentation feedback or embedded quizzes.

Source and verification scope​

Reviewed against toolkit a482a0e078e9bc436f62d764c84c3981b5027a25 (2.1.47): runtime/gxpAnalyticsPlugin.js, runtime installation/Vite environment mapping, configuration extraction and its native tests. Source/type/local runtime checks do not certify production transport, permission enforcement, consent policy or report accuracy in a deployed project.

Video playback recipe​

Use Video Playback and Analytics with Shaka for the platform manifest/transcript fields, a downloadable Vue player and tested measurement helper, click-versus-play distinctions, unique watched coverage, thresholds, completion policy and report formulas. Shaka handles playback; your application wires the analytics listeners.