# Checking Variants Without Triggering Exposures

When you call `treatment()`, the SDK records an **exposure**, telling ABsmartly that this user saw the experiment. That's usually what you want. But sometimes you need to know which variant a user is in without counting it as an exposure.

The `peek()` method does exactly this. It returns the same variant number as `treatment()`, but silently, without recording anything.

## When to use peek

Here are some real scenarios where peeking makes sense:

* **Pre-loading assets.** You need to know the variant ahead of time to prefetch images, scripts, or data. The actual exposure should be recorded later when the user sees the content.
* **Server-side routing with client-side exposure.** Your server decides which page template to render based on the variant, but the exposure should only fire on the client where the user actually sees it.
* **Debug logging.** You want to log which variant a user is in for debugging, but you don't want that logging to affect the experiment by creating exposures.
* **Admin panels.** An internal dashboard shows the current state of experiments for a user. Looking at this state shouldn't count as an exposure.

> **caution**
>
> If you peek but never call `treatment()` for the same experiment, no exposure will be recorded. That user won't appear in your experiment results at all. Make sure that somewhere in your code, `treatment()` gets called for users who actually see the experiment.

> **React users**
>
> You can also peek using the `useTreatment` hook by passing `true` as the second argument:
>
> ```jsx
> import { useTreatment } from "@absmartly/react-sdk";
>
> const { variant } = useTreatment("experiment_name", true);
> ```
>
> This returns the variant without recording an exposure, just like `context.peek()`.

## Peeking at treatments

The peek method returns the variant number just like `treatment()`, but without recording an exposure. The method name varies by SDK:

* **Javascript, React, Vue**: `peek()`
* **Python, Ruby**: `peek_treatment()`
* **PHP, Swift, Java, Flutter/Dart**: `peekTreatment()`
* **Go, .NET**: `PeekTreatment()`

**Javascript**

```js
if (context.peek("exp_test_experiment") == 0) {
  // user is in control group (variant 0)
} else {
  // user is in treatment group
}
```

**Python3**

```py
    res = context.peek_treatment("exp_test_experiment")
    if res == 0:
        # user is in control group (variant 0)
    else:
        # user is in treatment group
```

**React**

```jsx
const { context } = useABSmartly();

useEffect(() => {
  context
    .ready()
    .then(() => {
      if (context.peek("exp_test_experiment") === 0) {
        // User is in control group (variant 0)
      } else {
        // User is in treatment group
      }
    })
    .catch((error) => console.error(error));
}, [context]);
```

**Swift**

```swift
let treatment = context.peekTreatment(experimentName: "exp_test_experiment")

if treatment == 0 {
// user is in control group (variant 0)
} else {
// user is in treatment group
}
```

**Vue2**

```js
if (this.$absmartly.peek("exp_test_experiment") == 0) {
  // user is in control group (variant 0)
} else {
  // user is in treatment group
}
```

**Vue3**

```js
if (this.$absmartly.peek("exp_test_experiment") == 0) {
  // user is in control group (variant 0)
} else {
  // user is in treatment group
}
```

**Java**

```java
    if (context.peekTreatment("exp_test_experiment") == 0) {
        // user is in control group (variant 0)
    } else {
        // user is in treatment group
    }
```

**Go**

```go
var res, _ = context.PeekTreatment("exp_test_experiment")
if res == 0 {
	// user is in control group (variant 0)
} else {
	// user is in treatment group
}
```

**.NET**

```csharp
    if (context.PeekTreatment("exp_test_experiment") == 0) {
        // user is in control group (variant 0)
    } else {
        // user is in treatment group
    }
```

**PHP**

```php
$treatment = $context->peekTreatment('exp_test_experiment');

if ($treatment === 0) {
    // user is in control group (variant 0)
}
else {
    // user is in treatment group
}
```

**Ruby**

```ruby
treatment = context.peek_treatment('exp_test_experiment')
```

**Flutter/Dart**

```dart
    var value = await ctx.peekTreatment("experimentName");
```

## Peeking at variables

The peek variable method returns the variable value just like `variableValue()`, but without recording an exposure. It's called `peekVariableValue()` in most SDKs and `peek_variable_value()` in Python and Ruby.

**Javascript**

```js
const buttonColor = context.peekVariableValue("button.color", "red");
```

**Python3**

```py
    button_color = context.peek_variable("button.color", "red")
```

**React**

```jsx
const { context } = useABSmartly();

const buttonColor = context.peekVariableValue("button.color", "red");
```

**Swift**

```swift
let color = context.peekVariableValue("colorGComponent", defaultValue: 255)
```

**Vue2**

```js
this.variableValue = this.$absmartly.peekVariableValue("button.color", "red");
```

**Vue3**

```js
this.variableValue = this.$absmartly.peekVariableValue("button.color", "red");
```

**Java**

```java
final Object variable = context.peekVariable("button.color");
```

**Go**

```go
var variable = context.PeekVariable("button.color")
```

**.NET**

```csharp
    var buttonColor = context.PeekVariableValue("button.color");
```

**PHP**

```php
$buttonColor = $context->peekVariableValue('button.color', 'red');
```

**Ruby**

```ruby
treatment = context.peek_variable_value('button.color', default_button_color_value)
```

**Flutter/Dart**

```dart
    final dynamic variable = context.peekVariableValue("button.color", defaultButtonColorValue);
```
