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.
type | Returns |
|---|---|
data | Basic project and snippet information |
activePageIds | IDs of the currently active pages |
activeExperimentIds | Currently active experiments |
pingedGoals | Goals recorded while testing in preview or QA mode |
pages / experiments / goals | Raw project data lists |
variationById / goalById | A single variation or goal |
trackingConsentEnabled | Stored consent state |
deviceType | Device type of the visitor |
bucketing | Variation assignment of the visitor |
preview_bucketing | Variations selected via preview mode |
tools | The tools object |
data
Object with the following values:
| Property | Meaning |
|---|---|
projectId | The project the snippet belongs to. |
version | The snippet version. |
revision | The publication number. It increases with every publication. Compare it with Snippet revision in the snippet settings to see whether you get the latest version. |
goalsEnabled | false means goals are not counted, which is the case in preview mode. |
isPreview | true if preview mode is active. |
optedOut | true if you opted out in this browser. |
storage | Where 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 snippetbucketing
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');