JavaScript API

The Command Queue

The tracking script exposes a command queue via window._conv_q. You can push commands to this queue before or after the script loads — commands pushed before the script loads are processed once it initialises.

// Always initialise safely
window._conv_q = window._conv_q || [];

// Push a command
window._conv_q.push({
  what: 'methodName',
  params: { key: 'value' }
});

Important: Always use window._conv_q = window._conv_q || [] — never assign an empty array directly, as this overwrites any commands already in the queue.

Command Format

Commands can use the modern object format or the legacy array format:

// Modern (recommended)
window._conv_q.push({ what: 'identify', params: { visitorId: 'abc123' } });

// Legacy
window._conv_q.push(['identify', { visitorId: 'abc123' }]);

Available Commands

Visitor Identification

CommandDescriptionParameters
identifySet a custom visitor ID (BYOID){ visitorId: string }

The visitorId must use only 0-9, a-z, A-Z, ., - and _. As a regular expression, the rule is ^[0-9a-zA-Z._-]+$. Keep the ID to 64 characters or fewer. One longer ID can stop reports from using visitor-level revenue statistics for its whole variation. An ID over 256 characters may not be tracked at all.

The tracking script accepts any value, but the tracking server drops every event for an ID that breaks the rule. It still answers 200 OK, and experiences still render, so nothing reaches your reports or Live Logs without any visible error. An Auth0 user ID such as auth0|64f1c2… and an email address both break the rule. URL-encoding does not help, because % is not allowed either. Pass its SHA-256 hex digest instead, which is exactly 64 characters. Do not use a longer digest such as SHA-512.

Consent Management

CommandDescriptionParameters
consentRequiredBlock tracking until consent is given{ runExperiences?: boolean } (default: true)
consentGivenSignal that consent has been given — flushes queued events and re-runs the script—

When runExperiences is false, both experiments and data collection are blocked until consent. When true (default), experiments display immediately but data collection waits.

Experience Control

CommandDescriptionParameters
runRe-run the full evaluation cycle—
assignVariationProgrammatically decide a variation{ experienceId, variationId }
triggerExperienceVariationForce a specific variation (testing){ experienceId, variationId }
executeExperienceManually run a specific experience{ experienceId }
disableExperienceDisable a specific experience{ experienceId }
enableExperienceRe-enable a disabled experience{ experienceId }
disableVariationDisable a specific variation{ experienceId, variationId }
enableVariationRe-enable a disabled variation{ experienceId, variationId }
doNotRunExperiencesDisable all experience processing—
checkExperiencesRe-evaluate deferred experiences—

Goal Tracking

CommandDescriptionParameters
triggerConversionManually trigger a goal{ goalId, experienceId? }
triggerConversionsTrigger multiple goalsSame as triggerConversion
sendRevenueTrack a revenue transaction{ goalId?, transactionId, amount, productsCount? }
pushRevenueAlternative revenue tracking{ amount, productsCount?, goalId?, transactionId? }
recheckGoalsRe-evaluate all goals—

Segments

CommandDescriptionParameters
placeVisitorIntoSegmentManually place visitor into a segment{ segmentId }
checkSegmentsRe-evaluate segments that were waiting for data—

Location Triggers

CommandDescriptionParameters
triggerLocationManually activate a location trigger{ locationId }

Configuration

CommandDescriptionParameters
setParametersSet tracking script parameters{ delayContinuousActivation?, throttleChanges?, interceptEventsEarly? }
setIntegrationVariableSet a custom variable for targeting{ key, value }
showBodyForce-remove the anti-flicker overlay—

Navigation

CommandDescriptionParameters
refreshReload the current page (for split URL original)—
redirectNavigate to a URL (for split URL variation){ url: string }

Events

CommandDescriptionParameters
addListenerListen for lifecycle events{ event, handler }
readyCallback when the script has initialisedfunction

Lifecycle Events

You can listen for events fired during the tracking script's lifecycle:

window._conv_q = window._conv_q || [];
window._conv_q.push({
  what: 'addListener',
  params: {
    event: 'experience.activated',
    handler: function(data) {
      console.log('Experience activated:', data.experienceId, data.variationId);
    }
  }
});

Available Events

EventDescriptionData
snippet.initializedScript started—
snippet.segments_evaluatedSegments processed{ visitorId }
snippet.experiences_evaluatedExperiences processed—
snippet.goals_evaluatedGoals processed—
experience.activatedExperience shown to visitor{ experienceId, variationId }
experience.variation_decidedVariation selected{ experienceId, variationId }
goal.triggeredGoal conversion recorded{ goalId }
location.activatedLocation trigger matched{ locationId }
location.deactivatedLocation trigger unmatched{ locationId }
url.changedSPA navigation detected{ from, to }
render.completePage shown (anti-flicker removed)—

Timing: Listeners must be registered before the script processes them — either before the script loads, or from Global JavaScript. Listeners added after the script initialises will miss events that already fired.


Did this page help you?