# Client-side setup

Learn how to set up the client-side SDK.

The PHP SDK runs on the server, where it fetches content and evaluates queries. Client-side concerns, such as tracking user interactions, are handled by the [JavaScript SDK](/reference/sdk/javascript) running in the browser.

To connect both sides into a single visitor session, set up the client-side SDK with the configuration from the server.

## Set up the client-side SDK

After processing a request, persist the session cookies and configure the client-side SDK, so the browser works transparently with the same visitor and client ID:

**index.php**

```php
<?php
use Croct\Plug\Croct;

$croct = Croct::fromDotenv();
Croct::emitCookies();
?>
<script src="https://cdn.croct.io/js/v1/lib/plug.js"></script>
<script>croct.plug(<?= json_encode($croct->getPlugOptions()) ?>);</script>
```

The [`emitCookies`](api/core/croct/emit-cookies) call writes the session cookies before any output, and [`getPlugOptions`](api/core/plug/get-plug-options) returns the application ID and cookie configuration that configure the client-side SDK to read those same cookies and work transparently with the same session.

## Event tracking

Once the client-side SDK is configured, the [JavaScript SDK](/reference/sdk/javascript) tracks user interactions, such as page views, clicks, and conversions, directly from the browser.

See [Event tracking](/reference/sdk/javascript/event-tracking) for how to track events with the JavaScript SDK.

## Response caching

> **Shared cache risk**
>
> Pages that fetch personalized content or carry the visitor session cookies are unique to each visitor. Storing them in a shared cache, such as a CDN or reverse proxy, would serve one visitor's content to another. Mark these responses as private so they are never cached across visitors.

Our framework integrations, such as the [Laravel](/reference/sdk/laravel/integration), [Symfony](/reference/sdk/symfony/integration), and [Drupal](/reference/sdk/drupal/integration) SDKs, mark personalized responses as private automatically.

## Explore

- [getPlugOptions method](api/core/plug/get-plug-options): Explore the options that configure the client-side SDK.
- [Event tracking](/reference/sdk/javascript/event-tracking): Learn how to track user interactions with the JavaScript SDK.
