Skip to main content
window._pgnt.variables() returns a synchronous snapshot of the current visitor’s pagent context: session identifiers, the goal you ask about, and the active experiment the visitor is enrolled in. Use it to read identifiers on the page, link backend conversions to a session, or build readable experiment names for your own analytics or naming tools. Unlike the pagent:event bus, which pushes events to you as they happen, variables() is a pull-based call you make whenever you need the current values.
Note: Call this after the pagent SDK has initialized. Experiment fields are populated once a session is active for an enrolled visitor.

Call Signature

The argument is optional. Call it with no argument to read session and experiment context. Pass a conversion goal label (for example "purchase") to additionally resolve a conversion_id for that goal.

Fields

Null Semantics

All experiment fields (experiment_id, experiment_numeric_id, variation_id, is_control, endpoint_path) return null when there is no active pagent test on the current page. This includes analytics-only sessions and visitors who are not enrolled in any running test. conversion_id is null unless you pass a goal label that matches a configured goal.
Important: Always null-check these fields before composing a name or sending them onward. Recording them unconditionally will produce strings like "pagent Test null /null" in your reports.

Building Readable Experiment Names

The experiment fields let you construct a single machine-readable name that maps back to what you see in the pagent dashboard. Many analytics and naming tools expect one compact token with no spaces, so the example below leads with the human-readable parts (the test number) and appends the raw UUIDs at the end. Wire it to any element on your page — for example a conversion button — and call convert() when the visitor acts:
Notes on the example:
  • Human-readable parts come first (experiment_numeric_id, is_control) so the name is recognizable at a glance; the UUIDs (experiment_id, variation_id) are appended for exact reference.
  • The output contains no spaces, so it can be used directly as an event name or identifier.

Conversion Tracking

When you pass a goal label, variables("goal_label") also returns the conversion_id you need to record conversions from your backend. See Server-Side Conversions for the full flow.