# ablyft.get()

URL: https://docs.ablyft.com/developers/reference/javascript-api/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`](#data)                                                       | Basic project and snippet information              |
| [`activePageIds`](#activepageids)                                     | IDs of the currently active pages                  |
| [`activeExperimentIds`](#activeexperimentids)                         | Currently active experiments                       |
| [`pingedGoals`](#pingedgoals)                                         | Goals recorded while testing in preview or QA mode |
| [`pages`](#pages) / [`experiments`](#experiments) / [`goals`](#goals) | Raw project data lists                             |
| [`variationById`](#variationbyid) / [`goalById`](#goalbyid)           | A single variation or goal                         |
| [`trackingConsentEnabled`](#trackingconsentenabled)                   | Stored consent state                               |
| [`deviceType`](#devicetype)                                           | Device type of the visitor                         |
| [`bucketing`](#bucketing)                                             | Variation assignment of the visitor                |
| [`preview_bucketing`](#preview_bucketing)                             | Variations selected via preview mode               |
| [`tools`](#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](https://docs.ablyft.com/developers/installation/snippet-settings/#publishing). 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).                                                                                                                                                                |

```js
const data = ablyft.get('data');
console.log(data.projectId, data.version, data.revision);
```

## activePageIds

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

## activeExperimentIds

```js
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.

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

## pages

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

## experiments

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

## goals

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

## variationById

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

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

## goalById

Requires the goal ID as second argument.

```js
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](https://docs.ablyft.com/developers/consent-and-security/consent-manager/).

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

## deviceType

```js
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.

```js
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.

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

## tools

Same as [`ablyft.getTools()`](https://docs.ablyft.com/developers/reference/javascript-api/tools/).

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

