Integrate ABlyftReferenceJavaScript API

ablyft.get()

Read project data and runtime state from the snippet.

ablyft.get(type, argument?) returns data depending on type. An unknown type logs ABlyft - Unknown API type to the console and returns undefined.

typeReturns
dataBasic project and snippet information
activePageIdsIDs of the currently active pages
activeExperimentIdsCurrently active experiments
pingedGoalsGoals recorded while testing in preview or QA mode
pages / experiments / goalsRaw project data lists
variationById / goalByIdA single variation or goal
trackingConsentEnabledStored consent state
deviceTypeDevice type of the visitor
bucketingVariation assignment of the visitor
preview_bucketingVariations selected via preview mode
toolsThe tools object

data

Object with the following values:

PropertyMeaning
projectIdThe project the snippet belongs to.
versionThe snippet version.
revisionThe publication number. It increases with every publication. Compare it with Snippet revision in the snippet settings to see whether you get the latest version.
goalsEnabledfalse means goals are not counted, which is the case in preview mode.
isPreviewtrue if preview mode is active.
optedOuttrue if you opted out in this browser.
storageWhere the snippet stores data (default or a custom setting).
const data = ablyft.get('data');
console.log(data.projectId, data.version, data.revision);

activePageIds

const pageIds = ablyft.get('activePageIds'); // e.g. [12345678]

activeExperimentIds

const experiments = ablyft.get('activeExperimentIds');
console.log(experiments);

pingedGoals

Goals that were recorded during the current browser session while you test in preview or QA mode (read from sessionStorage). In these modes goals are listed but not sent to ABlyft. Returns an empty array if none.

const goals = ablyft.get('pingedGoals');
console.log(`${goals.length} goals recorded in this session`);

pages

const pages = ablyft.get('pages');

experiments

const experiments = ablyft.get('experiments');

goals

const goals = ablyft.get('goals');

variationById

Requires the variation ID as second argument; without it, nothing is returned.

const variation = ablyft.get('variationById', 98765432);

goalById

Requires the goal ID as second argument.

const goal = ablyft.get('goalById', 55555555);

trackingConsentEnabled

Returns true if consent was granted, false if it was declined, and an empty value (not set) if the visitor has not decided yet. Handy for the consent rules in the project settings, see Consent manager.

if (ablyft.get('trackingConsentEnabled') === true) {
  console.log('Tracking allowed');
}

deviceType

const device = ablyft.get('deviceType'); // device type detected by the snippet

bucketing

Object mapping experiment IDs to the variation IDs the visitor is assigned to.

const bucketing = ablyft.get('bucketing');
// { "12345678": 98765432 }

preview_bucketing

Variations selected through preview mode, as an object mapping experiment ID to variation ID (number). Empty object if preview mode is not used.

const preview = ablyft.get('preview_bucketing');

tools

Same as ablyft.getTools().

const tools = ablyft.get('tools');

On this page